@@ -27,11 +27,11 @@ import {
2727 addLinkedModalAttribute ,
2828} from './utils' ;
2929
30- registerBlockType ( metadata . name , {
30+ registerBlockType ( metadata . name , {
3131 icon : modal ,
3232 edit : Edit ,
3333 save,
34- } ) ;
34+ } ) ;
3535
3636/**
3737 * Returns the list of block names allowed as modal triggers (same as filter blockparty_modal_trigger_allowed_blocks).
@@ -41,99 +41,99 @@ registerBlockType(metadata.name, {
4141 */
4242function getModalTriggerAllowedBlocks ( ) {
4343 try {
44- const settings = select ( 'core/block-editor' ) . getSettings ( ) ;
44+ const settings = select ( 'core/block-editor' ) . getSettings ( ) ;
4545 const list = settings ?. blockpartyModalTriggerAllowedBlocks ;
46- return Array . isArray ( list ) ? list : [ 'core/button' ] ;
46+ return Array . isArray ( list ) ? list : [ 'core/button' ] ;
4747 } catch {
48- return [ 'core/button' ] ;
48+ return [ 'core/button' ] ;
4949 }
5050}
5151
5252// Add linkedModalId attribute only to blocks allowed as modal triggers.
5353addFilter (
5454 'blocks.registerBlockType' ,
5555 'blockparty-modal/add-linked-modal-attribute' ,
56- ( settings , blockName ) => {
56+ ( settings , blockName ) => {
5757 const allowedBlocks = getModalTriggerAllowedBlocks ( ) ;
58- if ( ! allowedBlocks . includes ( blockName ) ) {
58+ if ( ! allowedBlocks . includes ( blockName ) ) {
5959 return settings ;
6060 }
61- return addLinkedModalAttribute ( settings ) ;
61+ return addLinkedModalAttribute ( settings ) ;
6262 }
6363) ;
6464
6565// Blocks registered before our script loaded (e.g. core blocks) didn't get the
6666// filter — re-register only allowed blocks so linkedModalId is persisted on save.
6767const allowedBlocks = getModalTriggerAllowedBlocks ( ) ;
6868const blockTypes = getBlockTypes ( ) ;
69- blockTypes . forEach ( ( blockType ) => {
69+ blockTypes . forEach ( ( blockType ) => {
7070 if (
71- allowedBlocks . includes ( blockType . name ) &&
72- ! blockType . attributes ?. [ LINKED_MODAL_ATTR ]
71+ allowedBlocks . includes ( blockType . name ) &&
72+ ! blockType . attributes ?. [ LINKED_MODAL_ATTR ]
7373 ) {
7474 registerBlockType (
7575 blockType . name ,
76- addLinkedModalAttribute ( blockType )
76+ addLinkedModalAttribute ( blockType )
7777 ) ;
7878 }
79- } ) ;
79+ } ) ;
8080
8181// Add "Attached modal" panel with Combobox only to blocks allowed as modal triggers (see filter blockparty_modal_trigger_allowed_blocks).
8282addFilter (
8383 'editor.BlockEdit' ,
8484 'blockparty-modal/with-modal-trigger-control' ,
85- ( BlockEdit ) => ( props ) => {
85+ ( BlockEdit ) => ( props ) => {
8686 const { name, attributes, setAttributes } = props ;
8787
88- if ( name === MODAL_BLOCK_NAME ) {
89- return < BlockEdit { ...props } /> ;
88+ if ( name === MODAL_BLOCK_NAME ) {
89+ return < BlockEdit { ...props } /> ;
9090 }
9191
92- const triggerAllowedBlocks = useSelect ( ( storeSelect ) => {
93- const settings = storeSelect ( 'core/block-editor' ) . getSettings ( ) ;
92+ const triggerAllowedBlocks = useSelect ( ( storeSelect ) => {
93+ const settings = storeSelect ( 'core/block-editor' ) . getSettings ( ) ;
9494 const list = settings ?. blockpartyModalTriggerAllowedBlocks ;
95- return Array . isArray ( list ) ? list : [ 'core/button' ] ;
96- } , [ ] ) ;
95+ return Array . isArray ( list ) ? list : [ 'core/button' ] ;
96+ } , [ ] ) ;
9797
98- if ( ! triggerAllowedBlocks . includes ( name ) ) {
99- return < BlockEdit { ...props } /> ;
98+ if ( ! triggerAllowedBlocks . includes ( name ) ) {
99+ return < BlockEdit { ...props } /> ;
100100 }
101101
102- const modalOptions = useSelect ( ( storeSelect ) => {
103- return getModalOptionsFromEditor ( storeSelect ) ;
104- } , [ ] ) ;
102+ const modalOptions = useSelect ( ( storeSelect ) => {
103+ return getModalOptionsFromEditor ( storeSelect ) ;
104+ } , [ ] ) ;
105105
106106 const options = [
107- { value : '' , label : __ ( 'None' , 'blockparty-modal' ) } ,
107+ { value : '' , label : __ ( 'None' , 'blockparty-modal' ) } ,
108108 ...modalOptions ,
109109 ] ;
110110
111- const value = attributes [ LINKED_MODAL_ATTR ] || '' ;
111+ const value = attributes [ LINKED_MODAL_ATTR ] || '' ;
112112
113113 return (
114114 < >
115- < BlockEdit { ...props } />
115+ < BlockEdit { ...props } />
116116 < InspectorControls key = "blockparty-modal-trigger" >
117117 < PanelBody
118- title = { __ ( 'Attached modal' , 'blockparty-modal' ) }
119- initialOpen = { false }
118+ title = { __ ( 'Attached modal' , 'blockparty-modal' ) }
119+ initialOpen = { false }
120120 >
121121 < ComboboxControl
122- label = { __ (
122+ label = { __ (
123123 'Modal to open when block is clicked' ,
124124 'blockparty-modal'
125- ) }
126- value = { value }
127- options = { options }
128- onChange = { ( newValue ) =>
129- setAttributes ( {
130- [ LINKED_MODAL_ATTR ] : newValue || '' ,
131- } )
125+ ) }
126+ value = { value }
127+ options = { options }
128+ onChange = { ( newValue ) =>
129+ setAttributes ( {
130+ [ LINKED_MODAL_ATTR ] : newValue || '' ,
131+ } )
132132 }
133- placeholder = { __ (
133+ placeholder = { __ (
134134 'Select a modal…' ,
135135 'blockparty-modal'
136- ) }
136+ ) }
137137 />
138138 </ PanelBody >
139139 </ InspectorControls >
0 commit comments