Koenig - Move list/card replacement actions into {{koenig-editor}}

This commit is contained in:
Kevin Ansfield 2018-02-02 16:22:37 +01:00
parent 714de7e64d
commit d0ca47892a
3 changed files with 46 additions and 28 deletions

View File

@ -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());
});
}
},

View File

@ -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;
postEditor.replaceSection(section, card);
if (needsTrailingParagraph) {
let newSection = postEditor.builder.createMarkupSection('p');
postEditor.insertSectionAtEnd(newSection);
postEditor.setRange(newSection.tailPosition());
}
this.replaceWithCardSection(cardName, range);
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();
});
}
},

View File

@ -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|}}