From b9c08ca4b9ad357c3659ff7d1c27823cb387ab19 Mon Sep 17 00:00:00 2001 From: Steven Thompson Date: Mon, 13 Jan 2025 21:30:20 +0000 Subject: [PATCH] fix(document): reorganise createOrUpdateHtmlFile (#246) --- plugin/src/lib/api/files/document.ts | 35 +++++++++++++++++----------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/plugin/src/lib/api/files/document.ts b/plugin/src/lib/api/files/document.ts index 4c53220..8b0eae8 100644 --- a/plugin/src/lib/api/files/document.ts +++ b/plugin/src/lib/api/files/document.ts @@ -255,7 +255,7 @@ export class payloadCrowdinSyncDocumentFilesApi extends payloadCrowdinSyncFilesA collection: CollectionConfig | GlobalConfig; }) { // brittle check for Lexical value - improve this detection. Type check? Anything from Payload to indicate the type? - let html, blockContent, blockConfig: BlockField | undefined + let blockContent, blockConfig: BlockField | undefined const isLexical = Object.prototype.hasOwnProperty.call(value, "root") if (isLexical) { @@ -268,7 +268,7 @@ export class payloadCrowdinSyncDocumentFilesApi extends payloadCrowdinSyncFilesA const editorConfig = getLexicalEditorConfig(field) if (editorConfig) { - html = await convertLexicalToHtml(value, editorConfig) + const html = await convertLexicalToHtml(value, editorConfig) // no need to detect change - this has already been done on the field's JSON object blockContent = value && extractLexicalBlockContent(value.root) blockConfig = editorConfig && getLexicalBlockFields(editorConfig) @@ -281,21 +281,30 @@ export class payloadCrowdinSyncDocumentFilesApi extends payloadCrowdinSyncFilesA req: this.req, }) } + await this.createOrUpdateFile({ + name: name, + fileData: html, + fileType: "html", + ...(!isEmpty(blockContent) && { + sourceBlocks: blockContent + }), + }); } else { - html = "lexical configuration not found" + const html = "lexical configuration not found" + await this.createOrUpdateFile({ + name: name, + fileData: html, + fileType: "html", + }); } } else { - html = convertSlateToHtml(value, this.pluginOptions.slateToHtmlConfig) + const html = convertSlateToHtml(value, this.pluginOptions.slateToHtmlConfig) + await this.createOrUpdateFile({ + name: name, + fileData: html, + fileType: "html", + }); } - - await this.createOrUpdateFile({ - name: name, - fileData: html, - fileType: "html", - ...(!isEmpty(blockContent) && { - sourceBlocks: blockContent - }), - }); } async createLexicalBlocks({