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

View File

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

View File

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