Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Added data pipeline v -> m conversion.
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarwrobel committed Aug 7, 2019
1 parent f4669dd commit c787683
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/todolistconverters.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,31 @@ export function modelViewChangeChecked( model ) {
};
}

/**
* @see module:engine/conversion/upcastdispatcher~UpcastDispatcher#event:element
* @param {module:utils/eventinfo~EventInfo} evt An object containing information about the fired event.
* @param {Object} data An object containing conversion input and a placeholder for conversion output and possibly other values.
* @param {module:engine/conversion/upcastdispatcher~UpcastConversionApi} conversionApi Conversion interface to be used by the callback.
*/
export function dataViewModelCheckmarkInsertion( evt, data, conversionApi ) {
if ( data.viewItem.getAttribute( 'type' ) != 'checkbox' || data.modelCursor.parent.name != 'listItem' ) {
return;
}

if ( !conversionApi.consumable.consume( data.viewItem, { name: true } ) ) {
return;
}

const { writer } = conversionApi;
const modelItem = data.modelCursor.parent;

writer.setAttribute( 'listType', 'todo', modelItem );

if ( data.viewItem.getAttribute( 'checked' ) == 'checked' ) {
writer.setAttribute( 'todoListChecked', true, modelItem );
}
}

function addTodoElementsToListItem( modelItem, viewItem, viewWriter, model ) {
const isChecked = !!modelItem.getAttribute( 'todoListChecked' );

Expand Down
5 changes: 4 additions & 1 deletion src/todolistediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
dataModelViewInsertion,
dataModelViewTextInsertion,
modelViewChangeChecked,
modelViewChangeType
modelViewChangeType,
dataViewModelCheckmarkInsertion
} from './todolistconverters';

/**
Expand Down Expand Up @@ -53,6 +54,8 @@ export default class TodoListEditing extends Plugin {
editing.downcastDispatcher.on( 'attribute:listType:listItem', modelViewChangeType( model ) );
editing.downcastDispatcher.on( 'attribute:todoListChecked:listItem', modelViewChangeChecked( model ) );

data.upcastDispatcher.on( 'element:input', dataViewModelCheckmarkInsertion, { priority: 'high' } );

// Register command for todo list.
editor.commands.add( 'todoList', new ListCommand( editor, 'todo' ) );

Expand Down

0 comments on commit c787683

Please sign in to comment.