@@ -18,7 +18,6 @@ import './style.scss';
1818
1919import Edit from './edit' ;
2020import save from './save' ;
21- import deprecated from './deprecated' ;
2221import metadata from './block.json' ;
2322
2423import {
@@ -28,12 +27,11 @@ import {
2827 addLinkedModalAttribute ,
2928} from './utils' ;
3029
31- registerBlockType ( metadata . name , {
30+ registerBlockType ( metadata . name , {
3231 icon : modal ,
3332 edit : Edit ,
3433 save,
35- deprecated,
36- } ) ;
34+ } ) ;
3735
3836/**
3937 * Returns the list of block names allowed as modal triggers (same as filter blockparty_modal_trigger_allowed_blocks).
@@ -43,99 +41,99 @@ registerBlockType( metadata.name, {
4341 */
4442function getModalTriggerAllowedBlocks ( ) {
4543 try {
46- const settings = select ( 'core/block-editor' ) . getSettings ( ) ;
44+ const settings = select ( 'core/block-editor' ) . getSettings ( ) ;
4745 const list = settings ?. blockpartyModalTriggerAllowedBlocks ;
48- return Array . isArray ( list ) ? list : [ 'core/button' ] ;
46+ return Array . isArray ( list ) ? list : [ 'core/button' ] ;
4947 } catch {
50- return [ 'core/button' ] ;
48+ return [ 'core/button' ] ;
5149 }
5250}
5351
5452// Add linkedModalId attribute only to blocks allowed as modal triggers.
5553addFilter (
5654 'blocks.registerBlockType' ,
5755 'blockparty-modal/add-linked-modal-attribute' ,
58- ( settings , blockName ) => {
56+ ( settings , blockName ) => {
5957 const allowedBlocks = getModalTriggerAllowedBlocks ( ) ;
60- if ( ! allowedBlocks . includes ( blockName ) ) {
58+ if ( ! allowedBlocks . includes ( blockName ) ) {
6159 return settings ;
6260 }
63- return addLinkedModalAttribute ( settings ) ;
61+ return addLinkedModalAttribute ( settings ) ;
6462 }
6563) ;
6664
6765// Blocks registered before our script loaded (e.g. core blocks) didn't get the
6866// filter — re-register only allowed blocks so linkedModalId is persisted on save.
6967const allowedBlocks = getModalTriggerAllowedBlocks ( ) ;
7068const blockTypes = getBlockTypes ( ) ;
71- blockTypes . forEach ( ( blockType ) => {
69+ blockTypes . forEach ( ( blockType ) => {
7270 if (
73- allowedBlocks . includes ( blockType . name ) &&
74- ! blockType . attributes ?. [ LINKED_MODAL_ATTR ]
71+ allowedBlocks . includes ( blockType . name ) &&
72+ ! blockType . attributes ?. [ LINKED_MODAL_ATTR ]
7573 ) {
7674 registerBlockType (
7775 blockType . name ,
78- addLinkedModalAttribute ( blockType )
76+ addLinkedModalAttribute ( blockType )
7977 ) ;
8078 }
81- } ) ;
79+ } ) ;
8280
8381// Add "Attached modal" panel with Combobox only to blocks allowed as modal triggers (see filter blockparty_modal_trigger_allowed_blocks).
8482addFilter (
8583 'editor.BlockEdit' ,
8684 'blockparty-modal/with-modal-trigger-control' ,
87- ( BlockEdit ) => ( props ) => {
85+ ( BlockEdit ) => ( props ) => {
8886 const { name, attributes, setAttributes } = props ;
8987
90- if ( name === MODAL_BLOCK_NAME ) {
91- return < BlockEdit { ...props } /> ;
88+ if ( name === MODAL_BLOCK_NAME ) {
89+ return < BlockEdit { ...props } /> ;
9290 }
9391
94- const triggerAllowedBlocks = useSelect ( ( storeSelect ) => {
95- const settings = storeSelect ( 'core/block-editor' ) . getSettings ( ) ;
92+ const triggerAllowedBlocks = useSelect ( ( storeSelect ) => {
93+ const settings = storeSelect ( 'core/block-editor' ) . getSettings ( ) ;
9694 const list = settings ?. blockpartyModalTriggerAllowedBlocks ;
97- return Array . isArray ( list ) ? list : [ 'core/button' ] ;
98- } , [ ] ) ;
95+ return Array . isArray ( list ) ? list : [ 'core/button' ] ;
96+ } , [ ] ) ;
9997
100- if ( ! triggerAllowedBlocks . includes ( name ) ) {
101- return < BlockEdit { ...props } /> ;
98+ if ( ! triggerAllowedBlocks . includes ( name ) ) {
99+ return < BlockEdit { ...props } /> ;
102100 }
103101
104- const modalOptions = useSelect ( ( storeSelect ) => {
105- return getModalOptionsFromEditor ( storeSelect ) ;
106- } , [ ] ) ;
102+ const modalOptions = useSelect ( ( storeSelect ) => {
103+ return getModalOptionsFromEditor ( storeSelect ) ;
104+ } , [ ] ) ;
107105
108106 const options = [
109- { value : '' , label : __ ( 'None' , 'blockparty-modal' ) } ,
107+ { value : '' , label : __ ( 'None' , 'blockparty-modal' ) } ,
110108 ...modalOptions ,
111109 ] ;
112110
113- const value = attributes [ LINKED_MODAL_ATTR ] || '' ;
111+ const value = attributes [ LINKED_MODAL_ATTR ] || '' ;
114112
115113 return (
116114 < >
117- < BlockEdit { ...props } />
115+ < BlockEdit { ...props } />
118116 < InspectorControls key = "blockparty-modal-trigger" >
119117 < PanelBody
120- title = { __ ( 'Attached modal' , 'blockparty-modal' ) }
121- initialOpen = { false }
118+ title = { __ ( 'Attached modal' , 'blockparty-modal' ) }
119+ initialOpen = { false }
122120 >
123121 < ComboboxControl
124- label = { __ (
122+ label = { __ (
125123 'Modal to open when block is clicked' ,
126124 'blockparty-modal'
127- ) }
128- value = { value }
129- options = { options }
130- onChange = { ( newValue ) =>
131- setAttributes ( {
132- [ LINKED_MODAL_ATTR ] : newValue || '' ,
133- } )
125+ ) }
126+ value = { value }
127+ options = { options }
128+ onChange = { ( newValue ) =>
129+ setAttributes ( {
130+ [ LINKED_MODAL_ATTR ] : newValue || '' ,
131+ } )
134132 }
135- placeholder = { __ (
133+ placeholder = { __ (
136134 'Select a modal…' ,
137135 'blockparty-modal'
138- ) }
136+ ) }
139137 />
140138 </ PanelBody >
141139 </ InspectorControls >
0 commit comments