Skip to content

Commit 2bab271

Browse files
authored
fix(Designer): Revert - Updated HTML Editor to support newline characters (#4808)
* cherry-pick * Revert "fix(Designer): Updated HTML Editor to support newline characters (for dynamic content) (#4635)" This reverts commit f4e1f8b.
1 parent 08b761c commit 2bab271

File tree

4 files changed

+10
-42
lines changed

4 files changed

+10
-42
lines changed

libs/designer-ui/src/lib/editor/base/utils/editorToSegment.ts

+2-28
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ const getChildrenNodesToSegments = (node: ElementNode, segments: ValueSegment[],
3737
export const convertStringToSegments = (
3838
value: string,
3939
nodeMap: Map<string, ValueSegment>,
40-
options?: SegmentParserOptions,
41-
convertSpaceToNewline?: boolean
40+
options?: SegmentParserOptions
4241
): ValueSegment[] => {
4342
if (!value) {
4443
return [];
@@ -90,28 +89,7 @@ export const convertStringToSegments = (
9089
segmentSoFar += currChar;
9190

9291
if (!isInQuotedString && currChar === '}' && currSegmentType === ValueSegmentType.TOKEN) {
93-
let token: ValueSegment | undefined = undefined;
94-
95-
// removes formatting compatibility issues between nodemap and HTML text in the editor
96-
// when opening an action with an HTML editor
97-
if (convertSpaceToNewline) {
98-
// modifiedSegmentSoFar -> in segmentSoFar, replace spaces with no space
99-
const modifiedSegmentSoFar = removeNewlinesAndSpaces(segmentSoFar);
100-
// for each key in nodeMap
101-
for (const key of nodeMap.keys()) {
102-
// keyNoNewline = key, but replace all newlines with no space
103-
const keyNoNewline = removeNewlinesAndSpaces(key);
104-
// if the nodemap key and modified HTML segment match,
105-
// take the corresponding HTML node in the nodemap
106-
if (keyNoNewline === modifiedSegmentSoFar) {
107-
token = nodeMap.get(key);
108-
break;
109-
}
110-
}
111-
} else {
112-
token = nodeMap.get(segmentSoFar);
113-
}
114-
92+
const token = nodeMap.get(segmentSoFar);
11593
if (token) {
11694
// If remove quotes param is set, remove the quotes from previous and next segments if it's a single token
11795
if (options?.removeSingleTokenQuotesWrapping && doubleQuotesStarted && returnSegments.length > 0) {
@@ -164,7 +142,3 @@ const collapseLiteralSegments = (segments: ValueSegment[]): void => {
164142
index++;
165143
}
166144
};
167-
168-
const removeNewlinesAndSpaces = (inputStr: string): string => {
169-
return inputStr.replace(/\s+/g, '').replaceAll(/\n/g, '');
170-
};

libs/designer-ui/src/lib/editor/base/utils/parsesegments.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const appendChildrenNode = (
143143
const childNodeFormat = childNode.getFormat();
144144

145145
if (tokensEnabled && nodeMap) {
146-
const contentAsParameter = convertStringToSegments(decodedTextContent, nodeMap, options, true);
146+
const contentAsParameter = convertStringToSegments(decodedTextContent, nodeMap, options);
147147
contentAsParameter.forEach((segment) => {
148148
const tokenNode = createTokenNodeFromSegment(segment, options, nodeMap);
149149
if (tokenNode) {

libs/designer-ui/src/lib/html/plugins/toolbar/helper/HTMLChangePlugin.tsx

+7-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
encodeStringSegmentTokensInLexicalContext,
88
} from '../../../../editor/base/utils/parsesegments';
99
import {
10-
canReplaceSpanWithId,
1110
cleanHtmlString,
1211
cleanStyleAttribute,
1312
encodeSegmentValueInLexicalContext,
@@ -75,7 +74,6 @@ export const convertEditorState = (
7574
// Create a temporary DOM element to parse the HTML string
7675
const tempElement = getDomFromHtmlEditorString(htmlEditorString, nodeMap);
7776

78-
let idValue = '';
7977
// Loop through all elements and remove unwanted attributes
8078
const elements = tempElement.querySelectorAll('*');
8179
// biome-ignore lint/style/useForOf: Node List isn't iterable
@@ -89,7 +87,7 @@ export const convertEditorState = (
8987
}
9088
if (attribute.name === 'id' && !isValuePlaintext) {
9189
// If we're in the rich HTML editor, encoding occurs at the element level since they are all wrapped in <span>.
92-
idValue = element.getAttribute('id') ?? ''; // e.g., "@{concat('&lt;', '"')}"
90+
const idValue = element.getAttribute('id') ?? ''; // e.g., "@{concat('&lt;', '"')}"
9391
const encodedIdValue = encodeSegmentValueInLexicalContext(idValue); // e.g., "@{concat('%26lt;', '%22')}"
9492
element.setAttribute('id', encodedIdValue);
9593
continue;
@@ -108,11 +106,12 @@ export const convertEditorState = (
108106

109107
// Replace `<span id="..."></span>` with the captured `id` value if it is found in the viable IDs map.
110108
const spanIdPattern = /<span id="(.*?)"><\/span>/g;
111-
let noTokenSpansString = decodedLexicalString;
112-
const decodedLexicalStringWithoutNewlines = decodedLexicalString.replace(/\n/g, '');
113-
if (canReplaceSpanWithId(idValue, nodeMap)) {
114-
noTokenSpansString = decodedLexicalStringWithoutNewlines.replace(spanIdPattern, idValue);
115-
}
109+
const noTokenSpansString = decodedLexicalString.replace(spanIdPattern, (match, idValue) => {
110+
if (nodeMap.get(idValue)) {
111+
return idValue;
112+
}
113+
return match;
114+
});
116115
const valueSegments: ValueSegment[] = convertStringToSegments(noTokenSpansString, nodeMap, { tokensEnabled: true });
117116
resolve(valueSegments);
118117
});

libs/designer-ui/src/lib/html/plugins/toolbar/helper/util.ts

-5
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ export const cleanHtmlString = (html: string): string => {
6565
return cleanedHtmlString;
6666
};
6767

68-
// If we can find the id in the nodemap, return true.
69-
export const canReplaceSpanWithId = (idValue: string, nodeMap: Map<string, ValueSegment>): boolean => {
70-
return nodeMap.get(idValue) !== undefined;
71-
};
72-
7368
export const cleanStyleAttribute = (styleAttributeValue: string): string | undefined => {
7469
const newValue = styleAttributeValue.replace('white-space: pre-wrap;', '').trim();
7570
return newValue.length ? newValue : undefined;

0 commit comments

Comments
 (0)