| 1 |
import './deprecated'; |
| 2 |
import './attributes'; |
| 3 |
import './styles'; |
| 4 |
import './effects'; |
| 5 |
import './position'; |
| 6 |
import './spacings'; |
| 7 |
import './frame'; |
| 8 |
import './transform'; |
| 9 |
import './custom-css'; |
| 10 |
import './display'; |
| 11 |
import './toc-headings'; |
| 12 |
import './toolbar-templates'; |
| 13 |
import './block-actions-copy-paste'; |
| 14 |
|
| 15 |
import { hasBlockSupport } from '@wordpress/blocks'; |
| 16 |
import { createHigherOrderComponent } from '@wordpress/compose'; |
| 17 |
import { addFilter } from '@wordpress/hooks'; |
| 18 |
|
| 19 |
import ApplyFilters from '../components/apply-filters'; |
| 20 |
|
| 21 |
/** |
| 22 |
* Override the default edit UI to include GhostKit extensions |
| 23 |
* |
| 24 |
* @param {Function | Component} BlockEdit Original component. |
| 25 |
* |
| 26 |
* @return {string} Wrapped component. |
| 27 |
*/ |
| 28 |
const withGhostKitExtensions = createHigherOrderComponent( |
| 29 |
(OriginalComponent) => { |
| 30 |
function GhostKitExtensionsWrapper(props) { |
| 31 |
const hasExtensionsSupport = hasBlockSupport(props.name, [ |
| 32 |
'ghostkit', |
| 33 |
]); |
| 34 |
|
| 35 |
if (!hasExtensionsSupport) { |
| 36 |
return <OriginalComponent {...props} />; |
| 37 |
} |
| 38 |
|
| 39 |
return ( |
| 40 |
<> |
| 41 |
<OriginalComponent {...props} /> |
| 42 |
{/* |
| 43 |
* Used priorities: |
| 44 |
* 11 - Effects |
| 45 |
* 12 - Position |
| 46 |
* 13 - Spacings |
| 47 |
* 14 - Frame |
| 48 |
* 15 - Transform |
| 49 |
* 16 - Custom CSS |
| 50 |
* 17 - Display Conditions |
| 51 |
*/} |
| 52 |
<ApplyFilters |
| 53 |
name="ghostkit.editor.extensions" |
| 54 |
props={props} |
| 55 |
/> |
| 56 |
</> |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
return GhostKitExtensionsWrapper; |
| 61 |
}, |
| 62 |
'withGhostKitExtensions' |
| 63 |
); |
| 64 |
|
| 65 |
/** |
| 66 |
* Add `ghostkit` attribute to deprecated blocks settings. |
| 67 |
* |
| 68 |
* @param {Object} blockSettings Original block settings. |
| 69 |
* |
| 70 |
* @return {Object} Filtered block settings. |
| 71 |
*/ |
| 72 |
function addAttribute(blockSettings) { |
| 73 |
// Add attribute to All blocks. |
| 74 |
// Previously we used hasBlockSupport function, but it's not working correctly for all blocks |
| 75 |
// and leads to issues with blocks that are not registered yet (probably in deprecated block variations). |
| 76 |
if (blockSettings.attributes && !blockSettings.attributes.ghostkit) { |
| 77 |
blockSettings.attributes.ghostkit = { |
| 78 |
type: 'object', |
| 79 |
}; |
| 80 |
} |
| 81 |
|
| 82 |
return blockSettings; |
| 83 |
} |
| 84 |
|
| 85 |
addFilter('editor.BlockEdit', 'ghostkit/extensions', withGhostKitExtensions); |
| 86 |
|
| 87 |
addFilter( |
| 88 |
'blocks.registerBlockType', |
| 89 |
'ghostkit/extensions/additional-attributes', |
| 90 |
addAttribute |
| 91 |
); |
| 92 |
|