Skip to content

Commit

Permalink
Merge pull request #65 from ryanwelcher/try/adding-transform
Browse files Browse the repository at this point in the history
Add "AQL" and "aql" shortcuts to quickly insert new instance of AQL
  • Loading branch information
ryanwelcher authored Jun 21, 2024
2 parents 1796d23 + ad48f17 commit 54b6b11
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
2 changes: 0 additions & 2 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ template: |
categories:
- title: '🚀 Features'
collapse-after: 3
label: 'enhancement'
- title: '🐛 Bug Fixes'
collapse-after: 3
labels:
- 'fix'
- 'bugfix'
Expand Down
50 changes: 49 additions & 1 deletion src/variations/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { addFilter } from '@wordpress/hooks';
import { InspectorControls } from '@wordpress/block-editor';
import { PanelBody } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { createBlock } from '@wordpress/blocks';
/**
* Internal dependencies
*/
Expand Down Expand Up @@ -92,4 +93,51 @@ const withAdvancedQueryControls = ( BlockEdit ) => ( props ) => {
return <BlockEdit { ...props } />;
};

addFilter( 'editor.BlockEdit', 'core/query', withAdvancedQueryControls );
addFilter(
'editor.BlockEdit',
'aql/add-add-controls/core/query',
withAdvancedQueryControls
);

/**
* Filter to add AQL transform to core/query block
*
* @param {Object} settings
* @param {string} name
* @return {Object} settings
*/
function addAQLTransforms( settings, name ) {
if ( name !== 'core/query' ) {
return settings;
}

return {
...settings,
keywords: [ ...settings.keywords, 'AQL', 'aql' ],
transforms: {
to: settings?.transforms?.to || [],
from: [
...( settings?.transforms?.from || [] ),
{
type: 'enter',
regExp: /^(AQL|aql)$/,
transform: () => {
return createBlock(
'core/query',
{
namespace: 'advanced-query-loop',
},
[]
);
},
},
],
},
};
}

addFilter(
'blocks.registerBlockType',
'aql/add-transforms/query-block',
addAQLTransforms
);

0 comments on commit 54b6b11

Please sign in to comment.