Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an initialSuggestions prop to simplify save/load integration with Track Changes #508

Open
DeltekDavid opened this issue Jul 17, 2024 · 1 comment

Comments

@DeltekDavid
Copy link

DeltekDavid commented Jul 17, 2024

It's currently too messy to load track changes. CKEditor component has an initialData prop, so why not initialSuggestions? The current integration instructions require either a globally-accessible variable (load/save) or an adapter that reads suggestions from the database on demand. The global variable is fine for demos, but we have a complex rendering tree with multiple editors, in which we load and convert the initial data as part of the parent component's rendering logic. For various reasons, we aren't going with the real-time adapter solution just yet. It doesn't work with our current model. Thanks

Edit: Alternately, an onInit config hook might do the trick, so we can populate the TC plugins' suggestions list as describe in the Save/Load integration docs. We tried doing it in the onReady callback, but that appears to be "too late" and we got an error:

CKEditorError: track-changes-user-not-found
Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#error-track-changes-user-not-found
    at p._getAuthorFromId (index.js:24:1)
    at p._createSuggestion (index.js:24:1)
    at p._handleNewSuggestionMarker (index.js:24:1)
    at Document.<anonymous> (index.js:24:1)
    at Document.fire (emittermixin.ts:241:1)
    at Document._handleChangeBlock (document.ts:370:1)
    at Model._runPendingChanges (model.ts:1116:1)
    at Model.enqueueChange (model.ts:353:1)
    at DataController.init (datacontroller.ts:362:1)
    at DataController.<anonymous> (observablemixin.ts:277:1) {phase: 'initialization', willEditorRestart: false}

We've also populated the users in the onReady callback, before we populate the suggestions.

@DeltekDavid
Copy link
Author

OK, I found a workaround for now. We simply added an initialSuggestions property to our EditorConfig. Then we can pass in the initialSuggestions this way, and they are available to our plugins' init() methods via editor.config! Phew. So our code looks much like the save/load example, but rather than load from some global named appData, we just load the suggestions like:

import { Plugin } from 'ckeditor5';

export default class TrackChangesIntegration extends Plugin {
    static get requires() {
        return ['TrackChanges', 'UsersIntegration'];
    }

    static get pluginName() {
        return 'TrackChangesIntegration';
    }

    init() {
        const trackChangesPlugin = this.editor.plugins.get('TrackChanges');

        // Load the initial suggestions from the config.
        // We have to do it this way since there's no prop to pass in for initial suggestions,
        // unlike initialData.
        const initialSuggestions = this.editor.config.get('initialSuggestions');
        if (!initialSuggestions?.length) {
            return;
        }

        for (const suggestion of initialSuggestions) {
            trackChangesPlugin.addSuggestion(suggestion);
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant