-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
66 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Command from './base'; | ||
import { inherit } from 'node_modules/content-kit-utils/src/object-utils'; | ||
import BlockModel from 'node_modules/content-kit-compiler/src/models/block'; | ||
import Type from 'node_modules/content-kit-compiler/src/types/type'; | ||
|
||
function injectCardBlock(cardName, cardPayload, editor, index) { | ||
// FIXME: Do we change the block model internal representation here? | ||
var cardBlock = BlockModel.createWithType(Type.CARD, { | ||
attributes: { | ||
name: cardName, | ||
payload: cardPayload | ||
} | ||
}); | ||
editor.replaceBlock(cardBlock, index); | ||
} | ||
|
||
function CardCommand() { | ||
Command.call(this, { | ||
name: 'card', | ||
button: '<i>CA</i>' | ||
}); | ||
} | ||
inherit(CardCommand, Command); | ||
|
||
CardCommand.prototype = { | ||
exec: function() { | ||
CardCommand._super.prototype.exec.call(this); | ||
var editor = this.editorContext; | ||
var currentEditingIndex = editor.getCurrentBlockIndex(); | ||
|
||
var cardName = 'pick-color'; | ||
var cardPayload = { options: ['red', 'blue'] }; | ||
injectCardBlock(cardName, cardPayload, editor, currentEditingIndex); | ||
editor.renderBlockAt(currentEditingIndex, true); | ||
} | ||
}; | ||
|
||
export default CardCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters