mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 04:13:30 +03:00
Koenig - Move list/card replacement actions into {{koenig-editor}}
This commit is contained in:
parent
714de7e64d
commit
d0ca47892a
@ -297,6 +297,39 @@ export default Component.extend({
|
|||||||
toggleSection(sectionTagName) {
|
toggleSection(sectionTagName) {
|
||||||
let editor = this.get('editor');
|
let editor = this.get('editor');
|
||||||
editor.toggleSection(sectionTagName);
|
editor.toggleSection(sectionTagName);
|
||||||
|
},
|
||||||
|
|
||||||
|
replaceWithCardSection(cardName, range) {
|
||||||
|
let editor = this.get('editor');
|
||||||
|
let {head: {section}} = range;
|
||||||
|
|
||||||
|
editor.run((postEditor) => {
|
||||||
|
let {builder} = postEditor;
|
||||||
|
let card = builder.createCardSection(cardName);
|
||||||
|
let needsTrailingParagraph = !section.next;
|
||||||
|
|
||||||
|
postEditor.replaceSection(section, card);
|
||||||
|
|
||||||
|
if (needsTrailingParagraph) {
|
||||||
|
let newSection = postEditor.builder.createMarkupSection('p');
|
||||||
|
postEditor.insertSectionAtEnd(newSection);
|
||||||
|
postEditor.setRange(newSection.tailPosition());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
replaceWithListSection(listType, range) {
|
||||||
|
let editor = this.get('editor');
|
||||||
|
let {head: {section}} = range;
|
||||||
|
|
||||||
|
editor.run((postEditor) => {
|
||||||
|
let {builder} = postEditor;
|
||||||
|
let item = builder.createListItem();
|
||||||
|
let listSection = builder.createListSection(listType, [item]);
|
||||||
|
|
||||||
|
postEditor.replaceSection(section, listSection);
|
||||||
|
postEditor.setRange(listSection.headPosition());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -25,6 +25,10 @@ export default Component.extend({
|
|||||||
_hasCursorButton: false,
|
_hasCursorButton: false,
|
||||||
_onMousemoveHandler: null,
|
_onMousemoveHandler: null,
|
||||||
|
|
||||||
|
// closure actions
|
||||||
|
replaceWithCardSection() {},
|
||||||
|
replaceWithListSection() {},
|
||||||
|
|
||||||
style: computed('top', function () {
|
style: computed('top', function () {
|
||||||
return htmlSafe(`top: ${this.get('top')}px`);
|
return htmlSafe(`top: ${this.get('top')}px`);
|
||||||
}),
|
}),
|
||||||
@ -77,42 +81,20 @@ export default Component.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
replaceWithCardSection(cardName) {
|
replaceWithCardSection(cardName) {
|
||||||
let editor = this.get('editor');
|
|
||||||
let range = this._editorRange;
|
let range = this._editorRange;
|
||||||
let {head: {section}} = range;
|
|
||||||
|
|
||||||
editor.run((postEditor) => {
|
this.replaceWithCardSection(cardName, range);
|
||||||
let {builder} = postEditor;
|
|
||||||
let card = builder.createCardSection(cardName);
|
|
||||||
let needsTrailingParagraph = !section.next;
|
|
||||||
|
|
||||||
postEditor.replaceSection(section, card);
|
|
||||||
|
|
||||||
if (needsTrailingParagraph) {
|
|
||||||
let newSection = postEditor.builder.createMarkupSection('p');
|
|
||||||
postEditor.insertSectionAtEnd(newSection);
|
|
||||||
postEditor.setRange(newSection.tailPosition());
|
|
||||||
}
|
|
||||||
|
|
||||||
this._hideButton();
|
this._hideButton();
|
||||||
this._hideMenu();
|
this._hideMenu();
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
replaceWithListSection(listType) {
|
replaceWithListSection(listType) {
|
||||||
let editor = this.get('editor');
|
|
||||||
let range = this._editorRange;
|
let range = this._editorRange;
|
||||||
let {head: {section}} = range;
|
|
||||||
|
|
||||||
editor.run((postEditor) => {
|
this.replaceWithListSection(listType, range);
|
||||||
let {builder} = postEditor;
|
|
||||||
let item = builder.createListItem();
|
|
||||||
let listSection = builder.createListSection(listType, [item]);
|
|
||||||
|
|
||||||
postEditor.replaceSection(section, listSection);
|
|
||||||
postEditor.setRange(listSection.headPosition());
|
|
||||||
this._hideMenu();
|
this._hideMenu();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -68,8 +68,11 @@
|
|||||||
|
|
||||||
{{!-- (+) icon and pop-up menu --}}
|
{{!-- (+) icon and pop-up menu --}}
|
||||||
{{koenig-plus-menu
|
{{koenig-plus-menu
|
||||||
editorRange=selectedRange
|
|
||||||
editor=editor
|
editor=editor
|
||||||
|
editorRange=selectedRange
|
||||||
|
replaceWithCardSection=(action "replaceWithCardSection")
|
||||||
|
replaceWithListSection=(action "replaceWithListSection")
|
||||||
|
}}
|
||||||
}}
|
}}
|
||||||
|
|
||||||
{{#each componentCards as |card|}}
|
{{#each componentCards as |card|}}
|
||||||
|
Loading…
Reference in New Issue
Block a user