-
Notifications
You must be signed in to change notification settings - Fork 0
Chore/blueprint #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore/blueprint #18
Changes from all commits
33f7d13
86833b3
bfd33cb
564e4bc
6120247
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ | |
|
|
||
| import Edit from './edit'; | ||
| import save from './save'; | ||
| import deprecated from './deprecated'; | ||
| import metadata from './block.json'; | ||
|
|
||
| import { | ||
|
|
@@ -28,12 +27,11 @@ | |
| addLinkedModalAttribute, | ||
| } from './utils'; | ||
|
|
||
| registerBlockType( metadata.name, { | ||
| registerBlockType(metadata.name, { | ||
| icon: modal, | ||
| edit: Edit, | ||
| save, | ||
| deprecated, | ||
| } ); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing block deprecation breaks existing saved blocksHigh Severity The Additional Locations (1) |
||
|
|
||
| /** | ||
| * Returns the list of block names allowed as modal triggers (same as filter blockparty_modal_trigger_allowed_blocks). | ||
|
|
@@ -43,99 +41,99 @@ | |
| */ | ||
| function getModalTriggerAllowedBlocks() { | ||
| try { | ||
| const settings = select( 'core/block-editor' ).getSettings(); | ||
| const settings = select('core/block-editor').getSettings(); | ||
| const list = settings?.blockpartyModalTriggerAllowedBlocks; | ||
| return Array.isArray( list ) ? list : [ 'core/button' ]; | ||
| return Array.isArray(list) ? list : ['core/button']; | ||
| } catch { | ||
| return [ 'core/button' ]; | ||
| return ['core/button']; | ||
| } | ||
| } | ||
|
|
||
| // Add linkedModalId attribute only to blocks allowed as modal triggers. | ||
| addFilter( | ||
| 'blocks.registerBlockType', | ||
| 'blockparty-modal/add-linked-modal-attribute', | ||
| ( settings, blockName ) => { | ||
| (settings, blockName) => { | ||
| const allowedBlocks = getModalTriggerAllowedBlocks(); | ||
| if ( ! allowedBlocks.includes( blockName ) ) { | ||
| if (!allowedBlocks.includes(blockName)) { | ||
| return settings; | ||
| } | ||
| return addLinkedModalAttribute( settings ); | ||
| return addLinkedModalAttribute(settings); | ||
| } | ||
| ); | ||
|
|
||
| // Blocks registered before our script loaded (e.g. core blocks) didn't get the | ||
| // filter — re-register only allowed blocks so linkedModalId is persisted on save. | ||
| const allowedBlocks = getModalTriggerAllowedBlocks(); | ||
| const blockTypes = getBlockTypes(); | ||
| blockTypes.forEach( ( blockType ) => { | ||
| blockTypes.forEach((blockType) => { | ||
| if ( | ||
| allowedBlocks.includes( blockType.name ) && | ||
| ! blockType.attributes?.[ LINKED_MODAL_ATTR ] | ||
| allowedBlocks.includes(blockType.name) && | ||
| !blockType.attributes?.[LINKED_MODAL_ATTR] | ||
| ) { | ||
| registerBlockType( | ||
| blockType.name, | ||
| addLinkedModalAttribute( blockType ) | ||
| addLinkedModalAttribute(blockType) | ||
| ); | ||
| } | ||
| } ); | ||
| }); | ||
|
|
||
| // Add "Attached modal" panel with Combobox only to blocks allowed as modal triggers (see filter blockparty_modal_trigger_allowed_blocks). | ||
| addFilter( | ||
| 'editor.BlockEdit', | ||
| 'blockparty-modal/with-modal-trigger-control', | ||
| ( BlockEdit ) => ( props ) => { | ||
| (BlockEdit) => (props) => { | ||
| const { name, attributes, setAttributes } = props; | ||
|
|
||
| if ( name === MODAL_BLOCK_NAME ) { | ||
| return <BlockEdit { ...props } />; | ||
| if (name === MODAL_BLOCK_NAME) { | ||
| return <BlockEdit {...props} />; | ||
| } | ||
|
|
||
| const triggerAllowedBlocks = useSelect( ( storeSelect ) => { | ||
| const settings = storeSelect( 'core/block-editor' ).getSettings(); | ||
| const triggerAllowedBlocks = useSelect((storeSelect) => { | ||
| const settings = storeSelect('core/block-editor').getSettings(); | ||
| const list = settings?.blockpartyModalTriggerAllowedBlocks; | ||
| return Array.isArray( list ) ? list : [ 'core/button' ]; | ||
| }, [] ); | ||
| return Array.isArray(list) ? list : ['core/button']; | ||
| }, []); | ||
|
|
||
| if ( ! triggerAllowedBlocks.includes( name ) ) { | ||
| return <BlockEdit { ...props } />; | ||
| if (!triggerAllowedBlocks.includes(name)) { | ||
| return <BlockEdit {...props} />; | ||
| } | ||
|
|
||
| const modalOptions = useSelect( ( storeSelect ) => { | ||
| return getModalOptionsFromEditor( storeSelect ); | ||
| }, [] ); | ||
| const modalOptions = useSelect((storeSelect) => { | ||
| return getModalOptionsFromEditor(storeSelect); | ||
| }, []); | ||
|
|
||
| const options = [ | ||
| { value: '', label: __( 'None', 'blockparty-modal' ) }, | ||
| { value: '', label: __('None', 'blockparty-modal') }, | ||
| ...modalOptions, | ||
| ]; | ||
|
|
||
| const value = attributes[ LINKED_MODAL_ATTR ] || ''; | ||
| const value = attributes[LINKED_MODAL_ATTR] || ''; | ||
|
|
||
| return ( | ||
| <> | ||
| <BlockEdit { ...props } /> | ||
| <BlockEdit {...props} /> | ||
| <InspectorControls key="blockparty-modal-trigger"> | ||
| <PanelBody | ||
| title={ __( 'Attached modal', 'blockparty-modal' ) } | ||
| initialOpen={ false } | ||
| title={__('Attached modal', 'blockparty-modal')} | ||
| initialOpen={false} | ||
| > | ||
| <ComboboxControl | ||
| label={ __( | ||
| label={__( | ||
| 'Modal to open when block is clicked', | ||
| 'blockparty-modal' | ||
| ) } | ||
| value={ value } | ||
| options={ options } | ||
| onChange={ ( newValue ) => | ||
| setAttributes( { | ||
| [ LINKED_MODAL_ATTR ]: newValue || '', | ||
| } ) | ||
| )} | ||
| value={value} | ||
| options={options} | ||
| onChange={(newValue) => | ||
| setAttributes({ | ||
| [LINKED_MODAL_ATTR]: newValue || '', | ||
| }) | ||
| } | ||
| placeholder={ __( | ||
| placeholder={__( | ||
| 'Select a modal…', | ||
| 'blockparty-modal' | ||
| ) } | ||
| )} | ||
| /> | ||
| </PanelBody> | ||
| </InspectorControls> | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blueprint demo content mismatches installed plugin version
Low Severity
The blueprint installs the plugin from the
1.0.5git tag, which doesn't include the new.sr-onlyCSS class added instyle.scss. However, the base64-encoded demo page content usesclass="sr-only"(the new save output). Since v1.0.5's built stylesheet has no.sr-onlyrule, the close button label text ("Close this dialog window") will render as visible text on the Playground demo frontend instead of being visually hidden. Therefneeds to point to a version that includes the.sr-onlyCSS, or the demo content needs to match v1.0.5's expected markup.