🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

braft-utils

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

braft-utils - npm Package Compare versions

Comparing version

to
3.0.0

6

dist/base.js

@@ -8,7 +8,5 @@ "use strict";

exports.default = {
UniqueIndex: function UniqueIndex() {
return braftUniqueIndex += 1;
}
var UniqueIndex = exports.UniqueIndex = function UniqueIndex() {
return braftUniqueIndex += 1;
};
//# sourceMappingURL=base.js.map

@@ -6,3 +6,3 @@ "use strict";

});
var namedColors = {
var _namedColors = {
"aliceblue": "#f0f8ff",

@@ -151,3 +151,3 @@ "antiquewhite": "#faebd7",

var getHexColor = function getHexColor(color) {
var _getHexColor = function _getHexColor(color) {

@@ -175,34 +175,33 @@ color = color.replace('color:', '').replace(';', '').replace(' ', '');

exports.default = {
var namedColors = exports.namedColors = _namedColors;
var getHexColor = exports.getHexColor = _getHexColor;
namedColors: namedColors, getHexColor: getHexColor,
var detectColorsFromHTMLString = exports.detectColorsFromHTMLString = function detectColorsFromHTMLString(html) {
return typeof html !== 'string' ? [] : (html.match(/color:[^;]{3,24};/g) || []).map(getHexColor).filter(function (color) {
return color;
});
};
detectColorsFromHTMLString: function detectColorsFromHTMLString(html) {
return typeof html !== 'string' ? [] : (html.match(/color:[^;]{3,24};/g) || []).map(getHexColor).filter(function (color) {
return color;
});
},
detectColorsFromDraftState: function detectColorsFromDraftState(draftState) {
var detectColorsFromDraftState = exports.detectColorsFromDraftState = function detectColorsFromDraftState(draftState) {
var result = [];
var result = [];
if (!draftState || !draftState.blocks || !draftState.blocks.length) {
return result;
if (!draftState || !draftState.blocks || !draftState.blocks.length) {
return result;
}
draftState.blocks.forEach(function (block) {
if (block && block.inlineStyleRanges && block.inlineStyleRanges.length) {
block.inlineStyleRanges.forEach(function (inlineStyle) {
if (inlineStyle.style && inlineStyle.style.indexOf('COLOR-') >= 0) {
result.push('#' + inlineStyle.style.split('COLOR-')[1]);
}
});
}
});
draftState.blocks.forEach(function (block) {
if (block && block.inlineStyleRanges && block.inlineStyleRanges.length) {
block.inlineStyleRanges.forEach(function (inlineStyle) {
if (inlineStyle.style && inlineStyle.style.indexOf('COLOR-') >= 0) {
result.push('#' + inlineStyle.style.split('COLOR-')[1]);
}
});
}
});
return result.filter(function (color) {
return color;
});
}
return result.filter(function (color) {
return color;
});
};
//# sourceMappingURL=color.js.map

@@ -6,2 +6,3 @@ 'use strict';

});
exports.redo = exports.undo = exports.handleKeyCommand = exports.clear = exports.setMediaPosition = exports.removeMedia = exports.setMediaData = exports.insertMedias = exports.insertHorizontalLine = exports.insertAtomicBlock = exports.insertHTML = exports.insertText = exports.toggleSelectionLetterSpacing = exports.toggleSelectionFontFamily = exports.toggleSelectionLineHeight = exports.toggleSelectionFontSize = exports.toggleSelectionBackgroundColor = exports.toggleSelectionColor = exports.decreaseSelectionIndent = exports.increaseSelectionIndent = exports.toggleSelectionIndent = exports.toggleSelectionAlignment = exports.removeSelectionInlineStyles = exports.toggleSelectionInlineStyle = exports.selectionHasInlineStyle = exports.getSelectionInlineStyle = exports.toggleSelectionLink = exports.toggleSelectionEntity = exports.getSelectionEntityData = exports.getSelectionEntityType = exports.toggleSelectionBlockType = exports.getSelectionText = exports.getSelectionBlockType = exports.getSelectionBlockData = exports.setSelectionBlockData = exports.getSelectionBlock = exports.removeBlock = exports.selectNextBlock = exports.selectBlock = exports.isSelectionCollapsed = exports.createEditorState = exports.createEmptyEditorState = exports.isEditorState = undefined;

@@ -14,418 +15,431 @@ var _draftJs = require('draft-js');

exports.default = {
isEditorState: function isEditorState(editorState) {
return editorState instanceof _draftJs.EditorState;
},
createEmptyEditorState: function createEmptyEditorState(editorDecorators) {
return _draftJs.EditorState.createEmpty(editorDecorators);
},
createEditorState: function createEditorState(contentState, editorDecorators) {
return _draftJs.EditorState.createWithContent(contentState, editorDecorators);
},
isSelectionCollapsed: function isSelectionCollapsed(editorState) {
return editorState.getSelection().isCollapsed();
},
selectBlock: function selectBlock(editorState, block) {
var isEditorState = exports.isEditorState = function isEditorState(editorState) {
return editorState instanceof _draftJs.EditorState;
};
var blockKey = block.getKey();
var createEmptyEditorState = exports.createEmptyEditorState = function createEmptyEditorState(editorDecorators) {
return _draftJs.EditorState.createEmpty(editorDecorators);
};
return _draftJs.EditorState.forceSelection(editorState, new _draftJs.SelectionState({
anchorKey: blockKey,
anchorOffset: 0,
focusKey: blockKey,
focusOffset: block.getLength()
}));
},
selectNextBlock: function selectNextBlock(editorState, block) {
var nextBlock = editorState.getCurrentContent().getBlockAfter(block.getKey());
return nextBlock ? this.selectBlock(editorState, nextBlock) : editorState;
},
removeBlock: function removeBlock(editorState, block) {
var lastSelection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var createEditorState = exports.createEditorState = function createEditorState(contentState, editorDecorators) {
return _draftJs.EditorState.createWithContent(contentState, editorDecorators);
};
var isSelectionCollapsed = exports.isSelectionCollapsed = function isSelectionCollapsed(editorState) {
return editorState.getSelection().isCollapsed();
};
var nextContentState = void 0,
nextEditorState = void 0;
var blockKey = block.getKey();
var selectBlock = exports.selectBlock = function selectBlock(editorState, block) {
nextContentState = _draftJs.Modifier.removeRange(editorState.getCurrentContent(), new _draftJs.SelectionState({
anchorKey: blockKey,
anchorOffset: 0,
focusKey: blockKey,
focusOffset: block.getLength()
}), 'backward');
var blockKey = block.getKey();
nextContentState = _draftJs.Modifier.setBlockType(nextContentState, nextContentState.getSelectionAfter(), 'unstyled');
nextEditorState = _draftJs.EditorState.push(editorState, nextContentState, 'remove-range');
return _draftJs.EditorState.forceSelection(nextEditorState, lastSelection || nextContentState.getSelectionAfter());
},
getSelectionBlock: function getSelectionBlock(editorState) {
return editorState.getCurrentContent().getBlockForKey(editorState.getSelection().getAnchorKey());
},
setSelectionBlockData: function setSelectionBlockData(editorState, blockData, override) {
return _draftJs.EditorState.forceSelection(editorState, new _draftJs.SelectionState({
anchorKey: blockKey,
anchorOffset: 0,
focusKey: blockKey,
focusOffset: block.getLength()
}));
};
var newBlockData = override ? blockData : Object.assign({}, this.getSelectionBlockData(editorState).toJS(), blockData);
var selectNextBlock = exports.selectNextBlock = function selectNextBlock(editorState, block) {
var nextBlock = editorState.getCurrentContent().getBlockAfter(block.getKey());
return nextBlock ? selectBlock(editorState, nextBlock) : editorState;
};
Object.keys(newBlockData).forEach(function (key) {
if (newBlockData.hasOwnProperty(key) && newBlockData[key] === undefined) {
delete newBlockData[key];
}
});
var removeBlock = exports.removeBlock = function removeBlock(editorState, block) {
var lastSelection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
return (0, _draftjsUtils.setBlockData)(editorState, newBlockData);
},
getSelectionBlockData: function getSelectionBlockData(editorState, name) {
var blockData = this.getSelectionBlock(editorState).getData();
return name ? blockData.get(name) : blockData;
},
getSelectionBlockType: function getSelectionBlockType(editorState) {
return this.getSelectionBlock(editorState).getType();
},
getSelectionText: function getSelectionText(editorState) {
var selectionState = editorState.getSelection();
var contentState = editorState.getCurrentContent();
var nextContentState = void 0,
nextEditorState = void 0;
var blockKey = block.getKey();
if (selectionState.isCollapsed() || this.getSelectionBlockType(editorState) === 'atomic') {
return '';
}
nextContentState = _draftJs.Modifier.removeRange(editorState.getCurrentContent(), new _draftJs.SelectionState({
anchorKey: blockKey,
anchorOffset: 0,
focusKey: blockKey,
focusOffset: block.getLength()
}), 'backward');
var anchorKey = selectionState.getAnchorKey();
var currentContentBlock = contentState.getBlockForKey(anchorKey);
var start = selectionState.getStartOffset();
var end = selectionState.getEndOffset();
nextContentState = _draftJs.Modifier.setBlockType(nextContentState, nextContentState.getSelectionAfter(), 'unstyled');
nextEditorState = _draftJs.EditorState.push(editorState, nextContentState, 'remove-range');
return _draftJs.EditorState.forceSelection(nextEditorState, lastSelection || nextContentState.getSelectionAfter());
};
return currentContentBlock.getText().slice(start, end);
},
toggleSelectionBlockType: function toggleSelectionBlockType(editorState, blockType) {
return _draftJs.RichUtils.toggleBlockType(editorState, blockType);
},
getSelectionEntityType: function getSelectionEntityType(editorState) {
var getSelectionBlock = exports.getSelectionBlock = function getSelectionBlock(editorState) {
return editorState.getCurrentContent().getBlockForKey(editorState.getSelection().getAnchorKey());
};
var entityKey = (0, _draftjsUtils.getSelectionEntity)(editorState);
var setSelectionBlockData = exports.setSelectionBlockData = function setSelectionBlockData(editorState, blockData, override) {
if (entityKey) {
var entity = editorState.getCurrentContent().getEntity(entityKey);
return entity ? entity.get('type') : null;
var newBlockData = override ? blockData : Object.assign({}, getSelectionBlockData(editorState).toJS(), blockData);
Object.keys(newBlockData).forEach(function (key) {
if (newBlockData.hasOwnProperty(key) && newBlockData[key] === undefined) {
delete newBlockData[key];
}
});
return null;
},
getSelectionEntityData: function getSelectionEntityData(editorState, type) {
return (0, _draftjsUtils.setBlockData)(editorState, newBlockData);
};
var entityKey = (0, _draftjsUtils.getSelectionEntity)(editorState);
var getSelectionBlockData = exports.getSelectionBlockData = function getSelectionBlockData(editorState, name) {
var blockData = getSelectionBlock(editorState).getData();
return name ? blockData.get(name) : blockData;
};
if (entityKey) {
var entity = editorState.getCurrentContent().getEntity(entityKey);
if (entity && entity.get('type') === type) {
return entity.getData();
} else {
return {};
}
var getSelectionBlockType = exports.getSelectionBlockType = function getSelectionBlockType(editorState) {
return getSelectionBlock(editorState).getType();
};
var getSelectionText = exports.getSelectionText = function getSelectionText(editorState) {
var selectionState = editorState.getSelection();
var contentState = editorState.getCurrentContent();
if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
return '';
}
var anchorKey = selectionState.getAnchorKey();
var currentContentBlock = contentState.getBlockForKey(anchorKey);
var start = selectionState.getStartOffset();
var end = selectionState.getEndOffset();
return currentContentBlock.getText().slice(start, end);
};
var toggleSelectionBlockType = exports.toggleSelectionBlockType = function toggleSelectionBlockType(editorState, blockType) {
return _draftJs.RichUtils.toggleBlockType(editorState, blockType);
};
var getSelectionEntityType = exports.getSelectionEntityType = function getSelectionEntityType(editorState) {
var entityKey = (0, _draftjsUtils.getSelectionEntity)(editorState);
if (entityKey) {
var entity = editorState.getCurrentContent().getEntity(entityKey);
return entity ? entity.get('type') : null;
}
return null;
};
var getSelectionEntityData = exports.getSelectionEntityData = function getSelectionEntityData(editorState, type) {
var entityKey = (0, _draftjsUtils.getSelectionEntity)(editorState);
if (entityKey) {
var entity = editorState.getCurrentContent().getEntity(entityKey);
if (entity && entity.get('type') === type) {
return entity.getData();
} else {
return {};
}
},
toggleSelectionEntity: function toggleSelectionEntity(editorState, entity) {
} else {
return {};
}
};
var contentState = editorState.getCurrentContent();
var selectionState = editorState.getSelection();
var toggleSelectionEntity = exports.toggleSelectionEntity = function toggleSelectionEntity(editorState, entity) {
if (selectionState.isCollapsed() || this.getSelectionBlockType(editorState) === 'atomic') {
return editorState;
}
var contentState = editorState.getCurrentContent();
var selectionState = editorState.getSelection();
if (!entity || !entity.type || this.getSelectionEntityType(editorState) === entity.type) {
return _draftJs.EditorState.push(editorState, _draftJs.Modifier.applyEntity(contentState, selectionState, null), 'apply-entity');
}
if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
return editorState;
}
try {
if (!entity || !entity.type || getSelectionEntityType(editorState) === entity.type) {
return _draftJs.EditorState.push(editorState, _draftJs.Modifier.applyEntity(contentState, selectionState, null), 'apply-entity');
}
var nextContentState = contentState.createEntity(entity.type, entity.mutability, entity.data);
var entityKey = nextContentState.getLastCreatedEntityKey();
try {
var nextEditorState = _draftJs.EditorState.set(editorState, {
currentContent: nextContentState
});
var nextContentState = contentState.createEntity(entity.type, entity.mutability, entity.data);
var entityKey = nextContentState.getLastCreatedEntityKey();
return _draftJs.EditorState.push(nextEditorState, _draftJs.Modifier.applyEntity(nextContentState, selectionState, entityKey), 'apply-entity');
} catch (error) {
console.warn(error);
return editorState;
}
},
toggleSelectionLink: function toggleSelectionLink(editorState, href, target) {
var nextEditorState = _draftJs.EditorState.set(editorState, {
currentContent: nextContentState
});
var contentState = editorState.getCurrentContent();
var selectionState = editorState.getSelection();
return _draftJs.EditorState.push(nextEditorState, _draftJs.Modifier.applyEntity(nextContentState, selectionState, entityKey), 'apply-entity');
} catch (error) {
console.warn(error);
return editorState;
}
};
var entityData = { href: href, target: target };
var toggleSelectionLink = exports.toggleSelectionLink = function toggleSelectionLink(editorState, href, target) {
if (selectionState.isCollapsed() || this.getSelectionBlockType(editorState) === 'atomic') {
return editorState;
}
var contentState = editorState.getCurrentContent();
var selectionState = editorState.getSelection();
if (href === false) {
return _draftJs.RichUtils.toggleLink(editorState, selectionState, null);
}
var entityData = { href: href, target: target };
if (href === null) {
delete entityData.href;
}
if (selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
return editorState;
}
try {
if (href === false) {
return _draftJs.RichUtils.toggleLink(editorState, selectionState, null);
}
var nextContentState = contentState.createEntity('LINK', 'MUTABLE', entityData);
var entityKey = nextContentState.getLastCreatedEntityKey();
if (href === null) {
delete entityData.href;
}
var nextEditorState = _draftJs.EditorState.set(editorState, {
currentContent: nextContentState
});
try {
nextEditorState = _draftJs.RichUtils.toggleLink(nextEditorState, selectionState, entityKey);
nextEditorState = _draftJs.EditorState.forceSelection(nextEditorState, selectionState.merge({
anchorOffset: selectionState.getEndOffset(),
focusOffset: selectionState.getEndOffset()
}));
var nextContentState = contentState.createEntity('LINK', 'MUTABLE', entityData);
var entityKey = nextContentState.getLastCreatedEntityKey();
nextEditorState = _draftJs.EditorState.push(nextEditorState, _draftJs.Modifier.insertText(nextEditorState.getCurrentContent(), nextEditorState.getSelection(), ' '), 'insert-text');
var nextEditorState = _draftJs.EditorState.set(editorState, {
currentContent: nextContentState
});
return nextEditorState;
} catch (error) {
console.warn(error);
return editorState;
}
},
getSelectionInlineStyle: function getSelectionInlineStyle(editorState) {
return editorState.getCurrentInlineStyle();
},
selectionHasInlineStyle: function selectionHasInlineStyle(editorState, style) {
return this.getSelectionInlineStyle(editorState).has(style.toUpperCase());
},
toggleSelectionInlineStyle: function toggleSelectionInlineStyle(editorState, style) {
var stylesToBeRemoved = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
nextEditorState = _draftJs.RichUtils.toggleLink(nextEditorState, selectionState, entityKey);
nextEditorState = _draftJs.EditorState.forceSelection(nextEditorState, selectionState.merge({
anchorOffset: selectionState.getEndOffset(),
focusOffset: selectionState.getEndOffset()
}));
nextEditorState = _draftJs.EditorState.push(nextEditorState, _draftJs.Modifier.insertText(nextEditorState.getCurrentContent(), nextEditorState.getSelection(), ' '), 'insert-text');
var selectionState = editorState.getSelection();
var contentState = editorState.getCurrentContent();
return nextEditorState;
} catch (error) {
console.warn(error);
return editorState;
}
};
style = style.toUpperCase();
stylesToBeRemoved = stylesToBeRemoved.filter(function (item) {
return item !== style;
});
var getSelectionInlineStyle = exports.getSelectionInlineStyle = function getSelectionInlineStyle(editorState) {
return editorState.getCurrentInlineStyle();
};
var nextContentState = stylesToBeRemoved.length ? stylesToBeRemoved.reduce(function (contentState, item) {
return _draftJs.Modifier.removeInlineStyle(contentState, selectionState, item);
}, contentState) : contentState;
var selectionHasInlineStyle = exports.selectionHasInlineStyle = function selectionHasInlineStyle(editorState, style) {
return getSelectionInlineStyle(editorState).has(style.toUpperCase());
};
var nextEditorState = stylesToBeRemoved.length ? _draftJs.EditorState.push(editorState, nextContentState, 'change-inline-style') : editorState;
return _draftJs.RichUtils.toggleInlineStyle(nextEditorState, style);
},
removeSelectionInlineStyles: function removeSelectionInlineStyles(editorState) {
return (0, _draftjsUtils.removeAllInlineStyles)(editorState);
},
toggleSelectionAlignment: function toggleSelectionAlignment(editorState, alignment) {
return this.setSelectionBlockData(editorState, {
textAlign: this.getSelectionBlockData(editorState, 'textAlign') !== alignment ? alignment : undefined
});
},
toggleSelectionIndent: function toggleSelectionIndent(editorState, textIndent) {
var maxIndent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 6;
var toggleSelectionInlineStyle = exports.toggleSelectionInlineStyle = function toggleSelectionInlineStyle(editorState, style, prefix) {
return textIndent < 0 || textIndent > maxIndent || isNaN(textIndent) ? editorState : this.setSelectionBlockData(editorState, {
textIndent: textIndent || undefined
});
},
increaseSelectionIndent: function increaseSelectionIndent(editorState) {
var maxIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
var selectionState = editorState.getSelection();
var contentState = editorState.getCurrentContent();
var currentIndent = this.getSelectionBlockData(editorState, 'textIndent') || 0;
return this.toggleSelectionIndent(editorState, currentIndent + 1, maxIndent);
},
decreaseSelectionIndent: function decreaseSelectionIndent(editorState) {
var currentIndent = this.getSelectionBlockData(editorState, 'textIndent') || 0;
return this.toggleSelectionIndent(editorState, currentIndent - 1);
},
toggleSelectionColor: function toggleSelectionColor(editorState, color) {
var colorList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
style = style.toUpperCase();
return this.toggleSelectionInlineStyle(editorState, 'COLOR-' + color.replace('#', ''), colorList.map(function (item) {
return 'COLOR-' + item.replace('#', '').toUpperCase();
}));
},
toggleSelectionBackgroundColor: function toggleSelectionBackgroundColor(editorState, color) {
var colorList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
var stylesToBeRemoved = prefix ? editorState.getCurrentInlineStyle().toJS().filter(function (item) {
return item.indexOf(prefix) === 0;
}) : [];
return this.toggleSelectionInlineStyle(editorState, 'BGCOLOR-' + color.replace('#', ''), colorList.map(function (item) {
return 'BGCOLOR-' + item.replace('#', '').toUpperCase();
}));
},
toggleSelectionFontSize: function toggleSelectionFontSize(editorState, fontSize) {
var fontSizeList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
var nextEditorState = stylesToBeRemoved.length ? stylesToBeRemoved.reduce(function (editorState, item) {
// return Modifier.removeInlineStyle(contentState, selectionState, item)
return _draftJs.RichUtils.toggleInlineStyle(editorState, item);
}, editorState) : editorState;
return this.toggleSelectionInlineStyle(editorState, 'FONTSIZE-' + fontSize, fontSizeList.map(function (item) {
return 'FONTSIZE-' + item;
}));
},
toggleSelectionLineHeight: function toggleSelectionLineHeight(editorState, lineHeight) {
var lineHeightList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
// const nextEditorState = stylesToBeRemoved.length ? EditorState.push(editorState, nextContentState, 'change-inline-style') : editorState
return _draftJs.RichUtils.toggleInlineStyle(nextEditorState, style);
};
return this.toggleSelectionInlineStyle(editorState, 'LINEHEIGHT-' + lineHeight, lineHeightList.map(function (item) {
return 'LINEHEIGHT-' + item;
}));
},
toggleSelectionFontFamily: function toggleSelectionFontFamily(editorState, fontFamily) {
var fontFamilyList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
var removeSelectionInlineStyles = exports.removeSelectionInlineStyles = function removeSelectionInlineStyles(editorState) {
return (0, _draftjsUtils.removeAllInlineStyles)(editorState);
};
return this.toggleSelectionInlineStyle(editorState, 'FONTFAMILY-' + fontFamily, fontFamilyList.map(function (item) {
return 'FONTFAMILY-' + item.name.toUpperCase();
}));
},
toggleSelectionLetterSpacing: function toggleSelectionLetterSpacing(editorState, letterSpacing) {
var letterSpacingList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
var toggleSelectionAlignment = exports.toggleSelectionAlignment = function toggleSelectionAlignment(editorState, alignment) {
return setSelectionBlockData(editorState, {
textAlign: getSelectionBlockData(editorState, 'textAlign') !== alignment ? alignment : undefined
});
};
return this.toggleSelectionInlineStyle(editorState, 'LETTERSPACING-' + letterSpacing, letterSpacingList.map(function (item) {
return 'LETTERSPACING-' + item;
}));
},
insertText: function insertText(editorState, text, inlineStyle, entity) {
var toggleSelectionIndent = exports.toggleSelectionIndent = function toggleSelectionIndent(editorState, textIndent) {
var maxIndent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 6;
var selectionState = editorState.getSelection();
var currentSelectedBlockType = this.getSelectionBlockType(editorState);
return textIndent < 0 || textIndent > maxIndent || isNaN(textIndent) ? editorState : setSelectionBlockData(editorState, {
textIndent: textIndent || undefined
});
};
if (currentSelectedBlockType === 'atomic') {
return editorState;
}
var increaseSelectionIndent = exports.increaseSelectionIndent = function increaseSelectionIndent(editorState) {
var maxIndent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 6;
var entityKey = void 0;
var contentState = editorState.getCurrentContent();
var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
return toggleSelectionIndent(editorState, currentIndent + 1, maxIndent);
};
if (entity && entity.type) {
contentState = contentState.createEntity(entity.type, entity.mutability || 'MUTABLE', entity.data || entityData);
entityKey = contentState.getLastCreatedEntityKey();
}
var decreaseSelectionIndent = exports.decreaseSelectionIndent = function decreaseSelectionIndent(editorState) {
var currentIndent = getSelectionBlockData(editorState, 'textIndent') || 0;
return toggleSelectionIndent(editorState, currentIndent - 1);
};
if (!selectionState.isCollapsed()) {
return _draftJs.EditorState.push(editorState, _draftJs.Modifier.replaceText(contentState, selectionState, text, inlineStyle, entityKey), 'replace-text');
} else {
return _draftJs.EditorState.push(editorState, _draftJs.Modifier.insertText(contentState, selectionState, text, inlineStyle, entityKey), 'insert-text');
}
},
insertHTML: function insertHTML(editorState, htmlString, source) {
var toggleSelectionColor = exports.toggleSelectionColor = function toggleSelectionColor(editorState, color) {
return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'COLOR-');
};
if (!htmlString) {
return editorState;
}
var toggleSelectionBackgroundColor = exports.toggleSelectionBackgroundColor = function toggleSelectionBackgroundColor(editorState, color) {
return toggleSelectionInlineStyle(editorState, color.replace('#', ''), 'BGCOLOR-');
};
var selectionState = editorState.getSelection();
var contentState = editorState.getCurrentContent();
var options = editorState.convertOptions || {};
var toggleSelectionFontSize = exports.toggleSelectionFontSize = function toggleSelectionFontSize(editorState, fontSize) {
return toggleSelectionInlineStyle(editorState, fontSize, 'FONTSIZE-');
};
try {
var _convertFromRaw = (0, _draftJs.convertFromRaw)((0, _braftConvert.convertHTMLToRaw)(htmlString, options, source)),
blockMap = _convertFromRaw.blockMap;
var toggleSelectionLineHeight = exports.toggleSelectionLineHeight = function toggleSelectionLineHeight(editorState, lineHeight) {
return toggleSelectionInlineStyle(editorState, lineHeight, 'LINEHEIGHT-');
};
return _draftJs.EditorState.push(editorState, _draftJs.Modifier.replaceWithFragment(contentState, selectionState, blockMap), 'insert-fragment');
} catch (error) {
console.warn(error);
return editorState;
}
},
insertAtomicBlock: function insertAtomicBlock(editorState, type) {
var immutable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var toggleSelectionFontFamily = exports.toggleSelectionFontFamily = function toggleSelectionFontFamily(editorState, fontFamily) {
return toggleSelectionInlineStyle(editorState, fontFamily, 'FONTFAMILY-');
};
var toggleSelectionLetterSpacing = exports.toggleSelectionLetterSpacing = function toggleSelectionLetterSpacing(editorState, letterSpacing) {
return toggleSelectionInlineStyle(editorState, letterSpacing, 'LETTERSPACING-');
};
var selectionState = editorState.getSelection();
var contentState = editorState.getCurrentContent();
var insertText = exports.insertText = function insertText(editorState, text, inlineStyle, entity) {
if (!selectionState.isCollapsed() || this.getSelectionBlockType(editorState) === 'atomic') {
return editorState;
}
var selectionState = editorState.getSelection();
var currentSelectedBlockType = getSelectionBlockType(editorState);
var contentStateWithEntity = contentState.createEntity(type, immutable ? 'IMMUTABLE' : 'MUTABLE', data);
var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
var newEditorState = _draftJs.AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
if (currentSelectedBlockType === 'atomic') {
return editorState;
}
return newEditorState;
},
insertHorizontalLine: function insertHorizontalLine(editorState) {
return this.insertAtomicBlock(editorState, 'HR');
},
insertMedias: function insertMedias(editorState) {
var medias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var entityKey = void 0;
var contentState = editorState.getCurrentContent();
if (entity && entity.type) {
contentState = contentState.createEntity(entity.type, entity.mutability || 'MUTABLE', entity.data || entityData);
entityKey = contentState.getLastCreatedEntityKey();
}
if (!medias.length) {
return editorState;
}
if (!selectionState.isCollapsed()) {
return _draftJs.EditorState.push(editorState, _draftJs.Modifier.replaceText(contentState, selectionState, text, inlineStyle, entityKey), 'replace-text');
} else {
return _draftJs.EditorState.push(editorState, _draftJs.Modifier.insertText(contentState, selectionState, text, inlineStyle, entityKey), 'insert-text');
}
};
if (this.getSelectionBlockType(editorState) === 'atomic') {
this.selectNextBlock(editorState, this.getSelectionBlock(editorState));
}
var insertHTML = exports.insertHTML = function insertHTML(editorState, htmlString, source) {
return medias.reduce(function (editorState, media) {
var url = media.url,
name = media.name,
type = media.type,
meta = media.meta;
if (!htmlString) {
return editorState;
}
var contentStateWithEntity = editorState.getCurrentContent().createEntity(type, 'IMMUTABLE', { url: url, name: name, type: type, meta: meta });
var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
return _draftJs.AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
}, editorState);
},
setMediaData: function setMediaData(editorState, entityKey, data) {
return _draftJs.EditorState.push(editorState, editorState.getCurrentContent().mergeEntityData(entityKey, data), 'change-block-data');
},
removeMedia: function removeMedia(editorState, mediaBlock) {
return this.removeBlock(editorState, mediaBlock);
},
setMediaPosition: function setMediaPosition(editorState, mediaBlock, position) {
var selectionState = editorState.getSelection();
var contentState = editorState.getCurrentContent();
var options = editorState.convertOptions || {};
var newPosition = {};
var float = position.float,
alignment = position.alignment;
try {
var _convertFromRaw = (0, _draftJs.convertFromRaw)((0, _braftConvert.convertHTMLToRaw)(htmlString, options, source)),
blockMap = _convertFromRaw.blockMap;
return _draftJs.EditorState.push(editorState, _draftJs.Modifier.replaceWithFragment(contentState, selectionState, blockMap), 'insert-fragment');
} catch (error) {
console.warn(error);
return editorState;
}
};
if (typeof float !== 'undefined') {
newPosition.float = mediaBlock.getData().get('float') === float ? null : float;
}
var insertAtomicBlock = exports.insertAtomicBlock = function insertAtomicBlock(editorState, type) {
var immutable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var data = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
if (typeof alignment !== 'undefined') {
newPosition.alignment = mediaBlock.getData().get('alignment') === alignment ? null : alignment;
}
return this.setSelectionBlockData(this.selectBlock(editorState, mediaBlock), newPosition);
},
clear: function clear(editorState) {
var selectionState = editorState.getSelection();
var contentState = editorState.getCurrentContent();
var contentState = editorState.getCurrentContent();
if (!selectionState.isCollapsed() || getSelectionBlockType(editorState) === 'atomic') {
return editorState;
}
var firstBlock = contentState.getFirstBlock();
var lastBlock = contentState.getLastBlock();
var contentStateWithEntity = contentState.createEntity(type, immutable ? 'IMMUTABLE' : 'MUTABLE', data);
var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
var newEditorState = _draftJs.AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
var allSelected = new _draftJs.SelectionState({
anchorKey: firstBlock.getKey(),
anchorOffset: 0,
focusKey: lastBlock.getKey(),
focusOffset: lastBlock.getLength(),
hasFocus: true
});
return newEditorState;
};
return _draftJs.EditorState.push(editorState, _draftJs.Modifier.removeRange(contentState, allSelected, 'backward'), 'remove-range');
},
handleKeyCommand: function handleKeyCommand(editorState, command) {
return _draftJs.RichUtils.handleKeyCommand(editorState, command);
},
handleNewLine: function handleNewLine(editorState, event) {
return (0, _draftjsUtils.handleNewLine)(editorState, event);
},
undo: function undo(editorState) {
return _draftJs.EditorState.undo(editorState);
},
redo: function redo(editorState) {
return _draftJs.EditorState.redo(editorState);
var insertHorizontalLine = exports.insertHorizontalLine = function insertHorizontalLine(editorState) {
return insertAtomicBlock(editorState, 'HR');
};
var insertMedias = exports.insertMedias = function insertMedias(editorState) {
var medias = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
if (!medias.length) {
return editorState;
}
if (getSelectionBlockType(editorState) === 'atomic') {
selectNextBlock(editorState, getSelectionBlock(editorState));
}
return medias.reduce(function (editorState, media) {
var url = media.url,
name = media.name,
type = media.type,
meta = media.meta;
var contentStateWithEntity = editorState.getCurrentContent().createEntity(type, 'IMMUTABLE', { url: url, name: name, type: type, meta: meta });
var entityKey = contentStateWithEntity.getLastCreatedEntityKey();
return _draftJs.AtomicBlockUtils.insertAtomicBlock(editorState, entityKey, ' ');
}, editorState);
};
var setMediaData = exports.setMediaData = function setMediaData(editorState, entityKey, data) {
return _draftJs.EditorState.push(editorState, editorState.getCurrentContent().mergeEntityData(entityKey, data), 'change-block-data');
};
var removeMedia = exports.removeMedia = function removeMedia(editorState, mediaBlock) {
return removeBlock(editorState, mediaBlock);
};
var setMediaPosition = exports.setMediaPosition = function setMediaPosition(editorState, mediaBlock, position) {
var newPosition = {};
var float = position.float,
alignment = position.alignment;
if (typeof float !== 'undefined') {
newPosition.float = mediaBlock.getData().get('float') === float ? null : float;
}
if (typeof alignment !== 'undefined') {
newPosition.alignment = mediaBlock.getData().get('alignment') === alignment ? null : alignment;
}
return setSelectionBlockData(selectBlock(editorState, mediaBlock), newPosition);
};
var clear = exports.clear = function clear(editorState) {
var contentState = editorState.getCurrentContent();
var firstBlock = contentState.getFirstBlock();
var lastBlock = contentState.getLastBlock();
var allSelected = new _draftJs.SelectionState({
anchorKey: firstBlock.getKey(),
anchorOffset: 0,
focusKey: lastBlock.getKey(),
focusOffset: lastBlock.getLength(),
hasFocus: true
});
return _draftJs.EditorState.push(editorState, _draftJs.Modifier.removeRange(contentState, allSelected, 'backward'), 'remove-range');
};
var handleKeyCommand = exports.handleKeyCommand = function handleKeyCommand(editorState, command) {
return _draftJs.RichUtils.handleKeyCommand(editorState, command);
};
var undo = exports.undo = function undo(editorState) {
return _draftJs.EditorState.undo(editorState);
};
var redo = exports.redo = function redo(editorState) {
return _draftJs.EditorState.redo(editorState);
};
//# sourceMappingURL=content.js.map
{
"name": "braft-utils",
"version": "2.1.2",
"version": "3.0.0",
"description": "Utils for Braft Editor",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet