@payloadcms/richtext-lexical 3.35.0-internal.b3d367c → 3.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["htmlStartTagReg","htmlTagWithNameReg","htmlTagReg","htmlImgTagReg","htmlVideoTagReg","HtmlDiff","config","leastCommonLength","Infinity","matchedBlockList","newTokens","oldTokens","operationList","sideBySideContents","unifiedContent","constructor","oldHtml","newHtml","classNames","createBlock","createInline","deleteBlock","deleteInline","greedyBoundary","greedyMatch","minMatchedSize","trim","equalSequence","content","replace","match","name","tagNameLength","length","slice","tokenize","getMatchedBlockList","getOperationList","computeBestMatchedBlock","oldStart","oldEnd","newStart","newEnd","bestMatchedBlock","i","len","Math","min","ret","slideBestMatchedBlock","size","j","computeMatchedBlockList","matchBlock","push","dressUpBlockTag","type","token","dressUpDiffContent","tokens","tokensLength","result","textStartIndex","isMatchElement","includes","isMatchExplicitlyDisabled","isHtmlTag","dressUpText","newToken","dressupMatchEnabledHtmlTag","dressUpInlineTag","tagName","groups","matchType","text","join","n1","n2","start","end","e1","e2","commonLength","floor","unshift","walkIndexOld","walkIndexNew","matchedBlock","isOldStartIndexMatched","isNewStartIndexMatched","operationBase","Object","assign","maxIndexOld","maxIndexNew","tailOperationBase","isOldFinished","isNewFinished","addA","addB","maxSize","continuousSize","html","getSideBySideContents","undefined","forEach","operation","deletedTokens","equalTokens","equalString","startTagMatch","console","error","String","getUnifiedContent","olds","news","createdTokens","createIndex","deleteIndex","deletedToken","matchTagResultD","some","item","splice","isTagInNewFind","tempCreateIndex","createdToken","matchTagResultC","isEnd"],"sources":["../../../../src/field/Diff/htmlDiff/index.ts"],"sourcesContent":["// Taken and modified from https://github.com/Arman19941113/html-diff/blob/master/packages/html-diff/src/index.ts\n\ninterface MatchedBlock {\n newEnd: number\n newStart: number\n oldEnd: number\n oldStart: number\n size: number\n}\n\ninterface Operation {\n /**\n * Index of entry in tokenized token list\n */\n newEnd: number\n newStart: number\n oldEnd: number\n oldStart: number\n type: 'create' | 'delete' | 'equal' | 'replace'\n}\n\ntype BaseOpType = 'create' | 'delete'\n\ninterface HtmlDiffConfig {\n classNames: {\n createBlock: string\n createInline: string\n deleteBlock: string\n deleteInline: string\n }\n greedyBoundary: number\n greedyMatch: boolean\n minMatchedSize: number\n}\n\nexport interface HtmlDiffOptions {\n /**\n * The classNames for wrapper DOM.\n * Use this to configure your own styles without importing the built-in CSS file\n */\n classNames?: Partial<{\n createBlock?: string\n createInline?: string\n deleteBlock?: string\n deleteInline?: string\n }>\n /**\n * @defaultValue 1000\n */\n greedyBoundary?: number\n /**\n * When greedyMatch is enabled, if the length of the sub-tokens exceeds greedyBoundary,\n * we will use the matched sub-tokens that are sufficiently good, even if they are not optimal, to enhance performance.\n * @defaultValue true\n */\n greedyMatch?: boolean\n /**\n * Determine the minimum threshold for calculating common sub-tokens.\n * You may adjust it to a value larger than 2, but not lower, due to the potential inclusion of HTML tags in the count.\n * @defaultValue 2\n */\n minMatchedSize?: number\n}\n\n// eslint-disable-next-line regexp/no-super-linear-backtracking, regexp/optimal-quantifier-concatenation\nconst htmlStartTagReg = /^<(?<name>[^\\s/>]+)[^>]*>$/\n// eslint-disable-next-line regexp/no-super-linear-backtracking, regexp/optimal-quantifier-concatenation\nconst htmlTagWithNameReg = /^<(?<isEnd>\\/)?(?<name>[^\\s>]+)[^>]*>$/\n\nconst htmlTagReg = /^<[^>]+>/\nconst htmlImgTagReg = /^<img[^>]*>$/\nconst htmlVideoTagReg = /^<video[^>]*>.*?<\\/video>$/ms\n\nexport class HtmlDiff {\n private readonly config: HtmlDiffConfig\n private leastCommonLength: number = Infinity\n private readonly matchedBlockList: MatchedBlock[] = []\n private readonly newTokens: string[] = []\n private readonly oldTokens: string[] = []\n private readonly operationList: Operation[] = []\n private sideBySideContents?: [string, string]\n private unifiedContent?: string\n\n constructor(\n oldHtml: string,\n newHtml: string,\n {\n classNames = {\n createBlock: 'html-diff-create-block-wrapper',\n createInline: 'html-diff-create-inline-wrapper',\n deleteBlock: 'html-diff-delete-block-wrapper',\n deleteInline: 'html-diff-delete-inline-wrapper',\n },\n greedyBoundary = 1000,\n greedyMatch = true,\n minMatchedSize = 2,\n }: HtmlDiffOptions = {},\n ) {\n // init config\n this.config = {\n classNames: {\n createBlock: 'html-diff-create-block-wrapper',\n createInline: 'html-diff-create-inline-wrapper',\n deleteBlock: 'html-diff-delete-block-wrapper',\n deleteInline: 'html-diff-delete-inline-wrapper',\n ...classNames,\n },\n greedyBoundary,\n greedyMatch,\n minMatchedSize,\n }\n // white space is junk\n oldHtml = oldHtml.trim()\n newHtml = newHtml.trim()\n\n // no need to diff\n if (oldHtml === newHtml) {\n this.unifiedContent = oldHtml\n let equalSequence = 0\n // eslint-disable-next-line regexp/no-super-linear-backtracking, regexp/optimal-quantifier-concatenation\n const content = oldHtml.replace(/<([^\\s/>]+)[^>]*>/g, (match: string, name: string) => {\n const tagNameLength = name.length + 1\n return `${match.slice(0, tagNameLength)} data-seq=\"${++equalSequence}\"${match.slice(tagNameLength)}`\n })\n this.sideBySideContents = [content, content]\n return\n }\n\n // step1: split HTML to tokens(atomic tokens)\n this.oldTokens = this.tokenize(oldHtml)\n this.newTokens = this.tokenize(newHtml)\n // step2: find matched blocks\n this.matchedBlockList = this.getMatchedBlockList()\n\n // step3: generate operation list\n this.operationList = this.getOperationList()\n }\n\n // Find the longest matched block between tokens\n private computeBestMatchedBlock(\n oldStart: number,\n oldEnd: number,\n newStart: number,\n newEnd: number,\n ): MatchedBlock | null {\n let bestMatchedBlock = null\n for (let i = oldStart; i < oldEnd; i++) {\n const len = Math.min(oldEnd - i, newEnd - newStart)\n const ret = this.slideBestMatchedBlock(i, newStart, len)\n if (ret && (!bestMatchedBlock || ret.size > bestMatchedBlock.size)) {\n bestMatchedBlock = ret\n if (ret.size > this.leastCommonLength) {\n return bestMatchedBlock\n }\n }\n }\n for (let j = newStart; j < newEnd; j++) {\n const len = Math.min(oldEnd - oldStart, newEnd - j)\n const ret = this.slideBestMatchedBlock(oldStart, j, len)\n if (ret && (!bestMatchedBlock || ret.size > bestMatchedBlock.size)) {\n bestMatchedBlock = ret\n if (ret.size > this.leastCommonLength) {\n return bestMatchedBlock\n }\n }\n }\n return bestMatchedBlock\n }\n\n private computeMatchedBlockList(\n oldStart: number,\n oldEnd: number,\n newStart: number,\n newEnd: number,\n matchedBlockList: MatchedBlock[] = [],\n ): MatchedBlock[] {\n const matchBlock = this.computeBestMatchedBlock(oldStart, oldEnd, newStart, newEnd)\n\n if (!matchBlock) {\n return []\n }\n\n if (oldStart < matchBlock.oldStart && newStart < matchBlock.newStart) {\n this.computeMatchedBlockList(\n oldStart,\n matchBlock.oldStart,\n newStart,\n matchBlock.newStart,\n matchedBlockList,\n )\n }\n matchedBlockList.push(matchBlock)\n if (oldEnd > matchBlock.oldEnd && newEnd > matchBlock.newEnd) {\n this.computeMatchedBlockList(\n matchBlock.oldEnd,\n oldEnd,\n matchBlock.newEnd,\n newEnd,\n matchedBlockList,\n )\n }\n return matchedBlockList\n }\n\n private dressUpBlockTag(type: BaseOpType, token: string): string {\n if (type === 'create') {\n return `<div class=\"${this.config.classNames.createBlock}\">${token}</div>`\n }\n if (type === 'delete') {\n return `<div class=\"${this.config.classNames.deleteBlock}\">${token}</div>`\n }\n return ''\n }\n\n private dressUpDiffContent(type: BaseOpType, tokens: string[]): string {\n const tokensLength = tokens.length\n if (!tokensLength) {\n return ''\n }\n\n let result = ''\n let textStartIndex = 0\n let i = -1\n for (const token of tokens) {\n i++\n\n // If this is true, this HTML should be diffed as well - not just its children\n const isMatchElement = token.includes('data-enable-match=\"true\"')\n const isMatchExplicitlyDisabled = token.includes('data-enable-match=\"false\"')\n const isHtmlTag = !!token.match(htmlTagReg)?.length\n\n if (isMatchExplicitlyDisabled) {\n textStartIndex = i + 1\n result += token\n }\n // this token is html tag\n else if (!isMatchElement && isHtmlTag) {\n // handle text tokens before\n if (i > textStartIndex) {\n result += this.dressUpText(type, tokens.slice(textStartIndex, i))\n }\n // handle this tag\n textStartIndex = i + 1\n if (token.match(htmlVideoTagReg)) {\n result += this.dressUpBlockTag(type, token)\n } /* else if ([htmlImgTagReg].some((item) => token.match(item))) {\n result += this.dressUpInlineTag(type, token)\n }*/ else {\n result += token\n }\n } else if (isMatchElement && isHtmlTag) {\n // handle text tokens before\n if (i > textStartIndex) {\n result += this.dressUpText(type, tokens.slice(textStartIndex, i))\n }\n\n // handle this tag\n textStartIndex = i + 1\n // Add data-match-type to the tag that can be styled\n const newToken = this.dressupMatchEnabledHtmlTag(type, token)\n\n result += newToken\n }\n }\n if (textStartIndex < tokensLength) {\n result += this.dressUpText(type, tokens.slice(textStartIndex))\n }\n return result\n }\n\n private dressUpInlineTag(type: BaseOpType, token: string): string {\n if (type === 'create') {\n return `<span class=\"${this.config.classNames.createInline}\">${token}</span>`\n }\n if (type === 'delete') {\n return `<span class=\"${this.config.classNames.deleteInline}\">${token}</span>`\n }\n return ''\n }\n\n private dressupMatchEnabledHtmlTag(type: BaseOpType, token: string): string {\n // token is a single html tag, e.g. <a data-enable-match=\"true\" href=\"https://2\" rel=undefined target=undefined>\n // add data-match-type to the tag\n const tagName = token.match(htmlStartTagReg)?.groups?.name\n if (!tagName) {\n return token\n }\n const tagNameLength = tagName.length + 1\n const matchType = type === 'create' ? 'create' : 'delete'\n return `${token.slice(0, tagNameLength)} data-match-type=\"${matchType}\"${token.slice(\n tagNameLength,\n token.length,\n )}`\n }\n\n private dressUpText(type: BaseOpType, tokens: string[]): string {\n const text = tokens.join('')\n if (!text.trim()) {\n return ''\n }\n if (type === 'create') {\n return `<span data-match-type=\"create\">${text}</span>`\n }\n if (type === 'delete') {\n return `<span data-match-type=\"delete\">${text}</span>`\n }\n return ''\n }\n\n /**\n * Generates a list of token entries that are matched between the old and new HTML. This list will not\n * include token ranges that differ.\n */\n private getMatchedBlockList(): MatchedBlock[] {\n const n1 = this.oldTokens.length\n const n2 = this.newTokens.length\n\n // 1. sync from start\n let start: MatchedBlock | null = null\n let i = 0\n while (i < n1 && i < n2 && this.oldTokens[i] === this.newTokens[i]) {\n i++\n }\n if (i >= this.config.minMatchedSize) {\n start = {\n newEnd: i,\n newStart: 0,\n oldEnd: i,\n oldStart: 0,\n size: i,\n }\n }\n\n // 2. sync from end\n let end: MatchedBlock | null = null\n let e1 = n1 - 1\n let e2 = n2 - 1\n while (i <= e1 && i <= e2 && this.oldTokens[e1] === this.newTokens[e2]) {\n e1--\n e2--\n }\n const size = n1 - 1 - e1\n if (size >= this.config.minMatchedSize) {\n end = {\n newEnd: n2,\n newStart: e2 + 1,\n oldEnd: n1,\n oldStart: e1 + 1,\n size,\n }\n }\n\n // 3. handle rest\n const oldStart = start ? i : 0\n const oldEnd = end ? e1 + 1 : n1\n const newStart = start ? i : 0\n const newEnd = end ? e2 + 1 : n2\n // optimize for large tokens\n if (this.config.greedyMatch) {\n const commonLength = Math.min(oldEnd - oldStart, newEnd - newStart)\n if (commonLength > this.config.greedyBoundary) {\n this.leastCommonLength = Math.floor(commonLength / 3)\n }\n }\n const ret = this.computeMatchedBlockList(oldStart, oldEnd, newStart, newEnd)\n if (start) {\n ret.unshift(start)\n }\n if (end) {\n ret.push(end)\n }\n\n return ret\n }\n\n // Generate operation list by matchedBlockList\n private getOperationList(): Operation[] {\n const operationList: Operation[] = []\n let walkIndexOld = 0\n let walkIndexNew = 0\n for (const matchedBlock of this.matchedBlockList) {\n const isOldStartIndexMatched = walkIndexOld === matchedBlock.oldStart\n const isNewStartIndexMatched = walkIndexNew === matchedBlock.newStart\n const operationBase = {\n newEnd: matchedBlock.newStart,\n newStart: walkIndexNew,\n oldEnd: matchedBlock.oldStart,\n oldStart: walkIndexOld,\n }\n if (!isOldStartIndexMatched && !isNewStartIndexMatched) {\n operationList.push(Object.assign(operationBase, { type: 'replace' as const }))\n } else if (isOldStartIndexMatched && !isNewStartIndexMatched) {\n operationList.push(Object.assign(operationBase, { type: 'create' as const }))\n } else if (!isOldStartIndexMatched && isNewStartIndexMatched) {\n operationList.push(Object.assign(operationBase, { type: 'delete' as const }))\n }\n\n operationList.push({\n type: 'equal',\n newEnd: matchedBlock.newEnd,\n newStart: matchedBlock.newStart,\n oldEnd: matchedBlock.oldEnd,\n oldStart: matchedBlock.oldStart,\n })\n walkIndexOld = matchedBlock.oldEnd\n walkIndexNew = matchedBlock.newEnd\n }\n // handle the tail content\n const maxIndexOld = this.oldTokens.length\n const maxIndexNew = this.newTokens.length\n const tailOperationBase = {\n newEnd: maxIndexNew,\n newStart: walkIndexNew,\n oldEnd: maxIndexOld,\n oldStart: walkIndexOld,\n }\n const isOldFinished = walkIndexOld === maxIndexOld\n const isNewFinished = walkIndexNew === maxIndexNew\n if (!isOldFinished && !isNewFinished) {\n operationList.push(Object.assign(tailOperationBase, { type: 'replace' as const }))\n } else if (isOldFinished && !isNewFinished) {\n operationList.push(Object.assign(tailOperationBase, { type: 'create' as const }))\n } else if (!isOldFinished && isNewFinished) {\n operationList.push(Object.assign(tailOperationBase, { type: 'delete' as const }))\n }\n return operationList\n }\n\n private slideBestMatchedBlock(addA: number, addB: number, len: number): MatchedBlock | null {\n let maxSize = 0\n let bestMatchedBlock: MatchedBlock | null = null\n\n let continuousSize = 0\n for (let i = 0; i < len; i++) {\n if (this.oldTokens[addA + i] === this.newTokens[addB + i]) {\n continuousSize++\n } else {\n continuousSize = 0\n }\n if (continuousSize > maxSize) {\n maxSize = continuousSize\n bestMatchedBlock = {\n newEnd: addB + i + 1,\n newStart: addB + i - continuousSize + 1,\n oldEnd: addA + i + 1,\n oldStart: addA + i - continuousSize + 1,\n size: continuousSize,\n }\n }\n }\n\n return maxSize >= this.config.minMatchedSize ? bestMatchedBlock : null\n }\n\n /**\n * convert HTML to tokens\n * @example\n * tokenize(\"<a> Hello World </a>\")\n * [\"<a>\",\" \", \"Hello\", \" \", \"World\", \" \", \"</a>\"]\n */\n private tokenize(html: string): string[] {\n // atomic token: html tag、continuous numbers or letters、blank spaces、other symbol\n return (\n html.match(\n /<picture[^>]*>.*?<\\/picture>|<video[^>]*>.*?<\\/video>|<[^>]+>|\\w+\\b|\\s+|[^<>\\w]/gs,\n ) || []\n )\n }\n\n public getSideBySideContents(): string[] {\n if (this.sideBySideContents !== undefined) {\n return this.sideBySideContents\n }\n\n let oldHtml = ''\n let newHtml = ''\n let equalSequence = 0\n this.operationList.forEach((operation) => {\n switch (operation.type) {\n case 'create': {\n newHtml += this.dressUpDiffContent(\n 'create',\n this.newTokens.slice(operation.newStart, operation.newEnd),\n )\n break\n }\n\n case 'delete': {\n const deletedTokens = this.oldTokens.slice(operation.oldStart, operation.oldEnd)\n oldHtml += this.dressUpDiffContent('delete', deletedTokens)\n break\n }\n case 'equal': {\n const equalTokens = this.newTokens.slice(operation.newStart, operation.newEnd)\n let equalString = ''\n for (const token of equalTokens) {\n // find start tags and add data-seq to enable sync scroll\n const startTagMatch = token.match(htmlStartTagReg)\n if (startTagMatch) {\n equalSequence += 1\n const tagNameLength = (startTagMatch?.groups?.name?.length ?? 0) + 1\n equalString += `${token.slice(0, tagNameLength)} data-seq=\"${equalSequence}\"${token.slice(tagNameLength)}`\n } else {\n equalString += token\n }\n }\n oldHtml += equalString\n newHtml += equalString\n break\n }\n\n case 'replace': {\n oldHtml += this.dressUpDiffContent(\n 'delete',\n this.oldTokens.slice(operation.oldStart, operation.oldEnd),\n )\n newHtml += this.dressUpDiffContent(\n 'create',\n this.newTokens.slice(operation.newStart, operation.newEnd),\n )\n break\n }\n\n default: {\n console.error('Richtext diff error - invalid operation: ' + String(operation.type))\n }\n }\n })\n\n const result: [string, string] = [oldHtml, newHtml]\n this.sideBySideContents = result\n return result\n }\n\n public getUnifiedContent(): string {\n if (this.unifiedContent !== undefined) {\n return this.unifiedContent\n }\n\n let result = ''\n this.operationList.forEach((operation) => {\n switch (operation.type) {\n case 'create': {\n result += this.dressUpDiffContent(\n 'create',\n this.newTokens.slice(operation.newStart, operation.newEnd),\n )\n break\n }\n\n case 'delete': {\n result += this.dressUpDiffContent(\n 'delete',\n this.oldTokens.slice(operation.oldStart, operation.oldEnd),\n )\n break\n }\n\n case 'equal': {\n for (const token of this.newTokens.slice(operation.newStart, operation.newEnd)) {\n result += token\n }\n break\n }\n\n case 'replace': {\n // handle specially tag replace\n const olds = this.oldTokens.slice(operation.oldStart, operation.oldEnd)\n const news = this.newTokens.slice(operation.newStart, operation.newEnd)\n if (\n olds.length === 1 &&\n news.length === 1 &&\n olds[0]?.match(htmlTagReg) &&\n news[0]?.match(htmlTagReg)\n ) {\n result += news[0]\n break\n }\n\n const deletedTokens: string[] = []\n const createdTokens: string[] = []\n let createIndex = operation.newStart\n for (\n let deleteIndex = operation.oldStart;\n deleteIndex < operation.oldEnd;\n deleteIndex++\n ) {\n const deletedToken = this.oldTokens[deleteIndex]\n\n if (!deletedToken) {\n continue\n }\n\n const matchTagResultD = deletedToken?.match(htmlTagWithNameReg)\n if (matchTagResultD) {\n // handle replaced tag token\n\n // skip special tag\n if ([htmlImgTagReg, htmlVideoTagReg].some((item) => deletedToken?.match(item))) {\n deletedTokens.push(deletedToken)\n continue\n }\n\n // handle normal tag\n result += this.dressUpDiffContent('delete', deletedTokens)\n deletedTokens.splice(0)\n let isTagInNewFind = false\n for (\n let tempCreateIndex = createIndex;\n tempCreateIndex < operation.newEnd;\n tempCreateIndex++\n ) {\n const createdToken = this.newTokens[tempCreateIndex]\n if (!createdToken) {\n continue\n }\n const matchTagResultC = createdToken?.match(htmlTagWithNameReg)\n if (\n matchTagResultC &&\n matchTagResultC.groups?.name === matchTagResultD.groups?.name &&\n matchTagResultC.groups?.isEnd === matchTagResultD.groups?.isEnd\n ) {\n // find first matched tag, but not maybe the expected tag(to optimize)\n isTagInNewFind = true\n result += this.dressUpDiffContent('create', createdTokens)\n result += createdToken\n createdTokens.splice(0)\n createIndex = tempCreateIndex + 1\n break\n } else {\n createdTokens.push(createdToken)\n }\n }\n if (!isTagInNewFind) {\n result += deletedToken\n createdTokens.splice(0)\n }\n } else {\n // token is not a tag\n deletedTokens.push(deletedToken)\n }\n }\n if (createIndex < operation.newEnd) {\n createdTokens.push(...this.newTokens.slice(createIndex, operation.newEnd))\n }\n result += this.dressUpDiffContent('delete', deletedTokens)\n result += this.dressUpDiffContent('create', createdTokens)\n break\n }\n\n default: {\n console.error('Richtext diff error - invalid operation: ' + String(operation.type))\n }\n }\n })\n this.unifiedContent = result\n return result\n }\n}\n"],"mappings":"AAAA;AAgEA;AACA,MAAMA,eAAA,GAAkB;AACxB;AACA,MAAMC,kBAAA,GAAqB;AAE3B,MAAMC,UAAA,GAAa;AACnB,MAAMC,aAAA,GAAgB;AACtB,MAAMC,eAAA,GAAkB;AAExB,OAAO,MAAMC,QAAA;EACMC,MAAA;EACTC,iBAAA,GAA4BC,QAAA;EACnBC,gBAAA,GAAmC,EAAE;EACrCC,SAAA,GAAsB,EAAE;EACxBC,SAAA,GAAsB,EAAE;EACxBC,aAAA,GAA6B,EAAE;EACxCC,kBAAA;EACAC,cAAA;EAERC,YACEC,OAAe,EACfC,OAAe,EACf;IACEC,UAAA,GAAa;MACXC,WAAA,EAAa;MACbC,YAAA,EAAc;MACdC,WAAA,EAAa;MACbC,YAAA,EAAc;IAChB,CAAC;IACDC,cAAA,GAAiB,IAAI;IACrBC,WAAA,GAAc,IAAI;IAClBC,cAAA,GAAiB;EAAC,CACF,GAAG,CAAC,CAAC,EACvB;IACA;IACA,IAAI,CAACnB,MAAM,GAAG;MACZY,UAAA,EAAY;QACVC,WAAA,EAAa;QACbC,YAAA,EAAc;QACdC,WAAA,EAAa;QACbC,YAAA,EAAc;QACd,GAAGJ;MACL;MACAK,cAAA;MACAC,WAAA;MACAC;IACF;IACA;IACAT,OAAA,GAAUA,OAAA,CAAQU,IAAI;IACtBT,OAAA,GAAUA,OAAA,CAAQS,IAAI;IAEtB;IACA,IAAIV,OAAA,KAAYC,OAAA,EAAS;MACvB,IAAI,CAACH,cAAc,GAAGE,OAAA;MACtB,IAAIW,aAAA,G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,KAAA,KAAUR,eAAA,CAAgBjD,MAAM,EAAEyD,KAAA,EAC1D;oBACA;oBACAJ,cAAA,GAAiB;oBACjBhE,MAAA,IAAU,IAAI,CAACH,kBAAkB,CAAC,UAAU2D,aAAA;oBAC5CxD,MAAA,IAAUkE,YAAA;oBACVV,aAAA,CAAcO,MAAM,CAAC;oBACrBN,WAAA,GAAcQ,eAAA,GAAkB;oBAChC;kBACF,OAAO;oBACLT,aAAA,CAAc/D,IAAI,CAACyE,YAAA;kBACrB;gBACF;gBACA,IAAI,CAACF,cAAA,EAAgB;kBACnBhE,MAAA,IAAU2D,YAAA;kBACVH,aAAA,CAAcO,MAAM,CAAC;gBACvB;cACF,OAAO;gBACL;gBACAjB,aAAA,CAAcrD,IAAI,CAACkE,YAAA;cACrB;YACF;YACA,IAAIF,WAAA,GAAcZ,SAAA,CAAUhE,MAAM,EAAE;cAClC2E,aAAA,CAAc/D,IAAI,IAAI,IAAI,CAAC5C,SAAS,CAACwB,KAAK,CAACoF,WAAA,EAAaZ,SAAA,CAAUhE,MAAM;YAC1E;YACAmB,MAAA,IAAU,IAAI,CAACH,kBAAkB,CAAC,UAAUiD,aAAA;YAC5C9C,MAAA,IAAU,IAAI,CAACH,kBAAkB,CAAC,UAAU2D,aAAA;YAC5C;UACF;QAEA;UAAS;YACPN,OAAA,CAAQC,KAAK,CAAC,8CAA8CC,MAAA,CAAOP,SAAA,CAAUlD,IAAI;UACnF;MACF;IACF;IACA,IAAI,CAAC1C,cAAc,GAAG+C,MAAA;IACtB,OAAOA,MAAA;EACT;AACF","ignoreList":[]}
@@ -1,4 +1,5 @@
1
1
  import type { RichTextFieldDiffServerComponent } from 'payload';
2
+ import './htmlDiff/index.scss';
2
3
  import './index.scss';
3
4
  import '../bundled.css';
4
5
  export declare const LexicalDiffComponent: RichTextFieldDiffServerComponent;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/field/Diff/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,SAAS,CAAA;AAI/D,OAAO,cAAc,CAAA;AACrB,OAAO,gBAAgB,CAAA;AAgBvB,eAAO,MAAM,oBAAoB,EAAE,gCAwDlC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/field/Diff/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,SAAS,CAAA;AAM/D,OAAO,uBAAuB,CAAA;AAC9B,OAAO,cAAc,CAAA;AACrB,OAAO,gBAAgB,CAAA;AAcvB,eAAO,MAAM,oBAAoB,EAAE,gCAmDlC,CAAA"}
@@ -1,7 +1,8 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { FieldDiffContainer, getHTMLDiffComponents } from '@payloadcms/ui/rsc';
3
- import '../bundled.css';
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { getTranslation } from '@payloadcms/translations';
3
+ import { FieldDiffLabel } from '@payloadcms/ui/rsc';
4
4
  import React from 'react';
5
+ import '../bundled.css';
5
6
  import { convertLexicalToHTMLAsync } from '../../features/converters/lexicalToHtml/async/index.js';
6
7
  import { getPayloadPopulateFn } from '../../features/converters/utilities/payloadPopulateFn.js';
