Skip to content

Commit

Permalink
fix(document): reorganise createOrUpdateHtmlFile (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsonsj authored Jan 13, 2025
1 parent b316b62 commit b9c08ca
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions plugin/src/lib/api/files/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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 = "<span>lexical configuration not found</span>"
const html = "<span>lexical configuration not found</span>"
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({
Expand Down

0 comments on commit b9c08ca

Please sign in to comment.