mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-13 14:39:52 +03:00
3fd32ce3cf
no issue We're spending a bit of time playing with an alternative to mobiledoc-kit to test it's feasibility as a base for future editor improvements. - add `editor.lexicalUrl` config that points at the unpkg release by default - set up a route on `/ghost/#/lexical-editor/post/` for the test playground which renders `<KoenigLexicialEditor>` as the editor - adds `<KoenigLexicalEditor>` component that lazy loads the external react component
75 lines
2.0 KiB
JavaScript
75 lines
2.0 KiB
JavaScript
import $ from 'jquery';
|
|
import AuthenticatedRoute from 'ghost-admin/routes/authenticated';
|
|
import {run} from '@ember/runloop';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default AuthenticatedRoute.extend({
|
|
config: service(),
|
|
feature: service(),
|
|
notifications: service(),
|
|
router: service(),
|
|
ui: service(),
|
|
|
|
classNames: ['editor'],
|
|
|
|
beforeModel() {
|
|
if (!this.config.get('editor.lexicalUrl')) {
|
|
return this.router.transitionTo('posts');
|
|
}
|
|
},
|
|
|
|
activate() {
|
|
this._super(...arguments);
|
|
this.ui.set('isFullScreen', true);
|
|
},
|
|
|
|
deactivate() {
|
|
this._super(...arguments);
|
|
this.ui.set('isFullScreen', false);
|
|
},
|
|
|
|
actions: {
|
|
save() {
|
|
this._blurAndScheduleAction(function () {
|
|
this.controller.send('save');
|
|
});
|
|
},
|
|
|
|
authorizationFailed() {
|
|
this.controller.send('toggleReAuthenticateModal');
|
|
},
|
|
|
|
willTransition(transition) {
|
|
// exit early if an upgrade is required because our extended route
|
|
// class will abort the transition and show an error
|
|
if (this.get('upgradeStatus.isRequired')) {
|
|
return this._super(...arguments);
|
|
}
|
|
|
|
this.controller.willTransition(transition);
|
|
}
|
|
},
|
|
|
|
buildRouteInfoMetadata() {
|
|
return {
|
|
titleToken: () => {
|
|
return this.get('controller.post.title') || 'Editor';
|
|
},
|
|
bodyClasses: ['gh-body-fullscreen'],
|
|
mainClasses: ['gh-main-white']
|
|
};
|
|
},
|
|
|
|
_blurAndScheduleAction(func) {
|
|
let selectedElement = $(document.activeElement);
|
|
|
|
// TODO: we should trigger a blur for textareas as well as text inputs
|
|
if (selectedElement.is('input[type="text"]')) {
|
|
selectedElement.trigger('focusout');
|
|
}
|
|
|
|
// wait for actions triggered by the focusout to finish before saving
|
|
run.scheduleOnce('actions', this, func);
|
|
}
|
|
});
|