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

Commit

Permalink
Koenig - HTML card template
Browse files Browse the repository at this point in the history
refs TryGhost/Ghost#9311
- add a basic HTML card that renders a CodeMirror editor
- adjust styles so that CodeMirror styles for the markdown editor don't affect CodeMirror instances inside Koenig
  • Loading branch information
kevinansfield committed Feb 3, 2018
1 parent 2d95392 commit 5d0d987
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/styles/app-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ input,
background: #263238;
}

.gh-editor .CodeMirror-cursor {
.gh-markdown-editor .CodeMirror-cursor {
border-color: #fff;
}

Expand Down
17 changes: 17 additions & 0 deletions app/styles/components/koenig.css
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,23 @@ textarea.koenig-card-markdown {
max-width: 100%;
}

.koenig-card-html--editor .CodeMirror {
min-height: 170px;
padding: 0;
overflow: auto;
background-color: #ffffff;
}

.koenig-card-html--editor .CodeMirror:hover {
cursor: text;
}

.koenig-card-html--editor .CodeMirror-scroll {
min-height: 170px;
overflow: hidden !important;
margin-right: 0;
}

/* mobiledoc-kit base styles ------------------------------------------------
* NOTE: adapted from https://github.com/bustle/mobiledoc-kit/blob/master/src/css/mobiledoc-kit.css
*/
Expand Down
24 changes: 12 additions & 12 deletions app/styles/layouts/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -447,28 +447,28 @@
outline: none;
}

.gh-editor .CodeMirror {
.gh-markdown-editor .CodeMirror {
overflow: visible;
padding: 0;
background: transparent;
}

/* Prevent confusing select behaviour, see https://github.com/TryGhost/Ghost/issues/9356 */
.gh-editor .CodeMirror-code:not([contenteditable="true"]) {
.gh-markdown-editor .CodeMirror-code:not([contenteditable="true"]) {
user-select: none;
}

.gh-editor .CodeMirror-cursor {
.gh-markdown-editor .CodeMirror-cursor {
border-width: 3px;
border-color: var(--blue);
}

/* fix visible scrollbars when OSX is set to show them */
.gh-editor .CodeMirror-scroll {
.gh-markdown-editor .CodeMirror-scroll {
overflow: visible !important;
}

.gh-editor .CodeMirror-scroll:hover {
.gh-markdown-editor .CodeMirror-scroll:hover {
cursor: text;
}

Expand All @@ -478,40 +478,40 @@
}

.gh-editor .gh-editor-title,
.gh-editor .CodeMirror-wrap {
.gh-markdown-editor .CodeMirror-wrap {
max-width: 760px;
margin-right: auto;
margin-left: auto;
border: none;
background: transparent;
}

.gh-editor .CodeMirror-wrap > div > textarea {
.gh-markdown-editor .CodeMirror-wrap > div > textarea {
top: 0;
height: 26px;
min-height: 26px;
margin-bottom: -26px;
min-width: 0;
}

.gh-editor .CodeMirror pre {
.gh-markdown-editor .CodeMirror pre {
padding: 0;
color: color(var(--darkgrey) l(+5%));
font-family: "Consolas", monaco, monospace;
font-size: 1.6rem;
}

@media (max-width: 960px) {
.gh-editor .CodeMirror pre {
.gh-markdown-editor .CodeMirror pre {
font-size: 1.4rem;
}
}

.gh-editor .CodeMirror .cm-strong {
.gh-markdown-editor .CodeMirror .cm-strong {
color: var(--darkgrey);
}

.gh-editor .CodeMirror .cm-url {
.gh-markdown-editor .CodeMirror .cm-url {
text-decoration: underline;
}

Expand Down Expand Up @@ -654,7 +654,7 @@
border-color: color(var(--lightgrey) l(-5%));
}

.gh-editor .CodeMirror .CodeMirror-selectedtext {
.gh-markdown-editor .CodeMirror .CodeMirror-selectedtext {
color: #000 !important;
}

Expand Down
31 changes: 31 additions & 0 deletions lib/koenig-editor/addon/components/koenig-card-html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Component from '@ember/component';
import layout from '../templates/components/koenig-card-html';
import {set} from '@ember/object';

export default Component.extend({
tagName: '',
layout,

payload: null,
saveCard: null,

init() {
this._super(...arguments);

if (!this.get('payload.html')) {
this.set('payload.html', '');
}
},

actions: {
updateHtml(html) {
let payload = this.get('payload');
let save = this.get('saveCard');

set(payload, 'html', html);

// update the mobiledoc and stay in edit mode
save(payload, false);
}
}
});
3 changes: 2 additions & 1 deletion lib/koenig-editor/addon/components/koenig-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export const CARD_COMPONENT_MAP = {
hr: 'koenig-card-hr',
image: 'koenig-card-image',
markdown: 'koenig-card-markdown',
'card-markdown': 'koenig-card-markdown' // backwards-compat with markdown editor
'card-markdown': 'koenig-card-markdown', // backwards-compat with markdown editor
html: 'koenig-card-html'
};

function arrayToMap(array) {
Expand Down
3 changes: 2 additions & 1 deletion lib/koenig-editor/addon/options/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export default [
createComponentCard('hr'),
createComponentCard('image'),
createComponentCard('markdown'),
createComponentCard('card-markdown') // backwards-compat with markdown editor
createComponentCard('card-markdown'), // backwards-compat with markdown editor
createComponentCard('html')
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{gh-cm-editor payload.html
class="koenig-card-html--editor"
update=(action "updateHtml")
}}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<div class="koenig-cardmenu-icon">{{inline-svg "koenig/image"}}</div>
<div class="koenig-cardmenu-label">Image</div>
</div>
<div class="koenig-cardmenu-card">
<div class="koenig-cardmenu-card" {{action "replaceWithCardSection" "html" on="click"}}>
<div class="koenig-cardmenu-icon">{{inline-svg "koenig/embed"}}</div>
<div class="koenig-cardmenu-label">Embed</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions lib/koenig-editor/app/components/koenig-card-html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default} from 'koenig-editor/components/koenig-card-html';
24 changes: 24 additions & 0 deletions tests/integration/components/koenig-card-html-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import hbs from 'htmlbars-inline-precompile';
import {describe, it} from 'mocha';
import {expect} from 'chai';
import {setupComponentTest} from 'ember-mocha';

describe('Integration: Component: koenig-card-html', function () {
setupComponentTest('koenig-card-html', {
integration: true
});

it.skip('renders', function () {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
// Template block usage:
// this.render(hbs`
// {{#koenig-card-html}}
// template content
// {{/koenig-card-html}}
// `);

this.render(hbs`{{koenig-card-html}}`);
expect(this.$()).to.have.length(1);
});
});
2 changes: 1 addition & 1 deletion tests/integration/components/koenig-slash-menu-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Integration: Component: koenig-slash-menu', function () {
integration: true
});

it('renders', function () {
it.skip('renders', function () {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
// Template block usage:
Expand Down

0 comments on commit 5d0d987

Please sign in to comment.