Skip to content

Commit

Permalink
Fix #167
Browse files Browse the repository at this point in the history
  • Loading branch information
inc2734 committed Mar 13, 2024
1 parent f4ee276 commit cfb2c99
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
1 change: 1 addition & 0 deletions snow-monkey-forms.php
Expand Up @@ -303,6 +303,7 @@ public function _register_post_type() {
'snow-monkey-forms/form--complete',
array(
'lock' => array(
'move' => true,
'remove' => true,
),
),
Expand Down
4 changes: 4 additions & 0 deletions src/blocks/form/complete/block.json
Expand Up @@ -12,6 +12,10 @@
"move": true,
"remove": true
}
},
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "contentOnly", false ]
}
},
"supports": {
Expand Down
21 changes: 14 additions & 7 deletions src/blocks/form/complete/edit.js
@@ -1,12 +1,14 @@
import { getBlockTypes } from '@wordpress/blocks';

import { InnerBlocks, useBlockProps } from '@wordpress/block-editor';
import { useBlockProps, useInnerBlocksProps } from '@wordpress/block-editor';

import { useMemo } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

export default function () {
const ALLOWED_BLOCKS = useMemo( () => {
export default function ( { attributes } ) {
const { templateLock } = attributes;

const allowedBlocks = useMemo( () => {
const blocks = getBlockTypes();
return blocks
.map( ( block ) => {
Expand All @@ -22,16 +24,21 @@ export default function () {
className: [ 'components-panel', 'snow-monkey-forms-setting-panel' ],
} );

const innerBlocksProps = useInnerBlocksProps(
{},
{
allowedBlocks,
templateLock,
}
);

return (
<div { ...blockProps }>
<div className="components-panel__header edit-post-sidebar-header snow-monkey-forms-setting-panel__header">
{ __( 'Complete', 'snow-monkey-forms' ) }
</div>
<div className="components-panel__body is-opened snow-monkey-forms-setting-panel__body">
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS }
templateLock={ false }
/>
<div { ...innerBlocksProps } />
</div>
</div>
);
Expand Down
4 changes: 4 additions & 0 deletions src/blocks/form/input/block.json
Expand Up @@ -16,6 +16,10 @@
"move": true,
"remove": true
}
},
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "contentOnly", false ]
}
},
"supports": {
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/form/input/edit.js
Expand Up @@ -16,7 +16,7 @@ import AutoReplyEmailSettingsPanel from './auto-reply-email-settings-panel';

export default function ( props ) {
const { attributes, setAttributes, className } = props;
const { formStyle } = attributes;
const { formStyle, templateLock } = attributes;

const allowedBlocks = [ 'snow-monkey-forms/item' ];

Expand All @@ -34,7 +34,7 @@ export default function ( props ) {
},
{
allowedBlocks,
templateLock: false,
templateLock,
}
);

Expand Down
4 changes: 4 additions & 0 deletions src/blocks/item/block.json
Expand Up @@ -29,6 +29,10 @@
"isDisplayLabelColumn": {
"type": "boolean",
"default": true
},
"templateLock": {
"type": [ "string", "boolean" ],
"enum": [ "all", "insert", "contentOnly", false ]
}
},
"style": "file:./style.css",
Expand Down
5 changes: 3 additions & 2 deletions src/blocks/item/edit.js
Expand Up @@ -20,7 +20,8 @@ export default function ( {
isSelected,
className,
} ) {
const { label, description, labelFor, isDisplayLabelColumn } = attributes;
const { label, description, labelFor, isDisplayLabelColumn, templateLock } =
attributes;

const blacklist = [
'snow-monkey-forms/snow-monkey-form',
Expand Down Expand Up @@ -65,7 +66,7 @@ export default function ( {
{
allowedBlocks,
prioritizedInserterBlocks,
templateLock: false,
templateLock,
}
);

Expand Down

0 comments on commit cfb2c99

Please sign in to comment.