Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export class SuperToolbar extends EventEmitter {
this.config = { ...this.config, ...config };
this.toolbarItems = [];
this.overflowItems = [];
this.documentMode = 'editing';
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The document mode was set to 'editing' and never changed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But since the document mode is checked on toolbar state update, I can assume that it should change (on doc mode change).

this.documentMode = config.documentMode || 'editing';
this.isDev = config.isDev || false;
this.superdoc = config.superdoc;
this.role = config.role || 'editor';
Expand Down
2 changes: 1 addition & 1 deletion packages/superdoc/src/SuperDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const onEditorCreate = ({ editor }) => {
const { documentId } = editor.options;
const doc = getDocument(documentId);
doc.setEditor(editor);
proxy.$superdoc.activeEditor = editor;
proxy.$superdoc.setActiveEditor(editor);
proxy.$superdoc.broadcastEditorCreate(editor);
proxy.$superdoc.log('[SuperDoc] Editor created', proxy.$superdoc.activeEditor);
proxy.$superdoc.log('[SuperDoc] Page styles (pixels)', editor.getPageStyles());
Expand Down
28 changes: 23 additions & 5 deletions packages/superdoc/src/core/SuperDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ export class SuperDoc extends EventEmitter {

// If a toolbar element is provided, render a toolbar
this.addToolbar(this);

}

get requiredNumberOfEditors() {
Expand Down Expand Up @@ -354,11 +353,13 @@ export class SuperDoc extends EventEmitter {
role: this.config.role,
pagination: this.config.pagination,
icons: this.config.toolbarIcons,
documentMode: this.config.documentMode,
superdoc: this,
};

this.toolbar = new SuperToolbar(config);
this.toolbar.on('superdoc-command', this.onToolbarCommand.bind(this));
this.once('editorCreate', () => this.toolbar.updateToolbarState());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to wait for the editor to be created to update the toolbar state because there are a lot of asynchronous things behind.

}

addCommentsList(element) {
Expand Down Expand Up @@ -402,26 +403,38 @@ export class SuperDoc extends EventEmitter {
if (this.config.role !== 'editor') return this.#setModeSuggesting();
if (this.superdocStore.documents.length > 0) {
const firstEditor = this.superdocStore.documents[0]?.getEditor();
if (firstEditor) {
this.setActiveEditor(firstEditor);
this.toolbar.activeEditor = firstEditor;
}
if (firstEditor) this.setActiveEditor(firstEditor);
}

this.superdocStore.documents.forEach((doc) => {
doc.restoreComments();
const editor = doc.getEditor();
if (editor) editor.setDocumentMode('editing');
});

if (this.toolbar) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set document mode for toolbar and update the state.

this.toolbar.documentMode = 'editing';
this.toolbar.updateToolbarState();
}
}

#setModeSuggesting() {
if (!['editor', 'suggester'].includes(this.config.role)) return this.#setModeViewing();
if (this.superdocStore.documents.length > 0) {
const firstEditor = this.superdocStore.documents[0]?.getEditor();
if (firstEditor) this.setActiveEditor(firstEditor);
}

this.superdocStore.documents.forEach((doc) => {
doc.restoreComments();
const editor = doc.getEditor();
if (editor) editor.setDocumentMode('suggesting');
});

if (this.toolbar) {
this.toolbar.documentMode = 'suggesting';
this.toolbar.updateToolbarState();
}
}

#setModeViewing() {
Expand All @@ -431,6 +444,11 @@ export class SuperDoc extends EventEmitter {
const editor = doc.getEditor();
if (editor) editor.setDocumentMode('viewing');
});

if (this.toolbar) {
this.toolbar.documentMode = 'viewing';
this.toolbar.updateToolbarState();
}
}

/**
Expand Down