PluginProbe
Extendify / 1.17.1
Extendify v1.17.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 0.7.0 All 126 releases
extendify / src / Draft / hooks / useSelectedText.js

useSelectedText.js in Extendify 1.17.1, at src/Draft/hooks/useSelectedText.js

24 lines 683 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { store as blockEditorStore } from '@wordpress/block-editor';
2 import { useSelect } from '@wordpress/data';
3 import { useCallback } from '@wordpress/element';
4
5 export const useSelectedText = () => {
6 const { getSelectedBlockClientIds, getBlocksByClientId } = useSelect(
7 (select) => select(blockEditorStore),
8 [],
9 );
10
11 const selectedBlockId = getSelectedBlockClientIds();
12
13 const getSelectedContent = useCallback(() => {
14 const selectedBlocks = getBlocksByClientId(selectedBlockId);
15 return selectedBlocks
16 .map(({ attributes }) => attributes.content)
17 .join('\n\n');
18 }, [getBlocksByClientId, selectedBlockId]);
19
20 return {
21 selectedText: getSelectedContent(),
22 };
23 };
24