2018-03-20 16:12:05 +01:00
|
|
|
import { trimEnd, trimStart } from 'lodash';
|
2018-03-13 21:39:27 +01:00
|
|
|
import styles from './styles.scss';
|
|
|
|
|
/**
|
|
|
|
|
* Override the editor css
|
|
|
|
|
* @param {[type]} block [description]
|
|
|
|
|
* @return {[type]} [description]
|
|
|
|
|
*/
|
|
|
|
|
|
2018-03-13 13:12:06 +01:00
|
|
|
export function getBlockStyle(block) {
|
|
|
|
|
switch (block.getType()) {
|
|
|
|
|
case 'blockquote':
|
|
|
|
|
return styles.editorBlockquote;
|
|
|
|
|
case 'code-block':
|
|
|
|
|
return styles.editorCodeBlock;
|
2018-03-22 12:01:11 +01:00
|
|
|
default:
|
|
|
|
|
return null;
|
2018-03-13 13:12:06 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-20 15:17:33 +01:00
|
|
|
export function getBlockContent(style) {
|
|
|
|
|
switch (style) {
|
|
|
|
|
case 'IMG':
|
|
|
|
|
return {
|
|
|
|
|
innerContent: 'link',
|
|
|
|
|
endReplacer: ')',
|
|
|
|
|
startReplacer: '',
|
|
|
|
|
startReplacer: '[text](',
|
|
|
|
|
};
|
2018-03-20 15:17:33 +01:00
|
|
|
default:
|
|
|
|
|
return {
|
|
|
|
|
innerContent: '',
|
|
|
|
|
endReplacer: '',
|
|
|
|
|
startReplacer: '',
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-13 21:39:27 +01:00
|
|
|
|
2018-03-22 12:01:11 +01:00
|
|
|
export const getDefaultSelectionOffsets = (
|
|
|
|
|
content,
|
|
|
|
|
startReplacer,
|
|
|
|
|
endReplacer,
|
|
|
|
|
initPosition = 0,
|
|
|
|
|
) => ({
|
|
|
|
|
anchorOffset: initPosition + content.length - trimStart(content, startReplacer).length,
|
|
|
|
|
focusOffset: initPosition + trimEnd(content, endReplacer).length,
|
|
|
|
|
});
|
2018-03-20 16:12:05 +01:00
|
|
|
|
2018-03-13 21:39:27 +01:00
|
|
|
/**
|
|
|
|
|
* Get the start and end offset
|
|
|
|
|
* @param {Object} selection
|
|
|
|
|
* @return {Object}
|
|
|
|
|
*/
|
|
|
|
|
export function getOffSets(selection) {
|
|
|
|
|
return {
|
|
|
|
|
end: selection.getEndOffset(),
|
|
|
|
|
start: selection.getStartOffset(),
|
|
|
|
|
};
|
|
|
|
|
}
|