Skip to content

Commit d2fe844

Browse files
committed
Block conversion update: ability to convert to complex objects
1 parent de6fd78 commit d2fe844

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/components/utils/blocks.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ export async function getConvertibleToolsForBlock(block: BlockAPI, allBlockTools
6161
}
6262

6363
const exportData = convertBlockDataForExport(blockData, blockTool.conversionConfig);
64-
6564
return allBlockTools.reduce((result, tool) => {
6665
/**
6766
* Skip tools without «import» rule specified
@@ -85,6 +84,14 @@ export async function getConvertibleToolsForBlock(block: BlockAPI, allBlockTools
8584
return result;
8685
}
8786

87+
/**
88+
* Checking that the block is not empty after conversion
89+
*/
90+
const importData = convertExportToBlockData(exportData, tool.conversionConfig);
91+
if (isUndefined(importData) || isEmpty(importData)) {
92+
return result;
93+
}
94+
8895
/** Filter out invalid toolbox entries */
8996
const actualToolboxItems = tool.toolbox.filter((toolboxItem) => {
9097
/**

types/configs/conversion-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface ConversionConfig {
1212
* 1. String — the key of Tool data object to fill it with imported string on render.
1313
* 2. Function — method that accepts importing string and composes Tool data to render.
1414
*/
15-
import?: ((data: string, config: ToolConfig) => BlockToolData) | string;
15+
import?: ((data: string | object, config: ToolConfig) => BlockToolData) | string;
1616

1717
/**
1818
* How to export this Tool to make other Block.

0 commit comments

Comments
 (0)