Skip to content

Commit d5be9db

Browse files
committed
fix: readonly not working
1 parent d39698c commit d5be9db

File tree

6 files changed

+23
-10
lines changed

6 files changed

+23
-10
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ const Editor = forwardRef((props: EditorProps, ref: MutableRefObject<Quill | nul
9898
image: customImageUploadHandler
9999
}
100100
}
101-
: false;
101+
: // we cannot set toolbar to false, because "table-better" needs toolbar module
102+
// hidden toolbar will be set with display: none
103+
[];
102104

103105
// Quill instance configurations.
104106
const options: QuillOptions = {
@@ -130,7 +132,7 @@ const Editor = forwardRef((props: EditorProps, ref: MutableRefObject<Quill | nul
130132
"table-better": {
131133
language: "en_US",
132134
menus: ["column", "row", "merge", "table", "cell", "wrap", "copy", "delete"],
133-
toolbarTable: true
135+
toolbarTable: !readOnly
134136
},
135137
toolbar
136138
},
@@ -144,7 +146,7 @@ const Editor = forwardRef((props: EditorProps, ref: MutableRefObject<Quill | nul
144146
ref.current = quill;
145147

146148
const delta = quill.clipboard.convert({ html: defaultValue ?? "" });
147-
quill.updateContents(delta, Quill.sources.USER);
149+
quill.updateContents(delta, Quill.sources.SILENT);
148150

149151
quill.on(Quill.events.TEXT_CHANGE, (...arg) => {
150152
onTextChangeRef.current?.(...arg);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ function EditorWrapperInner(props: EditorWrapperProps): ReactElement {
174174
<div
175175
className={classNames(
176176
"flexcontainer",
177-
toolbarLocation === "bottom" ? "flex-column-reverse" : "flex-column"
177+
toolbarLocation === "bottom" ? "flex-column-reverse" : "flex-column",
178+
{ "hide-toolbar": shouldHideToolbar }
178179
)}
179180
>
180181
<If condition={!shouldHideToolbar && toolbarOptions === undefined}>

packages/pluggableWidgets/rich-text-web/src/ui/RichText.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ $rte-brand-primary: #264ae5;
8484
}
8585
}
8686

87+
.hide-toolbar .ql-toolbar {
88+
display: none;
89+
}
90+
8791
.widget-rich-text-footer {
8892
align-items: center;
8993
border-top: 1px solid var(--border-color-default, $rte-border-color-default);

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/quill-table-better.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ class Table extends Module {
8585
this.operateLine = new OperateLine(quill, this);
8686
this.tableMenus = new TableMenus(quill, this);
8787
this.tableSelect = new TableSelect();
88-
quill.root.addEventListener("keyup", this.handleKeyup.bind(this));
89-
quill.root.addEventListener("mousedown", this.handleMousedown.bind(this));
90-
quill.root.addEventListener("scroll", this.handleScroll.bind(this));
91-
this.registerToolbarTable(options?.toolbarTable);
88+
if (!this.quill.options.readOnly) {
89+
quill.root.addEventListener("keyup", this.handleKeyup.bind(this));
90+
quill.root.addEventListener("mousedown", this.handleMousedown.bind(this));
91+
quill.root.addEventListener("scroll", this.handleScroll.bind(this));
92+
this.registerToolbarTable(options?.toolbarTable);
93+
}
9294
}
9395

9496
clearHistorySelected() {

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/ui/cell-selection.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ class CellSelection {
5656
this.disabledList = [];
5757
this.singleList = [];
5858
this.tableBetter = tableBetter;
59-
this.quill.root.addEventListener("click", this.handleClick.bind(this));
59+
if (!this.quill.options.readOnly) {
60+
this.quill.root.addEventListener("click", this.handleClick.bind(this));
61+
}
6062
this.initDocumentListener();
6163
this.initWhiteList();
6264
}

packages/pluggableWidgets/rich-text-web/src/utils/formats/quill-table-better/ui/table-menus.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ class TableMenus {
231231
this.scroll = false;
232232
this.tableBetter = tableBetter;
233233
this.tablePropertiesForm = null;
234-
this.quill.root.addEventListener("click", this.handleClick.bind(this));
234+
if (!this.quill.options.readOnly) {
235+
this.quill.root.addEventListener("click", this.handleClick.bind(this));
236+
}
235237
this.root = this.createMenus();
236238
}
237239

0 commit comments

Comments
 (0)