mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +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) {
|
||||
let editor = this.get('editor');
|
||||
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,
|
||||
_onMousemoveHandler: null,
|
||||
|
||||
// closure actions
|
||||
replaceWithCardSection() {},
|
||||
replaceWithListSection() {},
|
||||
|
||||
style: computed('top', function () {
|
||||
return htmlSafe(`top: ${this.get('top')}px`);
|
||||
}),
|
||||
@ -77,42 +81,20 @@ export default Component.extend({
|
||||
},
|
||||
|
||||
replaceWithCardSection(cardName) {
|
||||
let editor = this.get('editor');
|
||||
let range = this._editorRange;
|
||||
let {head: {section}} = range;
|
||||
|
||||
editor.run((postEditor) => {
|
||||
let {builder} = postEditor;
|
||||
let card = builder.createCardSection(cardName);
|
||||
let needsTrailingParagraph = !section.next;
|
||||
this.replaceWithCardSection(cardName, range);
|
||||
|
||||
postEditor.replaceSection(section, card);
|
||||
|
||||
if (needsTrailingParagraph) {
|
||||
let newSection = postEditor.builder.createMarkupSection('p');
|
||||
postEditor.insertSectionAtEnd(newSection);
|
||||
postEditor.setRange(newSection.tailPosition());
|
||||
}
|
||||
|
||||
this._hideButton();
|
||||
this._hideMenu();
|
||||
});
|
||||
this._hideButton();
|
||||
this._hideMenu();
|
||||
},
|
||||
|
||||
replaceWithListSection(listType) {
|
||||
let editor = this.get('editor');
|
||||
let range = this._editorRange;
|
||||
let {head: {section}} = range;
|
||||
|
||||
editor.run((postEditor) => {
|
||||
let {builder} = postEditor;
|
||||
let item = builder.createListItem();
|
||||
let listSection = builder.createListSection(listType, [item]);
|
||||
this.replaceWithListSection(listType, range);
|
||||
|
||||
postEditor.replaceSection(section, listSection);
|
||||
postEditor.setRange(listSection.headPosition());
|
||||
this._hideMenu();
|
||||
});
|
||||
this._hideMenu();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -68,8 +68,11 @@
|
||||
|
||||
{{!-- (+) icon and pop-up menu --}}
|
||||
{{koenig-plus-menu
|
||||
editorRange=selectedRange
|
||||
editor=editor
|
||||
editorRange=selectedRange
|
||||
replaceWithCardSection=(action "replaceWithCardSection")
|
||||
replaceWithListSection=(action "replaceWithListSection")
|
||||
}}
|
||||
}}
|
||||
|
||||
{{#each componentCards as |card|}}
|
||||
|
Loading…
Reference in New Issue
Block a user