Skip to content

Commit f96f464

Browse files
committed
fix: removes troubling conversion and cleanup code
1 parent 2ca3300 commit f96f464

4 files changed

Lines changed: 4 additions & 45 deletions

File tree

packages/pluggableWidgets/rich-text-web/src/components/EditorWrapper.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { CSSProperties, ReactElement, useCallback, useContext, useEffect, useRef
99
import { RichTextContainerProps } from "typings/RichTextProps";
1010
import { EditorContext, EditorProvider } from "../store/EditorProvider";
1111
import { useActionEvents } from "../store/useActionEvents";
12-
import { updateLegacyQuillFormats } from "../utils/helpers";
1312
import MendixTheme from "../utils/themes/mxTheme";
1413
import { MxQuillModulesOptions } from "../utils/MxQuill";
1514
import { createPreset } from "./CustomToolbars/presets";
@@ -108,10 +107,6 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
108107

109108
useEffect(() => {
110109
if (quillRef.current) {
111-
const isTransformed = updateLegacyQuillFormats(quillRef.current);
112-
if (isTransformed) {
113-
setAttributeValueDebounce(quillRef.current.getSemanticHTML());
114-
}
115110
if (!isFirstLoad.current) {
116111
executeAction(onLoad);
117112
isFirstLoad.current = true;

packages/pluggableWidgets/rich-text-web/src/utils/MxQuill.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ class MxEditor extends Editor {
6464
* https://github.com/slab/quill/blob/main/packages/quill/src/core/editor.ts
6565
*/
6666
getHTML(index: number, length: number): string {
67+
if (this.isBlank()) {
68+
return "";
69+
}
6770
const [line, lineOffset] = this.scroll.line(index);
6871
if (line) {
6972
const lineLength = line.length();
Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { CSSProperties } from "react";
2-
import Quill from "quill";
3-
import { Delta, Op } from "quill/core";
42
import { RichTextContainerProps } from "typings/RichTextProps";
53

64
export const ACTION_DISPATCHER = "ACTION_DISPATCHER";
@@ -34,36 +32,3 @@ export function constructWrapperStyle(props: RichTextContainerProps): CSSPropert
3432

3533
return wrapperStyle;
3634
}
37-
38-
export function updateLegacyQuillFormats(quill: Quill): boolean {
39-
const results = transformLegacyQuillFormats(quill.getContents());
40-
if (results.isDirty) {
41-
quill.setContents(new Delta(results.data), Quill.sources.API);
42-
}
43-
return results.isDirty;
44-
}
45-
46-
/**
47-
* Transform previous version of Quill formats :
48-
* - previous version us ql-indent-n as classnames for indentation, which is highly dependant on quill's css
49-
* this function will transformed it to use inline style
50-
*/
51-
export function transformLegacyQuillFormats(delta: Delta): { data: Op[]; isDirty: boolean } {
52-
let isDirty = false;
53-
const newDelta: Op[] = delta.map(d => {
54-
if (d.attributes && d.attributes.indent) {
55-
if (!d.attributes.list) {
56-
d.attributes["indent-left"] = (d.attributes.indent as number) * 3;
57-
delete d.attributes.indent;
58-
}
59-
60-
// although there seems no changes here, format.indent have been overriden for getSemanticHTML method
61-
// thus, this will keep being here instead of inside the upper if.
62-
if (!isDirty) {
63-
isDirty = true;
64-
}
65-
}
66-
return d;
67-
});
68-
return { data: newDelta, isDirty };
69-
}

packages/pluggableWidgets/rich-text-web/src/utils/modules/scroll.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import Scroll from "quill/blots/scroll";
22
import MxBlock from "../formats/block";
33

44
export default class MxScroll extends Scroll {
5-
optimize(context?: { [key: string]: any }): void;
6-
optimize(mutations?: MutationRecord[], context?: { [key: string]: any }): void;
7-
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
8-
optimize(mutations = [], context = {}) {
5+
trimEnd(): void {
96
// remove multiple empty line placed in the end
107
// this is usually occurs with multi level ListContainer
118
if (
@@ -15,6 +12,5 @@ export default class MxScroll extends Scroll {
1512
) {
1613
this.children.tail.parent.removeChild(this.children.tail);
1714
}
18-
super.optimize(mutations, context);
1915
}
2016
}

0 commit comments

Comments
 (0)