PluginProbe
Extendify / trunk
Extendify vtrunk
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / PageCreator / util / installBlocks.js

installBlocks.js in Extendify trunk, at src/PageCreator/util/installBlocks.js

29 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { downloadableBlocksManifest } from '@page-creator/lib/blocks';
2 import { useInstalledPluginsCache } from '@page-creator/state/plugins-cache';
3 import { store as blockDirectoryStore } from '@wordpress/block-directory';
4 import { dispatch } from '@wordpress/data';
5
6 const supportedBlocks = ['contact-form-7', 'simplybook'];
7
8 export const installBlocks = async ({ patterns }) => {
9 const { installBlockType } = dispatch(blockDirectoryStore);
10 const { installedPlugins, updateInstalledPlugins } =
11 useInstalledPluginsCache.getState();
12
13 const code = patterns
14 .flatMap((p) => p.patternReplacementCode)
15 .filter(Boolean);
16
17 // Look for any blocks we support installing
18 const foundBlocks = supportedBlocks.filter(
19 (block) =>
20 code.some((c) => c.includes(block)) && !installedPlugins.includes(block),
21 ); // Install the blocks
22 for (const block of foundBlocks) {
23 const blockManifest = downloadableBlocksManifest[block];
24 if (blockManifest) await installBlockType(blockManifest);
25 }
26
27 await updateInstalledPlugins();
28 };
29