PluginProbe
Extendify / 3.1.4
Extendify v3.1.4
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 / Agent / lib / block-code.js

block-code.js in Extendify 3.1.4, at src/Agent/lib/block-code.js

23 lines 891 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import apiFetch from '@wordpress/api-fetch';
2 import { addQueryArgs } from '@wordpress/url';
3
4 // Shared so the tool and DOMHighlighter build the same query args and can't drift.
5 export const blockCodeQueryArgs = (block, postId) => {
6 if (!block?.id) return null;
7 if (block.source?.kind === 'template-part') {
8 const { partSlug } = block.source;
9 return partSlug ? { blockId: String(block.id), partSlug } : null;
10 }
11 return postId ? { blockId: String(block.id), postId: String(postId) } : null;
12 };
13
14 // One block's current serialized code by TagBlocks id, scoped to the container's source.
15 export const fetchBlockCodeById = async (blockId, source, postId) => {
16 const args = blockCodeQueryArgs({ id: blockId, source }, postId);
17 if (!args) return '';
18 const response = await apiFetch({
19 path: addQueryArgs('/extendify/v1/agent/get-block-code', args),
20 });
21 return response?.block ?? '';
22 };
23