mirror of
https://github.com/WenPai-org/wpmind.git
synced 2025-08-03 02:48:41 +08:00
better handling nested block attributes and innerBlocks
This commit is contained in:
parent
cf1d2c7c65
commit
b2c3fbf927
1 changed files with 21 additions and 24 deletions
|
@ -109,29 +109,7 @@ export default class BlocksStreamProcessor {
|
|||
const parsed = JSON.parse(completedJson);
|
||||
|
||||
if (Array.isArray(parsed) && parsed.length > 0) {
|
||||
const contentMatches = [
|
||||
...jsonContent.matchAll(
|
||||
/"content"\s*:\s*"([^"]*)(?:[^"]*)?/g
|
||||
),
|
||||
];
|
||||
|
||||
const updatedBlocks = parsed.map((block, index) => {
|
||||
if (
|
||||
block.name === 'core/paragraph' &&
|
||||
contentMatches[index]
|
||||
) {
|
||||
return {
|
||||
...block,
|
||||
attributes: {
|
||||
...block.attributes,
|
||||
content: contentMatches[index][1],
|
||||
},
|
||||
};
|
||||
}
|
||||
return block;
|
||||
});
|
||||
|
||||
const transformedBlocks = updatedBlocks
|
||||
const transformedBlocks = parsed
|
||||
.map((block) => this.transformToBlock(block))
|
||||
.filter(Boolean);
|
||||
|
||||
|
@ -326,9 +304,14 @@ export default class BlocksStreamProcessor {
|
|||
.filter(Boolean)
|
||||
: [];
|
||||
|
||||
const attributes = blockData.attributes || {};
|
||||
|
||||
// Recursively process attributes
|
||||
const processedAttributes = this.processAttributes(attributes);
|
||||
|
||||
return createBlock(
|
||||
blockData.name,
|
||||
blockData.attributes || {},
|
||||
processedAttributes,
|
||||
innerBlocks
|
||||
);
|
||||
} catch (error) {
|
||||
|
@ -337,6 +320,20 @@ export default class BlocksStreamProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
processAttributes(attributes) {
|
||||
const processedAttributes = {};
|
||||
|
||||
for (const [key, value] of Object.entries(attributes)) {
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
processedAttributes[key] = this.processAttributes(value);
|
||||
} else {
|
||||
processedAttributes[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
return processedAttributes;
|
||||
}
|
||||
|
||||
async dispatchBlocks(blocks, isFinal = false) {
|
||||
const now = Date.now();
|
||||
const timeSinceLastUpdate = now - this.lastUpdate;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue