-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #34 - refactor, ready to add post_parent and number_posts
- Loading branch information
1 parent
1aa3df7
commit defa815
Showing
7 changed files
with
256 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const shortcode_attributes = | ||
{ | ||
shortcode: { | ||
type: 'string', | ||
default: '', | ||
}, | ||
|
||
content: { | ||
type: 'string', | ||
default: '', | ||
}, | ||
|
||
parameters: { | ||
type: 'string', | ||
default: '', | ||
}, | ||
|
||
post_type: { | ||
type: 'string', | ||
default: '', | ||
}, | ||
|
||
post_parent: { | ||
type: 'string', | ||
default: '.', | ||
}, | ||
|
||
number_posts: { | ||
type: 'string', | ||
default: 10, | ||
} | ||
|
||
// post_parent = ., 0, ID null | ||
// categories | ||
// number_posts = -1, 1->100 | ||
// offset = null, | ||
// orderby = | ||
// order = ASC / DESC | ||
// per_page | ||
// | ||
|
||
|
||
}; | ||
|
||
export { shortcode_attributes}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/** | ||
* Implements the edit part of oik/content-block | ||
* | ||
* @copyright (C) Copyright Bobbing Wide 2020 | ||
* @author Herb Miller @bobbingwide | ||
*/ | ||
const { __ } = wp.i18n; | ||
const { | ||
Editable, | ||
|
||
AlignmentToolbar, | ||
BlockControls, | ||
ServerSideRender, | ||
} = wp.editor; | ||
const { | ||
PlainText, | ||
InspectorControls, | ||
} = wp.blockEditor; | ||
|
||
const { | ||
withInstanceId, | ||
} = wp.compose; | ||
|
||
const { | ||
PanelBody, | ||
PanelRow, | ||
FormToggle, | ||
TextControl, | ||
TextareaControl, | ||
SelectControl, | ||
} = wp.components; | ||
const Fragment = wp.element.Fragment; | ||
import { map, partial, has } from 'lodash'; | ||
|
||
|
||
|
||
|
||
import {bw_shortcodes, getAttributes} from "./bw_shortcodes"; | ||
import {PostTypes} from "./post_type"; | ||
|
||
const edit= withInstanceId( | ||
( { attributes, setAttributes, instanceId, isSelected } ) => { | ||
const inputId = `blocks-shortcode-input-${ instanceId }`; | ||
|
||
|
||
const onChangeContent = ( value ) => { | ||
setAttributes( { content: value } ); | ||
}; | ||
|
||
const onChangeParameters = ( value ) => { | ||
setAttributes( { parameters: value } ); | ||
} | ||
|
||
const onChangeShortcode = ( value ) => { | ||
|
||
attributes = getAttributes( value ); | ||
setAttributes( { shortcode: value } ); | ||
}; | ||
|
||
|
||
function onChangeAttr( key, value ) { | ||
//var nextAttributes = {}; | ||
//nextAttributes[ key ] = value; | ||
//setAttributes( nextAttributes ); | ||
setAttributes( { [key] : value } ); | ||
}; | ||
|
||
const onChangePostType = ( value ) => { | ||
attributes = getAttributes( value ); | ||
setAttributes( { post_type: value }); | ||
} | ||
|
||
const onChangePostParent = ( value ) => { | ||
setAttributes( { post_parent: value }); | ||
} | ||
|
||
const onChangeNumberPosts = ( value ) => { | ||
setAttributes( { number_posts: value } ); | ||
} | ||
|
||
|
||
/* | ||
<GenericAttrs value={attributes.shortcode} /> | ||
*/ | ||
return ( | ||
<Fragment> | ||
|
||
<InspectorControls> | ||
<PanelBody> | ||
<SelectControl label="Display" value={attributes.shortcode} | ||
options={ map( bw_shortcodes, ( key, label ) => ( { value: label, label: label + ' - ' + key } ) ) } | ||
onChange={partial( onChangeAttr, 'shortcode' )} | ||
/> | ||
|
||
<PostTypes value={ attributes.post_type } onChange={onChangePostType } /> | ||
|
||
<TextareaControl label="Parameters" | ||
value={ attributes.parameters } | ||
placeholder={ __( 'Enter your shortcode parameters' ) } | ||
onChange={onChangeParameters} | ||
rows="1" | ||
/> | ||
<TextareaControl label="Content" | ||
id={ inputId } | ||
value={ attributes.content } | ||
placeholder={ __( 'Enter your shortcode content' ) } | ||
onChange={onChangeContent} | ||
/> | ||
|
||
|
||
|
||
|
||
|
||
|
||
</PanelBody> | ||
</InspectorControls> | ||
|
||
|
||
<div className="wp-block-oik-block-shortcode wp-block-shortcode"> | ||
<SelectControl label="Display" value={attributes.shortcode} | ||
options={ map( bw_shortcodes, ( key, label ) => ( { value: label, label: label + ' - ' + key } ) ) } | ||
onChange={partial( onChangeAttr, 'shortcode' )} | ||
/> | ||
|
||
|
||
|
||
</div> | ||
<div> | ||
<ServerSideRender | ||
block="oik/content-block" attributes={ attributes } | ||
/> | ||
</div> | ||
</Fragment> | ||
|
||
); | ||
} | ||
) | ||
|
||
export { edit }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Usage: | ||
* <NumberPosts value={ attributes.number_posts } onChange={onChangeNumberPosts} /> | ||
*/ |
Oops, something went wrong.