7
8
  import { LinkDiffHTMLConverterAsync } from './converters/link.js';
@@ -9,15 +10,15 @@ import { ListItemDiffHTMLConverterAsync } from './converters/listitem/index.js';
9
10
  import { RelationshipDiffHTMLConverterAsync } from './converters/relationship/index.js';
10
11
  import { UnknownDiffHTMLConverterAsync } from './converters/unknown/index.js';
11
12
  import { UploadDiffHTMLConverterAsync } from './converters/upload/index.js';
13
+ import { HtmlDiff } from './htmlDiff/index.js';
12
14
  const baseClass = 'lexical-diff';
13
15
  export const LexicalDiffComponent = async args => {
14
16
  const {
15
- comparisonValue: valueFrom,
17
+ comparisonValue,
16
18
  field,
17
19
  i18n,
18
20
  locale,
19
- nestingLevel,
20
- versionValue: valueTo
21
+ versionValue
21
22
  } = args;
22
23
  const converters = ({
23
24
  defaultConverters
@@ -43,35 +44,39 @@ export const LexicalDiffComponent = async args => {
43
44
  depth: 1,
44
45
  req: args.req
45
46
  });
46
- const fromHTML = await convertLexicalToHTMLAsync({
47
+ const comparisonHTML = await convertLexicalToHTMLAsync({
47
48
  converters,
48
- data: valueFrom,
49
- disableContainer: true,
49
+ data: comparisonValue,
50
50
  populate: payloadPopulateFn
51
51
  });
52
- const toHTML = await convertLexicalToHTMLAsync({
52
+ const versionHTML = await convertLexicalToHTMLAsync({
53
53
  converters,
54
- data: valueTo,
55
- disableContainer: true,
54
+ data: versionValue,
56
55
  populate: payloadPopulateFn
57
56
  });
58
- const {
59
- From,
60
- To
61
- } = getHTMLDiffComponents({
62
- fromHTML,
63
- toHTML
64
- });
65
- return /*#__PURE__*/_jsx(FieldDiffContainer, {
57
+ const diffHTML = new HtmlDiff(comparisonHTML, versionHTML);
58
+ const [oldHTML, newHTML] = diffHTML.getSideBySideContents();
59
+ return /*#__PURE__*/_jsxs("div", {
66
60
  className: baseClass,
67
- From: From,
68
- i18n: i18n,
69
- label: {
70
- label: field.label,
71
- locale
72
- },
73
- nestingLevel: nestingLevel,
74
- To: To
61
+ children: [/*#__PURE__*/_jsxs(FieldDiffLabel, {
62
+ children: [locale && /*#__PURE__*/_jsx("span", {
63
+ className: `${baseClass}__locale-label`,
64
+ children: locale
65
+ }), 'label' in field && typeof field.label !== 'function' && getTranslation(field.label || '', i18n)]
66
+ }), /*#__PURE__*/_jsxs("div", {
67
+ className: `${baseClass}__diff-container`,
68
+ children: [oldHTML && /*#__PURE__*/_jsx("div", {
69
+ className: `${baseClass}__diff-old`,
70
+ dangerouslySetInnerHTML: {
71
+ __html: oldHTML
72
+ }
73
+ }), newHTML && /*#__PURE__*/_jsx("div", {
74
+ className: `${baseClass}__diff-new`,
75
+ dangerouslySetInnerHTML: {
76
+ __html: newHTML
77
+ }
78
+ })]
79
+ })]
75
80
  });
76
81
  };
77
82
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["FieldDiffContainer","getHTMLDiffComponents","React","convertLexicalToHTMLAsync","getPayloadPopulateFn","LinkDiffHTMLConverterAsync","ListItemDiffHTMLConverterAsync","RelationshipDiffHTMLConverterAsync","UnknownDiffHTMLConverterAsync","UploadDiffHTMLConverterAsync","baseClass","LexicalDiffComponent","args","comparisonValue","valueFrom","field","i18n","locale","nestingLevel","versionValue","valueTo","converters","defaultConverters","req","payloadPopulateFn","currentDepth","depth","fromHTML","data","disableContainer","populate","toHTML","From","To","_jsx","className","label"],"sources":["../../../src/field/Diff/index.tsx"],"sourcesContent":["import type { SerializedEditorState } from 'lexical'\nimport type { RichTextFieldDiffServerComponent } from 'payload'\n\nimport { FieldDiffContainer, getHTMLDiffComponents } from '@payloadcms/ui/rsc'\n\nimport './index.scss'\nimport '../bundled.css'\n\nimport React from 'react'\n\nimport type { HTMLConvertersFunctionAsync } from '../../features/converters/lexicalToHtml/async/types.js'\n\nimport { convertLexicalToHTMLAsync } from '../../features/converters/lexicalToHtml/async/index.js'\nimport { getPayloadPopulateFn } from '../../features/converters/utilities/payloadPopulateFn.js'\nimport { LinkDiffHTMLConverterAsync } from './converters/link.js'\nimport { ListItemDiffHTMLConverterAsync } from './converters/listitem/index.js'\nimport { RelationshipDiffHTMLConverterAsync } from './converters/relationship/index.js'\nimport { UnknownDiffHTMLConverterAsync } from './converters/unknown/index.js'\nimport { UploadDiffHTMLConverterAsync } from './converters/upload/index.js'\n\nconst baseClass = 'lexical-diff'\n\nexport const LexicalDiffComponent: RichTextFieldDiffServerComponent = async (args) => {\n const {\n comparisonValue: valueFrom,\n field,\n i18n,\n locale,\n nestingLevel,\n versionValue: valueTo,\n } = args\n\n const converters: HTMLConvertersFunctionAsync = ({ defaultConverters }) => ({\n ...defaultConverters,\n ...LinkDiffHTMLConverterAsync({}),\n ...ListItemDiffHTMLConverterAsync,\n ...UploadDiffHTMLConverterAsync({ i18n: args.i18n, req: args.req }),\n ...RelationshipDiffHTMLConverterAsync({ i18n: args.i18n, req: args.req }),\n ...UnknownDiffHTMLConverterAsync({ i18n: args.i18n, req: args.req }),\n })\n\n const payloadPopulateFn = await getPayloadPopulateFn({\n currentDepth: 0,\n depth: 1,\n req: args.req,\n })\n const fromHTML = await convertLexicalToHTMLAsync({\n converters,\n data: valueFrom as SerializedEditorState,\n disableContainer: true,\n populate: payloadPopulateFn,\n })\n\n const toHTML = await convertLexicalToHTMLAsync({\n converters,\n data: valueTo as SerializedEditorState,\n disableContainer: true,\n populate: payloadPopulateFn,\n })\n\n const { From, To } = getHTMLDiffComponents({\n fromHTML,\n toHTML,\n })\n\n return (\n <FieldDiffContainer\n className={baseClass}\n From={From}\n i18n={i18n}\n label={{\n label: field.label,\n locale,\n }}\n nestingLevel={nestingLevel}\n To={To}\n />\n )\n}\n"],"mappings":";AAGA,SAASA,kBAAkB,EAAEC,qBAAqB,QAAQ;AAG1D,OAAO;AAEP,OAAOC,KAAA,MAAW;AAIlB,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,oBAAoB,QAAQ;AACrC,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,8BAA8B,QAAQ;AAC/C,SAASC,kCAAkC,QAAQ;AACnD,SAASC,6BAA6B,QAAQ;AAC9C,SAASC,4BAA4B,QAAQ;AAE7C,MAAMC,SAAA,GAAY;AAElB,OAAO,MAAMC,oBAAA,GAAyD,MAAOC,IAAA;EAC3E,MAAM;IACJC,eAAA,EAAiBC,SAAS;IAC1BC,KAAK;IACLC,IAAI;IACJC,MAAM;IACNC,YAAY;IACZC,YAAA,EAAcC;EAAO,CACtB,GAAGR,IAAA;EAEJ,MAAMS,UAAA,GAA0CA,CAAC;IAAEC;EAAiB,CAAE,MAAM;IAC1E,GAAGA,iBAAiB;IACpB,GAAGjB,0BAAA,CAA2B,CAAC,EAAE;IACjC,GAAGC,8BAA8B;IACjC,GAAGG,4BAAA,CAA6B;MAAEO,IAAA,EAAMJ,IAAA,CAAKI,IAAI;MAAEO,GAAA,EAAKX,IAAA,CAAKW;IAAI,EAAE;IACnE,GAAGhB,kCAAA,CAAmC;MAAES,IAAA,EAAMJ,IAAA,CAAKI,IAAI;MAAEO,GAAA,EAAKX,IAAA,CAAKW;IAAI,EAAE;IACzE,GAAGf,6BAAA,CAA8B;MAAEQ,IAAA,EAAMJ,IAAA,CAAKI,IAAI;MAAEO,GAAA,EAAKX,IAAA,CAAKW;IAAI;EACpE;EAEA,MAAMC,iBAAA,GAAoB,MAAMpB,oBAAA,CAAqB;IACnDqB,YAAA,EAAc;IACdC,KAAA,EAAO;IACPH,GAAA,EAAKX,IAAA,CAAKW;EACZ;EACA,MAAMI,QAAA,GAAW,MAAMxB,yBAAA,CAA0B;IAC/CkB,UAAA;IACAO,IAAA,EAAMd,SAAA;IACNe,gBAAA,EAAkB;IAClBC,QAAA,EAAUN;EACZ;EAEA,MAAMO,MAAA,GAAS,MAAM5B,yBAAA,CAA0B;IAC7CkB,UAAA;IACAO,IAAA,EAAMR,OAAA;IACNS,gBAAA,EAAkB;IAClBC,QAAA,EAAUN;EACZ;EAEA,MAAM;IAAEQ,IAAI;IAAEC;EAAE,CAAE,GAAGhC,qBAAA,CAAsB;IACzC0B,QAAA;IACAI;EACF;EAEA,oBACEG,IAAA,CAAClC,kBAAA;IACCmC,SAAA,EAAWzB,SAAA;IACXsB,IAAA,EAAMA,IAAA;IACNhB,IAAA,EAAMA,IAAA;IACNoB,KAAA,EAAO;MACLA,KAAA,EAAOrB,KAAA,CAAMqB,KAAK;MAClBnB;IACF;IACAC,YAAA,EAAcA,YAAA;IACde,EAAA,EAAIA;;AAGV","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["getTranslation","FieldDiffLabel","React","convertLexicalToHTMLAsync","getPayloadPopulateFn","LinkDiffHTMLConverterAsync","ListItemDiffHTMLConverterAsync","RelationshipDiffHTMLConverterAsync","UnknownDiffHTMLConverterAsync","UploadDiffHTMLConverterAsync","HtmlDiff","baseClass","LexicalDiffComponent","args","comparisonValue","field","i18n","locale","versionValue","converters","defaultConverters","req","payloadPopulateFn","currentDepth","depth","comparisonHTML","data","populate","versionHTML","diffHTML","oldHTML","newHTML","getSideBySideContents","_jsxs","className","_jsx","label","dangerouslySetInnerHTML","__html"],"sources":["../../../src/field/Diff/index.tsx"],"sourcesContent":["import type { SerializedEditorState } from 'lexical'\nimport type { RichTextFieldDiffServerComponent } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { FieldDiffLabel } from '@payloadcms/ui/rsc'\nimport React from 'react'\n\nimport './htmlDiff/index.scss'\nimport './index.scss'\nimport '../bundled.css'\n\nimport type { HTMLConvertersFunctionAsync } from '../../features/converters/lexicalToHtml/async/types.js'\n\nimport { convertLexicalToHTMLAsync } from '../../features/converters/lexicalToHtml/async/index.js'\nimport { getPayloadPopulateFn } from '../../features/converters/utilities/payloadPopulateFn.js'\nimport { LinkDiffHTMLConverterAsync } from './converters/link.js'\nimport { ListItemDiffHTMLConverterAsync } from './converters/listitem/index.js'\nimport { RelationshipDiffHTMLConverterAsync } from './converters/relationship/index.js'\nimport { UnknownDiffHTMLConverterAsync } from './converters/unknown/index.js'\nimport { UploadDiffHTMLConverterAsync } from './converters/upload/index.js'\nimport { HtmlDiff } from './htmlDiff/index.js'\nconst baseClass = 'lexical-diff'\n\nexport const LexicalDiffComponent: RichTextFieldDiffServerComponent = async (args) => {\n const { comparisonValue, field, i18n, locale, versionValue } = args\n\n const converters: HTMLConvertersFunctionAsync = ({ defaultConverters }) => ({\n ...defaultConverters,\n ...LinkDiffHTMLConverterAsync({}),\n ...ListItemDiffHTMLConverterAsync,\n ...UploadDiffHTMLConverterAsync({ i18n: args.i18n, req: args.req }),\n ...RelationshipDiffHTMLConverterAsync({ i18n: args.i18n, req: args.req }),\n ...UnknownDiffHTMLConverterAsync({ i18n: args.i18n, req: args.req }),\n })\n\n const payloadPopulateFn = await getPayloadPopulateFn({\n currentDepth: 0,\n depth: 1,\n req: args.req,\n })\n const comparisonHTML = await convertLexicalToHTMLAsync({\n converters,\n data: comparisonValue as SerializedEditorState,\n populate: payloadPopulateFn,\n })\n\n const versionHTML = await convertLexicalToHTMLAsync({\n converters,\n data: versionValue as SerializedEditorState,\n populate: payloadPopulateFn,\n })\n\n const diffHTML = new HtmlDiff(comparisonHTML, versionHTML)\n\n const [oldHTML, newHTML] = diffHTML.getSideBySideContents()\n\n return (\n <div className={baseClass}>\n <FieldDiffLabel>\n {locale && <span className={`${baseClass}__locale-label`}>{locale}</span>}\n {'label' in field &&\n typeof field.label !== 'function' &&\n getTranslation(field.label || '', i18n)}\n </FieldDiffLabel>\n <div className={`${baseClass}__diff-container`}>\n {oldHTML && (\n <div className={`${baseClass}__diff-old`} dangerouslySetInnerHTML={{ __html: oldHTML }} />\n )}\n {newHTML && (\n <div className={`${baseClass}__diff-new`} dangerouslySetInnerHTML={{ __html: newHTML }} />\n )}\n </div>\n </div>\n )\n}\n"],"mappings":";AAGA,SAASA,cAAc,QAAQ;AAC/B,SAASC,cAAc,QAAQ;AAC/B,OAAOC,KAAA,MAAW;AAIlB,OAAO;AAIP,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,oBAAoB,QAAQ;AACrC,SAASC,0BAA0B,QAAQ;AAC3C,SAASC,8BAA8B,QAAQ;AAC/C,SAASC,kCAAkC,QAAQ;AACnD,SAASC,6BAA6B,QAAQ;AAC9C,SAASC,4BAA4B,QAAQ;AAC7C,SAASC,QAAQ,QAAQ;AACzB,MAAMC,SAAA,GAAY;AAElB,OAAO,MAAMC,oBAAA,GAAyD,MAAOC,IAAA;EAC3E,MAAM;IAAEC,eAAe;IAAEC,KAAK;IAAEC,IAAI;IAAEC,MAAM;IAAEC;EAAY,CAAE,GAAGL,IAAA;EAE/D,MAAMM,UAAA,GAA0CA,CAAC;IAAEC;EAAiB,CAAE,MAAM;IAC1E,GAAGA,iBAAiB;IACpB,GAAGf,0BAAA,CAA2B,CAAC,EAAE;IACjC,GAAGC,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C;QAAID,SAAA,EAAW,GAAGvB,SAAA,YAAqB;QAAE0B,uBAAA,EAAyB;UAAEC,MAAA,EAAQR;QAAQ;UAEtFC,OAAA,iBACCI,IAAA,CAAC;QAAID,SAAA,EAAW,GAAGvB,SAAA,YAAqB;QAAE0B,uBAAA,EAAyB;UAAEC,MAAA,EAAQP;QAAQ;;;;AAK/F","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAGxE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAE7E,OAAO,mCAAmC,CAAA;AAC1C,OAAO,eAAe,CAAA;AACtB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAM5D,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAC/B;IACE,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAA;CACnD,GAAG,yBAAyB,CAiK9B,CAAA;AAaD,eAAO,MAAM,QAAQ,EAAE,OAAO,iBAAqC,CAAA"}
1
+ {"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../src/field/Field.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAGxE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAE7E,OAAO,mCAAmC,CAAA;AAC1C,OAAO,eAAe,CAAA;AACtB,OAAO,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAM5D,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAC/B;IACE,QAAQ,CAAC,YAAY,EAAE,2BAA2B,CAAA;CACnD,GAAG,yBAAyB,CAgK9B,CAAA;AAaD,eAAO,MAAM,QAAQ,EAAE,OAAO,iBAAqC,CAAA"}
@@ -13,7 +13,6 @@ const RichTextComponent = props => {
13
13
  editorConfig,
14
14
  field,
15
15
  field: {
16
- name,
17
16
  admin: {
18
17
  className,
19
18
  description,
@@ -28,7 +27,6 @@ const RichTextComponent = props => {
28
27
  validate
29
28
  } = props;
30
29
  const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin;
31
- const path = pathFromProps ?? name;
32
30
  const editDepth = useEditDepth();
33
31
  const memoizedValidate = useCallback((value, validationOptions) => {
34
32
  if (typeof validate === 'function') {
@@ -54,11 +52,12 @@ const RichTextComponent = props => {
54
52
  } = {},
55
53
  disabled: disabledFromField,
56
54
  initialValue,
55
+ path,
57
56
  setValue,
58
57
  showError,
59
58
  value: value_0
60
59
  } = useField({
61
- path,
60
+ potentiallyStalePath: pathFromProps,
62
61
  validate: memoizedValidate
63
62
  });
64
63
  const disabled = readOnlyFromProps || disabledFromField;
@@ -1 +1 @@
1
- {"version":3,"file":"Field.js","names":["FieldDescription","FieldError","FieldLabel","RenderCustomComponent","useEditDepth","useEffectEvent","useField","mergeFieldStyles","React","useCallback","useEffect","useMemo","useState","ErrorBoundary","LexicalProvider","baseClass","RichTextComponent","props","editorConfig","field","name","admin","className","description","readOnly","readOnlyFromAdmin","label","localized","required","path","pathFromProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","editDepth","memoizedValidate","value","validationOptions","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","disabledFromField","initialValue","setValue","showError","isSmallWidthViewport","setIsSmallWidthViewport","rerenderProviderKey","setRerenderProviderKey","prevInitialValueRef","useRef","prevValueRef","updateViewPortWidth","isNextSmallWidthViewport","window","matchMedia","matches","addEventListener","removeEventListener","classes","hideGutter","filter","Boolean","join","pathWithEditDepth","updateFieldValue","editorState","newState","toJSON","current","handleChange","requestIdleCallback","styles","handleInitialValueChange","JSON","stringify","Date","Object","is","_jsxs","style","_jsx","CustomComponent","Fallback","fallbackRender","onReset","composerKey","fieldProps","onChange","error","role","color","message","RichText"],"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type { EditorState, SerializedEditorState } from 'lexical'\nimport type { Validate } from 'payload'\n\nimport {\n FieldDescription,\n FieldError,\n FieldLabel,\n RenderCustomComponent,\n useEditDepth,\n useEffectEvent,\n useField,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\nimport { ErrorBoundary } from 'react-error-boundary'\n\nimport type { SanitizedClientEditorConfig } from '../lexical/config/types.js'\n\nimport '../lexical/theme/EditorTheme.scss'\nimport './bundled.css'\nimport './index.scss'\n\nimport type { LexicalRichTextFieldProps } from '../types.js'\n\nimport { LexicalProvider } from '../lexical/LexicalProvider.js'\n\nconst baseClass = 'rich-text-lexical'\n\nconst RichTextComponent: React.FC<\n {\n readonly editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n } & LexicalRichTextFieldProps\n> = (props) => {\n const {\n editorConfig,\n field,\n field: {\n name,\n admin: { className, description, readOnly: readOnlyFromAdmin } = {},\n label,\n localized,\n required,\n },\n path: pathFromProps,\n readOnly: readOnlyFromTopLevelProps,\n validate, // Users can pass in client side validation if they WANT to, but it's not required anymore\n } = props\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n const path = pathFromProps ?? name\n\n const editDepth = useEditDepth()\n\n const memoizedValidate = useCallback<Validate>(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n return validate(value, { ...validationOptions, required })\n }\n return true\n },\n // Important: do not add props to the dependencies array.\n // This would cause an infinite loop and endless re-rendering.\n // Removing props from the dependencies array fixed this issue: https://github.com/payloadcms/payload/issues/3709\n [validate, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled: disabledFromField,\n initialValue,\n setValue,\n showError,\n value,\n } = useField<SerializedEditorState>({\n path,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || disabledFromField\n\n const [isSmallWidthViewport, setIsSmallWidthViewport] = useState<boolean>(false)\n const [rerenderProviderKey, setRerenderProviderKey] = useState<Date>()\n\n const prevInitialValueRef = React.useRef<SerializedEditorState | undefined>(initialValue)\n const prevValueRef = React.useRef<SerializedEditorState | undefined>(value)\n\n useEffect(() => {\n const updateViewPortWidth = () => {\n const isNextSmallWidthViewport = window.matchMedia('(max-width: 768px)').matches\n\n if (isNextSmallWidthViewport !== isSmallWidthViewport) {\n setIsSmallWidthViewport(isNextSmallWidthViewport)\n }\n }\n updateViewPortWidth()\n window.addEventListener('resize', updateViewPortWidth)\n\n return () => {\n window.removeEventListener('resize', updateViewPortWidth)\n }\n }, [isSmallWidthViewport])\n\n const classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n disabled && `${baseClass}--read-only`,\n editorConfig?.admin?.hideGutter !== true && !isSmallWidthViewport\n ? `${baseClass}--show-gutter`\n : null,\n ]\n .filter(Boolean)\n .join(' ')\n\n const pathWithEditDepth = `${path}.${editDepth}`\n\n const updateFieldValue = (editorState: EditorState) => {\n const newState = editorState.toJSON()\n prevValueRef.current = newState\n setValue(newState)\n }\n\n const handleChange = useCallback(\n (editorState: EditorState) => {\n if (typeof window.requestIdleCallback === 'function') {\n requestIdleCallback(() => updateFieldValue(editorState))\n } else {\n updateFieldValue(editorState)\n }\n },\n [setValue],\n )\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n const handleInitialValueChange = useEffectEvent(\n (initialValue: SerializedEditorState | undefined) => {\n // Object deep equality check here, as re-mounting the editor if\n // the new value is the same as the old one is not necessary\n if (\n prevValueRef.current !== value &&\n JSON.stringify(prevValueRef.current) !== JSON.stringify(value)\n ) {\n prevInitialValueRef.current = initialValue\n prevValueRef.current = value\n setRerenderProviderKey(new Date())\n }\n },\n )\n\n useEffect(() => {\n // Needs to trigger for object reference changes - otherwise,\n // reacting to the same initial value change twice will cause\n // the second change to be ignored, even though the value has changed.\n // That's because initialValue is not kept up-to-date\n if (!Object.is(initialValue, prevInitialValueRef.current)) {\n handleInitialValueChange(initialValue)\n }\n }, [initialValue])\n\n return (\n <div className={classes} key={pathWithEditDepth} style={styles}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n {Label || <FieldLabel label={label} localized={localized} path={path} required={required} />}\n <div className={`${baseClass}__wrap`}>\n <ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>\n {BeforeInput}\n <LexicalProvider\n composerKey={pathWithEditDepth}\n editorConfig={editorConfig}\n fieldProps={props}\n isSmallWidthViewport={isSmallWidthViewport}\n key={JSON.stringify({ path, rerenderProviderKey })} // makes sure lexical is completely re-rendered when initialValue changes, bypassing the lexical-internal value memoization. That way, external changes to the form will update the editor. More infos in PR description (https://github.com/payloadcms/payload/pull/5010)\n onChange={handleChange}\n readOnly={disabled}\n value={value}\n />\n {AfterInput}\n </ErrorBoundary>\n {Description}\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n </div>\n )\n}\n\nfunction fallbackRender({ error }: { error: Error }) {\n // Call resetErrorBoundary() to reset the error boundary and retry the render.\n\n return (\n <div className=\"errorBoundary\" role=\"alert\">\n <p>Something went wrong:</p>\n <pre style={{ color: 'red' }}>{error.message}</pre>\n </div>\n )\n}\n\nexport const RichText: typeof RichTextComponent = RichTextComponent\n"],"mappings":"AAAA;;;AAIA,SACEA,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,qBAAqB,EACrBC,YAAY,EACZC,cAAc,EACdC,QAAQ,QACH;AACP,SAASC,gBAAgB,QAAQ;AACjC,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AACjE,SAASC,aAAa,QAAQ;AAK9B,OAAO;AAKP,SAASC,eAAe,QAAQ;AAEhC,MAAMC,SAAA,GAAY;AAElB,MAAMC,iBAA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sBA,oBAAA;UAEtB2C,QAAA,EAAUlB,YAAA;UACVlD,QAAA,EAAUoB,QAAA;UACVR,KAAA,EAAOA;WAHF0C,IAAA,CAAKC,SAAS,CAAC;UAAElD,IAAA;UAAMsB;QAAoB,KAKjDZ,UAAA;UAEFE,WAAA,E,aACD4C,IAAA,CAAClF,qBAAA;QACCmF,eAAA,EAAiB7C,WAAA;QACjB8C,QAAA,eAAUF,IAAA,CAACrF,gBAAA;UAAiBuB,WAAA,EAAaA,WAAA;UAAaM,IAAA,EAAMA;;;;KAxBpCuC,iBAAA;AA6BlC;AAEA,SAASoB,eAAe;EAAEK;AAAK,CAAoB;EACjD;EAEA,oBACEV,KAAA,CAAC;IAAI7D,SAAA,EAAU;IAAgBwE,IAAA,EAAK;4BAClCT,IAAA,CAAC;gBAAE;qBACHA,IAAA,CAAC;MAAID,KAAA,EAAO;QAAEW,KAAA,EAAO;MAAM;gBAAIF,KAAA,CAAMG;;;AAG3C;AAEA,OAAO,MAAMC,QAAA,GAAqCjF,iBAAA","ignoreList":[]}
1
+ {"version":3,"file":"Field.js","names":["FieldDescription","FieldError","FieldLabel","RenderCustomComponent","useEditDepth","useEffectEvent","useField","mergeFieldStyles","React","useCallback","useEffect","useMemo","useState","ErrorBoundary","LexicalProvider","baseClass","RichTextComponent","props","editorConfig","field","admin","className","description","readOnly","readOnlyFromAdmin","label","localized","required","path","pathFromProps","readOnlyFromTopLevelProps","validate","readOnlyFromProps","editDepth","memoizedValidate","value","validationOptions","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","disabledFromField","initialValue","setValue","showError","potentiallyStalePath","isSmallWidthViewport","setIsSmallWidthViewport","rerenderProviderKey","setRerenderProviderKey","prevInitialValueRef","useRef","prevValueRef","updateViewPortWidth","isNextSmallWidthViewport","window","matchMedia","matches","addEventListener","removeEventListener","classes","hideGutter","filter","Boolean","join","pathWithEditDepth","updateFieldValue","editorState","newState","toJSON","current","handleChange","requestIdleCallback","styles","handleInitialValueChange","JSON","stringify","Date","Object","is","_jsxs","style","_jsx","CustomComponent","Fallback","fallbackRender","onReset","composerKey","fieldProps","onChange","error","role","color","message","RichText"],"sources":["../../src/field/Field.tsx"],"sourcesContent":["'use client'\nimport type { EditorState, SerializedEditorState } from 'lexical'\nimport type { Validate } from 'payload'\n\nimport {\n FieldDescription,\n FieldError,\n FieldLabel,\n RenderCustomComponent,\n useEditDepth,\n useEffectEvent,\n useField,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\nimport { ErrorBoundary } from 'react-error-boundary'\n\nimport type { SanitizedClientEditorConfig } from '../lexical/config/types.js'\n\nimport '../lexical/theme/EditorTheme.scss'\nimport './bundled.css'\nimport './index.scss'\n\nimport type { LexicalRichTextFieldProps } from '../types.js'\n\nimport { LexicalProvider } from '../lexical/LexicalProvider.js'\n\nconst baseClass = 'rich-text-lexical'\n\nconst RichTextComponent: React.FC<\n {\n readonly editorConfig: SanitizedClientEditorConfig // With rendered features n stuff\n } & LexicalRichTextFieldProps\n> = (props) => {\n const {\n editorConfig,\n field,\n field: {\n admin: { className, description, readOnly: readOnlyFromAdmin } = {},\n label,\n localized,\n required,\n },\n path: pathFromProps,\n readOnly: readOnlyFromTopLevelProps,\n validate, // Users can pass in client side validation if they WANT to, but it's not required anymore\n } = props\n\n const readOnlyFromProps = readOnlyFromTopLevelProps || readOnlyFromAdmin\n\n const editDepth = useEditDepth()\n\n const memoizedValidate = useCallback<Validate>(\n (value, validationOptions) => {\n if (typeof validate === 'function') {\n // @ts-expect-error - vestiges of when tsconfig was not strict. Feel free to improve\n return validate(value, { ...validationOptions, required })\n }\n return true\n },\n // Important: do not add props to the dependencies array.\n // This would cause an infinite loop and endless re-rendering.\n // Removing props from the dependencies array fixed this issue: https://github.com/payloadcms/payload/issues/3709\n [validate, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled: disabledFromField,\n initialValue,\n path,\n setValue,\n showError,\n value,\n } = useField<SerializedEditorState>({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const disabled = readOnlyFromProps || disabledFromField\n\n const [isSmallWidthViewport, setIsSmallWidthViewport] = useState<boolean>(false)\n const [rerenderProviderKey, setRerenderProviderKey] = useState<Date>()\n\n const prevInitialValueRef = React.useRef<SerializedEditorState | undefined>(initialValue)\n const prevValueRef = React.useRef<SerializedEditorState | undefined>(value)\n\n useEffect(() => {\n const updateViewPortWidth = () => {\n const isNextSmallWidthViewport = window.matchMedia('(max-width: 768px)').matches\n\n if (isNextSmallWidthViewport !== isSmallWidthViewport) {\n setIsSmallWidthViewport(isNextSmallWidthViewport)\n }\n }\n updateViewPortWidth()\n window.addEventListener('resize', updateViewPortWidth)\n\n return () => {\n window.removeEventListener('resize', updateViewPortWidth)\n }\n }, [isSmallWidthViewport])\n\n const classes = [\n baseClass,\n 'field-type',\n className,\n showError && 'error',\n disabled && `${baseClass}--read-only`,\n editorConfig?.admin?.hideGutter !== true && !isSmallWidthViewport\n ? `${baseClass}--show-gutter`\n : null,\n ]\n .filter(Boolean)\n .join(' ')\n\n const pathWithEditDepth = `${path}.${editDepth}`\n\n const updateFieldValue = (editorState: EditorState) => {\n const newState = editorState.toJSON()\n prevValueRef.current = newState\n setValue(newState)\n }\n\n const handleChange = useCallback(\n (editorState: EditorState) => {\n if (typeof window.requestIdleCallback === 'function') {\n requestIdleCallback(() => updateFieldValue(editorState))\n } else {\n updateFieldValue(editorState)\n }\n },\n [setValue],\n )\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n const handleInitialValueChange = useEffectEvent(\n (initialValue: SerializedEditorState | undefined) => {\n // Object deep equality check here, as re-mounting the editor if\n // the new value is the same as the old one is not necessary\n if (\n prevValueRef.current !== value &&\n JSON.stringify(prevValueRef.current) !== JSON.stringify(value)\n ) {\n prevInitialValueRef.current = initialValue\n prevValueRef.current = value\n setRerenderProviderKey(new Date())\n }\n },\n )\n\n useEffect(() => {\n // Needs to trigger for object reference changes - otherwise,\n // reacting to the same initial value change twice will cause\n // the second change to be ignored, even though the value has changed.\n // That's because initialValue is not kept up-to-date\n if (!Object.is(initialValue, prevInitialValueRef.current)) {\n handleInitialValueChange(initialValue)\n }\n }, [initialValue])\n\n return (\n <div className={classes} key={pathWithEditDepth} style={styles}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n {Label || <FieldLabel label={label} localized={localized} path={path} required={required} />}\n <div className={`${baseClass}__wrap`}>\n <ErrorBoundary fallbackRender={fallbackRender} onReset={() => {}}>\n {BeforeInput}\n <LexicalProvider\n composerKey={pathWithEditDepth}\n editorConfig={editorConfig}\n fieldProps={props}\n isSmallWidthViewport={isSmallWidthViewport}\n key={JSON.stringify({ path, rerenderProviderKey })} // makes sure lexical is completely re-rendered when initialValue changes, bypassing the lexical-internal value memoization. That way, external changes to the form will update the editor. More infos in PR description (https://github.com/payloadcms/payload/pull/5010)\n onChange={handleChange}\n readOnly={disabled}\n value={value}\n />\n {AfterInput}\n </ErrorBoundary>\n {Description}\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n </div>\n )\n}\n\nfunction fallbackRender({ error }: { error: Error }) {\n // Call resetErrorBoundary() to reset the error boundary and retry the render.\n\n return (\n <div className=\"errorBoundary\" role=\"alert\">\n <p>Something went wrong:</p>\n <pre style={{ color: 'red' }}>{error.message}</pre>\n </div>\n )\n}\n\nexport const RichText: typeof RichTextComponent = RichTextComponent\n"],"mappings":"AAAA;;;AAIA,SACEA,gBAAgB,EAChBC,UAAU,EACVC,UAAU,EACVC,qBAAqB,EACrBC,YAAY,EACZC,cAAc,EACdC,QAAQ,QACH;AACP,SAASC,gBAAgB,QAAQ;AACjC,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AACjE,SAASC,aAAa,QAAQ;AAK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