Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Koenig reboot - rich text (#952)
Browse files Browse the repository at this point in the history
refs TryGhost/Ghost#9311

Koenig is being fully rebooted, first port of call is to focus on getting the rich-text only aspect of mobiledoc-kit working with our popup toolbar.

- renames old koenig implementation (used for reference, will eventually be deleted)
- new `{{koenig-editor}}` mobiledoc-kit component implementation based on ember-mobiledoc-editor
  - markdown text expansions
- new `{{gh-koenig-edtor}}` that wraps our title+editor and handles keyboard navigation between the two
  - clicks below content will focus the editor
- new `{{koenig-toolbar}}` component for the popup formatting toolbar with improved behaviour and simplified code
  • Loading branch information
kevinansfield committed Jan 30, 2018
1 parent 7013b26 commit 3d341e2
Show file tree
Hide file tree
Showing 114 changed files with 1,308 additions and 166 deletions.
120 changes: 120 additions & 0 deletions app/components/gh-koenig-editor.js
@@ -0,0 +1,120 @@
import Component from '@ember/component';

export default Component.extend({

// public attrs
tagName: '',
title: '',
titlePlaceholder: '',
body: null,
bodyPlaceholder: '',
bodyAutofocus: false,

// internal properties
_title: null,
_editor: null,

// closure actions
onTitleChange() {},
onTitleBlur() {},
onBodyChange() {},

actions: {
// triggered when a click is registered on .gh-koenig-editor-pane
focusEditor(event) {
// if a click occurs on the editor canvas, focus the editor and put
// the cursor at the end of the document. Allows for a much larger
// hit area for focusing the editor when it has no or little content
if (event.target.tagName === 'ARTICLE' && event.target.classList.contains('koenig-editor')) {
let {post} = this._editor;
let range = post.toRange();

event.preventDefault();

this._editor.focus();
this._editor.run((postEditor) => {
postEditor.setRange(range.tail.section.tailPosition());
});
}
},

/* title related actions -------------------------------------------- */

onTitleCreated(titleElement) {
this._title = titleElement;
},

onTitleChange(newTitle) {
this.onTitleChange(newTitle);
},

onTitleFocusOut() {
this.onTitleBlur();
},

onTitleKeydown(event) {
let value = event.target.value;
let selectionStart = event.target.selectionStart;

// enter will always focus the editor
// down arrow will only focus the editor when the cursor is at the
// end of the input to preserve the default OS behaviour
if (
event.key === 'Enter' ||
event.key === 'Tab' ||
(event.key === 'ArrowDown' && (!value || selectionStart === value.length))
) {
event.preventDefault();
this._editor.focus();
}
},

/* body related actions --------------------------------------------- */

onEditorCreated(editor) {
this._setupEditor(editor);
},

onBodyChange(newMobiledoc) {
this.onBodyChange(newMobiledoc);
}
},

/* public methods ------------------------------------------------------- */

/* internal methods ----------------------------------------------------- */

_setupEditor(editor) {
let component = this;

this._editor = editor;

// focus the title when pressing UP if cursor is at the beginning of doc
editor.registerKeyCommand({
str: 'UP',
run(editor) {
let cursorHead = editor.cursor.offsets.head;

if (
editor.hasCursor()
&& cursorHead.offset === 0
&& (!cursorHead.section || !cursorHead.section.prev)
) {
component._title.focus();
return true;
}

return false;
}
});

// focus the title when pressing SHIFT+TAB
editor.registerKeyCommand({
str: 'SHIFT+TAB',
run() {
component._title.focus();
return true;
}
});
}
});
4 changes: 4 additions & 0 deletions app/components/gh-textarea.js
Expand Up @@ -27,6 +27,10 @@ export default OneWayTextarea.extend(TextInputMixin, {
if (this.get('autoExpand')) {
run.scheduleOnce('afterRender', this, this._setupAutoExpand);
}

if (this.get('didCreateTextarea')) {
this.get('didCreateTextarea')(this.element);
}
},

willDestroyElement() {
Expand Down
6 changes: 3 additions & 3 deletions app/models/post.js
Expand Up @@ -5,7 +5,7 @@ import attr from 'ember-data/attr';
import boundOneWay from 'ghost-admin/utils/bound-one-way';
import moment from 'moment';
import {BLANK_DOC as BLANK_MARKDOWN} from 'ghost-admin/components/gh-markdown-editor';
import {BLANK_DOC as BLANK_MOBILEDOC} from 'gh-koenig/components/gh-koenig';
import {BLANK_DOC as BLANK_MOBILEDOC} from 'koenig-editor/components/koenig-editor';
import {belongsTo, hasMany} from 'ember-data/relationships';
import {compare} from '@ember/utils';
import {computed} from '@ember/object';
Expand Down Expand Up @@ -344,8 +344,8 @@ export default Model.extend(Comparable, ValidationEngine, {
isCompatibleWithMarkdownEditor() {
let mobiledoc = this.get('mobiledoc');

if (
mobiledoc.markups.length === 0
if (mobiledoc
&& mobiledoc.markups.length === 0
&& mobiledoc.cards.length === 1
&& mobiledoc.cards[0][0] === 'card-markdown'
&& mobiledoc.sections.length === 1
Expand Down
6 changes: 1 addition & 5 deletions app/styles/app-dark.css
Expand Up @@ -34,6 +34,7 @@
@import "components/popovers.css";
@import "components/tour.css";
@import "components/unsplash.css";
@import "components/koenig";


/* Layouts: Groups of Components
Expand All @@ -54,11 +55,6 @@
@import "layouts/subscribers.css";


/* Addons: gh-koenig
/* ---------------------------------------------------------- */
@import "addons/gh-koenig/gh-koenig.css";


:root {
--darkgrey: #e5eff5;
--midgrey: #738a94;
Expand Down
6 changes: 1 addition & 5 deletions app/styles/app.css
Expand Up @@ -34,6 +34,7 @@
@import "components/popovers.css";
@import "components/tour.css";
@import "components/unsplash.css";
@import "components/koenig";


/* Layouts: Groups of Components
Expand All @@ -54,11 +55,6 @@
@import "layouts/subscribers.css";


/* Addons: gh-koenig
/* ---------------------------------------------------------- */
@import "addons/gh-koenig/gh-koenig.css";


/* ---------------------------✈️----------------------------- */
/* I COMMITTED THIS COMMENT FROM A PLANE: http://bit.ly/2on5pmq
/* --------------------------------------------------------- */

0 comments on commit 3d341e2

Please sign in to comment.