improve rte list handling
This commit is contained in:
parent
31c997897f
commit
63e93d79ca
@ -160,6 +160,7 @@
|
|||||||
"semaphore": "^1.0.5",
|
"semaphore": "^1.0.5",
|
||||||
"slate": "^0.20.3",
|
"slate": "^0.20.3",
|
||||||
"slate-drop-or-paste-images": "^0.2.0",
|
"slate-drop-or-paste-images": "^0.2.0",
|
||||||
|
"slate-edit-list": "^0.7.1",
|
||||||
"slug": "^0.9.1",
|
"slug": "^0.9.1",
|
||||||
"textarea-caret-position": "^0.1.1",
|
"textarea-caret-position": "^0.1.1",
|
||||||
"unified": "^6.1.4",
|
"unified": "^6.1.4",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React, { Component, PropTypes } from 'react';
|
import React, { Component, PropTypes } from 'react';
|
||||||
import { Map, List } from 'immutable';
|
import { Map, List } from 'immutable';
|
||||||
import { Editor as SlateEditor, Html as SlateHtml, Raw as SlateRaw} from 'slate';
|
import { Editor as SlateEditor, Html as SlateHtml, Raw as SlateRaw} from 'slate';
|
||||||
|
import EditList from 'slate-edit-list';
|
||||||
import { markdownToHtml, htmlToMarkdown } from '../../unified';
|
import { markdownToHtml, htmlToMarkdown } from '../../unified';
|
||||||
import registry from '../../../../../lib/registry';
|
import registry from '../../../../../lib/registry';
|
||||||
import { createAssetProxy } from '../../../../../valueObjects/AssetProxy';
|
import { createAssetProxy } from '../../../../../valueObjects/AssetProxy';
|
||||||
@ -284,36 +285,28 @@ const SoftBreak = (options = {}) => ({
|
|||||||
|
|
||||||
const BackspaceCloseBlock = (options = {}) => ({
|
const BackspaceCloseBlock = (options = {}) => ({
|
||||||
onKeyDown(e, data, state) {
|
onKeyDown(e, data, state) {
|
||||||
if (data.key != 'backspace' || state.startBlock.type === 'paragraph') return;
|
if (data.key != 'backspace') return;
|
||||||
|
|
||||||
const { defaultBlock = 'paragraph', wrapped = {} } = options;
|
const { defaultBlock = 'paragraph', ignoreIn, onlyIn } = options;
|
||||||
const { startBlock } = state;
|
const { startBlock } = state;
|
||||||
const { type } = startBlock;
|
const { type } = startBlock;
|
||||||
|
|
||||||
|
if (onlyIn && !onlyIn.includes(type)) return;
|
||||||
|
if (ignoreIn && ignoreIn.includes(type)) return;
|
||||||
|
|
||||||
const characters = startBlock.getFirstText().characters;
|
const characters = startBlock.getFirstText().characters;
|
||||||
const isEmpty = !characters || characters.isEmpty();
|
const isEmpty = !characters || characters.isEmpty();
|
||||||
|
|
||||||
if (isEmpty) {
|
if (isEmpty) {
|
||||||
const transform = state.transform();
|
return state.transform().insertBlock(defaultBlock).focus().apply();
|
||||||
|
|
||||||
if (wrapped[type] && state.document.getPreviousSibling(startBlock.key)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (wrapped[type]) {
|
|
||||||
wrapped[type].forEach(wrapper => transform.unwrapBlock(wrapper));
|
|
||||||
}
|
|
||||||
|
|
||||||
return transform.insertBlock(defaultBlock).focus().apply();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const slatePlugins = [
|
const slatePlugins = [
|
||||||
SoftBreak({ ignoreIn: ['paragraph', 'list-item'], closeAfter: 2 }),
|
SoftBreak({ ignoreIn: ['paragraph', 'list-item', 'numbered-list', 'bulleted-list'], closeAfter: 1 }),
|
||||||
SoftBreak({ onlyIn: ['list-item'], shift: true}),
|
BackspaceCloseBlock({ ignoreIn: ['paragraph', 'list-item', 'bulleted-list', 'numbered-list'] }),
|
||||||
SoftBreak({ onlyIn: ['paragraph'], closeAfter: 1 }),
|
EditList({ types: ['bulleted-list', 'numbered-list'], typeItem: 'list-item' }),
|
||||||
BackspaceCloseBlock({ wrapped: { 'list-item': ['bulleted-list', 'numbered-list'] } }),
|
|
||||||
];
|
];
|
||||||
|
|
||||||
export default class Editor extends Component {
|
export default class Editor extends Component {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user