Browse Source

fix(admin-ui): Make rich text editor editable when creating products etc

Michael Bromley 5 years ago
parent
commit
d2682760ee

+ 6 - 2
packages/admin-ui/src/lib/core/src/shared/components/rich-text-editor/prosemirror/prosemirror.service.ts

@@ -22,7 +22,7 @@ import { SetupOptions } from './types';
 export interface CreateEditorViewOptions {
     onTextInput: (content: string) => void;
     element: HTMLElement;
-    isEditable: () => boolean;
+    isReadOnly: () => boolean;
 }
 
 @Injectable()
@@ -52,7 +52,7 @@ export class ProsemirrorService {
                     options.onTextInput(content);
                 }
             },
-            editable: () => options.isEditable(),
+            editable: () => options.isReadOnly(),
         });
     }
 
@@ -74,6 +74,10 @@ export class ProsemirrorService {
     setEnabled(enabled: boolean) {
         if (this.editorView) {
             this.enabled = enabled;
+            // Updating the state causes ProseMirror to check the
+            // `editable()` function from the contructor config object
+            // newly.
+            this.editorView.updateState(this.editorView.state);
         }
     }
 

+ 1 - 1
packages/admin-ui/src/lib/core/src/shared/components/rich-text-editor/rich-text-editor.component.ts

@@ -54,7 +54,7 @@ export class RichTextEditorComponent implements ControlValueAccessor, AfterViewI
                 this.onChange(content);
                 this.changeDetector.markForCheck();
             },
-            isEditable: () => !this._readonly,
+            isReadOnly: () => !this._readonly,
         });
         if (this.value) {
             this.prosemirrorService.update(this.value);