PluginProbe
Extendify / 1.14.0
Extendify v1.14.0
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 0.7.0 All 126 releases
extendify / src / Library / util / insert.js

insert.js in Extendify 1.14.0, at src/Library/util/insert.js

41 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { dispatch, select } from '@wordpress/data';
2 import { useGlobalsStore } from '@library/state/global';
3 import { addGlobalCSS, requiredCSSVars } from '@library/util/css';
4
5 export const insertBlocks = async (blocks) => {
6 const { insertBlocks, replaceBlock } = dispatch('core/block-editor');
7 const {
8 getSelectedBlock,
9 getBlockHierarchyRootClientId,
10 getBlockIndex,
11 getGlobalBlockCount,
12 } = select('core/block-editor');
13
14 const { clientId, name, attributes } = getSelectedBlock() || {};
15 const rootClientId = clientId ? getBlockHierarchyRootClientId(clientId) : '';
16 const insertPointIndex =
17 (rootClientId ? getBlockIndex(rootClientId) : getGlobalBlockCount()) + 1;
18
19 // If there are spacing vars in state, we need to add them to the dom
20 const { missingCSSVars } = useGlobalsStore.getState();
21 missingCSSVars.forEach((key) => {
22 // Add variables to the dom
23 document?.documentElement?.style?.setProperty(key, requiredCSSVars[key]);
24 // Editor might be nested in an iframe too
25 document
26 .querySelector('iframe[name="editor-canvas"]')
27 ?.contentDocument?.documentElement?.style?.setProperty(
28 key,
29 requiredCSSVars[key],
30 );
31 });
32
33 // We also need to add them to global styles too
34 if (missingCSSVars.length) addGlobalCSS(missingCSSVars);
35
36 if (name === 'core/paragraph' && attributes?.content === '') {
37 return await replaceBlock(clientId, blocks);
38 }
39 return await insertBlocks(blocks, insertPointIndex);
40 };
41