Comparing version 0.10.1 to 0.11.0-alpha
@@ -7,2 +7,6 @@ # Changelog | ||
## 0.11.0-alpha (February 2017) | ||
* Moved entities into content state | ||
## 0.10.1 | ||
@@ -9,0 +13,0 @@ |
@@ -16,5 +16,2 @@ /** | ||
// TODO: when removing the deprecated API update this to use the EntityMap type | ||
// instead of OrderedMap | ||
var key = 0; | ||
@@ -21,0 +18,0 @@ |
@@ -21,4 +21,4 @@ /** | ||
var EditorState = require('./EditorState'); | ||
var Immutable = require('immutable'); | ||
var SelectionState = require('./SelectionState'); | ||
var Immutable = require('immutable'); | ||
@@ -28,4 +28,4 @@ var generateRandomKey = require('./generateRandomKey'); | ||
var List = Immutable.List; | ||
var Repeat = Immutable.Repeat; | ||
var List = Immutable.List, | ||
Repeat = Immutable.Repeat; | ||
@@ -32,0 +32,0 @@ |
@@ -20,5 +20,5 @@ /** | ||
var List = Immutable.List; | ||
var Repeat = Immutable.Repeat; | ||
var Record = Immutable.Record; | ||
var List = Immutable.List, | ||
Repeat = Immutable.Repeat, | ||
Record = Immutable.Record; | ||
@@ -62,3 +62,3 @@ | ||
var leafSets = []; | ||
var decorations = decorator ? decorator.getDecorations(block, contentState) : List(Repeat(null, textLength)); | ||
var decorations = decorator ? decorator.getDecorations(contentState, block) : List(Repeat(null, textLength)); | ||
@@ -65,0 +65,0 @@ var chars = block.getCharacterList(); |
@@ -22,11 +22,11 @@ /** | ||
var _require = require('immutable'); | ||
var _require = require('immutable'), | ||
Map = _require.Map, | ||
OrderedSet = _require.OrderedSet, | ||
Record = _require.Record; | ||
var Map = _require.Map; | ||
var OrderedSet = _require.OrderedSet; | ||
var Record = _require.Record; | ||
// Immutable.map is typed such that the value for every key in the map | ||
// must be the same type | ||
var EMPTY_SET = OrderedSet(); | ||
@@ -33,0 +33,0 @@ |
@@ -55,3 +55,3 @@ /** | ||
CompositeDraftDecorator.prototype.getDecorations = function getDecorations(block, contentState) { | ||
CompositeDraftDecorator.prototype.getDecorations = function getDecorations(contentState, block) { | ||
var decorations = Array(block.getText().length).fill(null); | ||
@@ -71,3 +71,3 @@ | ||
}; | ||
strategy(block, callback, contentState); | ||
strategy(contentState, block, callback); | ||
}); | ||
@@ -74,0 +74,0 @@ |
@@ -25,6 +25,6 @@ /** | ||
var List = Immutable.List; | ||
var Map = Immutable.Map; | ||
var OrderedSet = Immutable.OrderedSet; | ||
var Record = Immutable.Record; | ||
var List = Immutable.List, | ||
Map = Immutable.Map, | ||
OrderedSet = Immutable.OrderedSet, | ||
Record = Immutable.Record; | ||
@@ -31,0 +31,0 @@ |
@@ -25,12 +25,16 @@ /** | ||
var ContentBlock = require('./ContentBlock'); | ||
var DraftEntity = require('./DraftEntity'); | ||
var Immutable = require('immutable'); | ||
var SelectionState = require('./SelectionState'); | ||
var addEntityToContentState = require('./addEntityToContentState'); | ||
var createEntityInContentState = require('./createEntityInContentState'); | ||
var invariant = require('fbjs/lib/invariant'); | ||
var generateRandomKey = require('./generateRandomKey'); | ||
var sanitizeDraftText = require('./sanitizeDraftText'); | ||
var updateEntityDataInContentState = require('./updateEntityDataInContentState'); | ||
var List = Immutable.List; | ||
var Record = Immutable.Record; | ||
var Repeat = Immutable.Repeat; | ||
var List = Immutable.List, | ||
Record = Immutable.Record, | ||
Repeat = Immutable.Repeat, | ||
OrderedMap = Immutable.OrderedMap; | ||
@@ -57,4 +61,3 @@ | ||
ContentState.prototype.getEntityMap = function getEntityMap() { | ||
// TODO: update this when we fully remove DraftEntity | ||
return DraftEntity; | ||
return this.get('entityMap'); | ||
}; | ||
@@ -122,4 +125,3 @@ | ||
ContentState.prototype.getLastCreatedEntityKey = function getLastCreatedEntityKey() { | ||
// TODO: update this when we fully remove DraftEntity | ||
return DraftEntity.__getLastCreatedEntityKey(); | ||
return this.getEntityMap().keySeq().last(); | ||
}; | ||
@@ -133,40 +135,29 @@ | ||
ContentState.prototype.createEntity = function createEntity(type, mutability, data) { | ||
// TODO: update this when we fully remove DraftEntity | ||
DraftEntity.__create(type, mutability, data); | ||
return this; | ||
return createEntityInContentState(this, type, mutability, data); | ||
}; | ||
ContentState.prototype.mergeEntityData = function mergeEntityData(key, toMerge) { | ||
// TODO: update this when we fully remove DraftEntity | ||
DraftEntity.__mergeData(key, toMerge); | ||
return this; | ||
return updateEntityDataInContentState(this, key, toMerge, true); | ||
}; | ||
ContentState.prototype.replaceEntityData = function replaceEntityData(key, newData) { | ||
// TODO: update this when we fully remove DraftEntity | ||
DraftEntity.__replaceData(key, newData); | ||
return this; | ||
return updateEntityDataInContentState(this, key, newData, false); | ||
}; | ||
ContentState.prototype.addEntity = function addEntity(instance) { | ||
// TODO: update this when we fully remove DraftEntity | ||
DraftEntity.__add(instance); | ||
return this; | ||
return addEntityToContentState(this, instance); | ||
}; | ||
ContentState.prototype.getEntity = function getEntity(key) { | ||
// TODO: update this when we fully remove DraftEntity | ||
return DraftEntity.__get(key); | ||
var instance = this.getEntityMap().get(key); | ||
!!!instance ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Unknown DraftEntity Key.') : invariant(false) : void 0; | ||
return instance; | ||
}; | ||
ContentState.createFromBlockArray = function createFromBlockArray( | ||
// TODO: update flow type when we completely deprecate the old entity API | ||
blocks, entityMap) { | ||
// TODO: remove this when we completely deprecate the old entity API | ||
var theBlocks = Array.isArray(blocks) ? blocks : blocks.contentBlocks; | ||
var blockMap = BlockMapBuilder.createFromArray(theBlocks); | ||
ContentState.createFromBlockArray = function createFromBlockArray(blocks, entityMap) { | ||
var blockMap = BlockMapBuilder.createFromArray(blocks); | ||
var selectionState = blockMap.isEmpty() ? new SelectionState() : SelectionState.createEmpty(blockMap.first().getKey()); | ||
return new ContentState({ | ||
blockMap: blockMap, | ||
entityMap: entityMap || DraftEntity, | ||
entityMap: entityMap || OrderedMap(), | ||
selectionBefore: selectionState, | ||
@@ -178,3 +169,3 @@ selectionAfter: selectionState | ||
ContentState.createFromText = function createFromText(text) { | ||
var delimiter = arguments.length <= 1 || arguments[1] === undefined ? /\r\n?|\n/g : arguments[1]; | ||
var delimiter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : /\r\n?|\n/g; | ||
@@ -181,0 +172,0 @@ var strings = text.split(delimiter); |
@@ -18,7 +18,5 @@ /** | ||
var _require = require('immutable'); | ||
var _require = require('immutable'), | ||
Map = _require.Map; | ||
var Map = _require.Map; | ||
var ContentStateInlineStyle = { | ||
@@ -25,0 +23,0 @@ add: function add(contentState, selectionState, inlineStyle) { |
@@ -19,6 +19,11 @@ /** | ||
var DefaultDraftBlockRenderMap = require('./DefaultDraftBlockRenderMap'); | ||
var DraftEntity = require('./DraftEntity'); | ||
var DraftEntityInstance = require('./DraftEntityInstance'); | ||
var Immutable = require('immutable'); | ||
var _require = require('immutable'), | ||
Set = _require.Set; | ||
var URI = require('fbjs/lib/URI'); | ||
var addEntityToEntityMap = require('./addEntityToEntityMap'); | ||
var generateRandomKey = require('./generateRandomKey'); | ||
@@ -30,9 +35,7 @@ var getSafeBodyFromHTML = require('./getSafeBodyFromHTML'); | ||
var _require = require('immutable'); | ||
var List = Immutable.List, | ||
OrderedSet = Immutable.OrderedSet, | ||
OrderedMap = Immutable.OrderedMap; | ||
var Set = _require.Set; | ||
var List = Immutable.List; | ||
var OrderedSet = Immutable.OrderedSet; | ||
var NBSP = ' '; | ||
@@ -127,3 +130,3 @@ var SPACE = ' '; | ||
var unstyledElement = blockRenderMap.get('unstyled').element; | ||
var tags = new Set([]); | ||
var tags = Set([]); | ||
@@ -181,33 +184,31 @@ blockRenderMap.forEach(function (draftBlock) { | ||
} else if (node instanceof HTMLElement) { | ||
(function () { | ||
var htmlElement = node; | ||
currentStyle = currentStyle.withMutations(function (style) { | ||
var fontWeight = htmlElement.style.fontWeight; | ||
var fontStyle = htmlElement.style.fontStyle; | ||
var textDecoration = htmlElement.style.textDecoration; | ||
var htmlElement = node; | ||
currentStyle = currentStyle.withMutations(function (style) { | ||
var fontWeight = htmlElement.style.fontWeight; | ||
var fontStyle = htmlElement.style.fontStyle; | ||
var textDecoration = htmlElement.style.textDecoration; | ||
if (boldValues.indexOf(fontWeight) >= 0) { | ||
style.add('BOLD'); | ||
} else if (notBoldValues.indexOf(fontWeight) >= 0) { | ||
style.remove('BOLD'); | ||
} | ||
if (boldValues.indexOf(fontWeight) >= 0) { | ||
style.add('BOLD'); | ||
} else if (notBoldValues.indexOf(fontWeight) >= 0) { | ||
style.remove('BOLD'); | ||
} | ||
if (fontStyle === 'italic') { | ||
style.add('ITALIC'); | ||
} else if (fontStyle === 'normal') { | ||
style.remove('ITALIC'); | ||
} | ||
if (fontStyle === 'italic') { | ||
style.add('ITALIC'); | ||
} else if (fontStyle === 'normal') { | ||
style.remove('ITALIC'); | ||
} | ||
if (textDecoration === 'underline') { | ||
style.add('UNDERLINE'); | ||
} | ||
if (textDecoration === 'line-through') { | ||
style.add('STRIKETHROUGH'); | ||
} | ||
if (textDecoration === 'none') { | ||
style.remove('UNDERLINE'); | ||
style.remove('STRIKETHROUGH'); | ||
} | ||
}).toOrderedSet(); | ||
})(); | ||
if (textDecoration === 'underline') { | ||
style.add('UNDERLINE'); | ||
} | ||
if (textDecoration === 'line-through') { | ||
style.add('STRIKETHROUGH'); | ||
} | ||
if (textDecoration === 'none') { | ||
style.remove('UNDERLINE'); | ||
style.remove('STRIKETHROUGH'); | ||
} | ||
}).toOrderedSet(); | ||
} | ||
@@ -311,18 +312,20 @@ return currentStyle; | ||
if (nodeName === 'img' && node instanceof HTMLImageElement && node.attributes.getNamedItem('src') && node.attributes.getNamedItem('src').value) { | ||
(function () { | ||
var image = node; | ||
var entityConfig = {}; | ||
var image = node; | ||
var entityConfig = {}; | ||
imgAttr.forEach(function (attr) { | ||
var imageAttribute = image.getAttribute(attr); | ||
if (imageAttribute) { | ||
entityConfig[attr] = imageAttribute; | ||
} | ||
}); | ||
var imageURI = new URI(entityConfig.src).toString(); | ||
node.textContent = imageURI; // Output src if no decorator | ||
imgAttr.forEach(function (attr) { | ||
var imageAttribute = image.getAttribute(attr); | ||
if (imageAttribute) { | ||
entityConfig[attr] = imageAttribute; | ||
} | ||
}); | ||
var imageURI = new URI(entityConfig.src).toString(); | ||
node.textContent = imageURI; // Output src if no decorator | ||
// TODO: update this when we remove DraftEntity entirely | ||
inEntity = DraftEntity.__create('IMAGE', 'MUTABLE', entityConfig || {}); | ||
})(); | ||
newEntityMap = addEntityToEntityMap(newEntityMap, new DraftEntityInstance({ | ||
type: 'IMAGE', | ||
mutability: 'MUTABLE', | ||
data: entityConfig || {} | ||
})); | ||
inEntity = newEntityMap.keySeq().last(); | ||
} | ||
@@ -378,4 +381,9 @@ | ||
entityConfig.url = new URI(anchor.href).toString(); | ||
// TODO: update this when we remove DraftEntity completely | ||
entityId = DraftEntity.__create('LINK', 'MUTABLE', entityConfig || {}); | ||
newEntityMap = addEntityToEntityMap(newEntityMap, new DraftEntityInstance({ | ||
type: 'LINK', | ||
mutability: 'MUTABLE', | ||
data: entityConfig || {} | ||
})); | ||
entityId = newEntityMap.keySeq().last(); | ||
})(); | ||
@@ -386,8 +394,6 @@ } else { | ||
var _genFragment = genFragment(newEntityMap, child, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, entityId || inEntity); | ||
var _genFragment = genFragment(newEntityMap, child, inlineStyle, lastList, inBlock, blockTags, depth, blockRenderMap, entityId || inEntity), | ||
generatedChunk = _genFragment.chunk, | ||
maybeUpdatedEntityMap = _genFragment.entityMap; | ||
var generatedChunk = _genFragment.chunk; | ||
var maybeUpdatedEntityMap = _genFragment.entityMap; | ||
newChunk = generatedChunk; | ||
@@ -435,9 +441,9 @@ newEntityMap = maybeUpdatedEntityMap; | ||
var _genFragment2 = genFragment(entityMap, safeBody, OrderedSet(), 'ul', null, workingBlocks, -1, blockRenderMap); | ||
var _genFragment2 = genFragment(entityMap, safeBody, OrderedSet(), 'ul', null, workingBlocks, -1, blockRenderMap), | ||
chunk = _genFragment2.chunk, | ||
newEntityMap = _genFragment2.entityMap; | ||
var chunk = _genFragment2.chunk; | ||
var newEntityMap = _genFragment2.entityMap; | ||
// join with previous block to prevent weirdness on paste | ||
if (chunk.text.indexOf('\r') === 0) { | ||
@@ -476,4 +482,4 @@ chunk = { | ||
function convertFromHTMLtoContentBlocks(html) { | ||
var DOMBuilder = arguments.length <= 1 || arguments[1] === undefined ? getSafeBodyFromHTML : arguments[1]; | ||
var blockRenderMap = arguments.length <= 2 || arguments[2] === undefined ? DefaultDraftBlockRenderMap : arguments[2]; | ||
var DOMBuilder = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : getSafeBodyFromHTML; | ||
var blockRenderMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DefaultDraftBlockRenderMap; | ||
@@ -485,3 +491,3 @@ // Be ABSOLUTELY SURE that the dom builder you pass here won't execute | ||
// TODO: replace DraftEntity with an OrderedMap here | ||
var chunkData = getChunkForHTML(html, DOMBuilder, blockRenderMap, DraftEntity); | ||
var chunkData = getChunkForHTML(html, DOMBuilder, blockRenderMap, OrderedMap()); | ||
@@ -492,4 +498,4 @@ if (chunkData == null) { | ||
var chunk = chunkData.chunk; | ||
var newEntityMap = chunkData.entityMap; | ||
var chunk = chunkData.chunk, | ||
newEntityMap = chunkData.entityMap; | ||
@@ -496,0 +502,0 @@ |
@@ -21,4 +21,5 @@ /** | ||
var ContentState = require('./ContentState'); | ||
var DraftEntity = require('./DraftEntity'); | ||
var DraftEntityInstance = require('./DraftEntityInstance'); | ||
var addEntityToEntityMap = require('./addEntityToEntityMap'); | ||
var createCharacterList = require('./createCharacterList'); | ||
@@ -29,3 +30,3 @@ var decodeEntityRanges = require('./decodeEntityRanges'); | ||
var Immutable = require('immutable'); | ||
var OrderedMap = Immutable.OrderedMap; | ||
var Map = Immutable.Map; | ||
@@ -35,4 +36,4 @@ | ||
function convertFromRawToDraftState(rawState) { | ||
var blocks = rawState.blocks; | ||
var entityMap = rawState.entityMap; | ||
var blocks = rawState.blocks, | ||
entityMap = rawState.entityMap; | ||
@@ -42,21 +43,27 @@ | ||
// TODO: Update this once we completely remove DraftEntity | ||
Object.keys(entityMap).forEach(function (storageKey) { | ||
var newEntityMap = Object.keys(entityMap).reduce(function (updatedEntityMap, storageKey) { | ||
var encodedEntity = entityMap[storageKey]; | ||
var type = encodedEntity.type; | ||
var mutability = encodedEntity.mutability; | ||
var data = encodedEntity.data; | ||
var type = encodedEntity.type, | ||
mutability = encodedEntity.mutability, | ||
data = encodedEntity.data; | ||
var newKey = DraftEntity.__create(type, mutability, data || {}); | ||
var instance = new DraftEntityInstance({ | ||
type: type, | ||
mutability: mutability, | ||
data: data || {} | ||
}); | ||
var tempEntityMap = addEntityToEntityMap(updatedEntityMap, instance); | ||
var newKey = tempEntityMap.keySeq().last(); | ||
fromStorageToLocal[storageKey] = newKey; | ||
}); | ||
return tempEntityMap; | ||
}, OrderedMap()); | ||
var contentBlocks = blocks.map(function (block) { | ||
var key = block.key; | ||
var type = block.type; | ||
var text = block.text; | ||
var depth = block.depth; | ||
var inlineStyleRanges = block.inlineStyleRanges; | ||
var entityRanges = block.entityRanges; | ||
var data = block.data; | ||
var key = block.key, | ||
type = block.type, | ||
text = block.text, | ||
depth = block.depth, | ||
inlineStyleRanges = block.inlineStyleRanges, | ||
entityRanges = block.entityRanges, | ||
data = block.data; | ||
@@ -85,5 +92,5 @@ key = key || generateRandomKey(); | ||
return ContentState.createFromBlockArray(contentBlocks); | ||
return ContentState.createFromBlockArray(contentBlocks, newEntityMap); | ||
} | ||
module.exports = convertFromRawToDraftState; |
@@ -16,7 +16,7 @@ /** | ||
var _require = require('immutable'), | ||
OrderedSet = _require.OrderedSet; | ||
var UnicodeUtils = require('fbjs/lib/UnicodeUtils'); | ||
var _require = require('immutable'); | ||
var OrderedSet = _require.OrderedSet; | ||
var substr = UnicodeUtils.substr; | ||
@@ -23,0 +23,0 @@ |
@@ -15,6 +15,5 @@ /** | ||
var _require = require('immutable'); | ||
var _require = require('immutable'), | ||
Map = _require.Map; | ||
var Map = _require.Map; | ||
var React = require('react'); | ||
@@ -21,0 +20,0 @@ |
@@ -10,2 +10,3 @@ /** | ||
* @providesModule Draft | ||
* | ||
*/ | ||
@@ -25,3 +26,2 @@ | ||
var DraftEditorBlock = require('./DraftEditorBlock.react'); | ||
var DraftEntity = require('./DraftEntity'); | ||
var DraftModifier = require('./DraftModifier'); | ||
@@ -47,3 +47,2 @@ var DraftEntityInstance = require('./DraftEntityInstance'); | ||
CompositeDecorator: CompositeDraftDecorator, | ||
Entity: DraftEntity, | ||
EntityInstance: DraftEntityInstance, | ||
@@ -50,0 +49,0 @@ |
@@ -34,3 +34,2 @@ /** | ||
var DraftEditorPlaceholder = require('./DraftEditorPlaceholder.react'); | ||
var EditorState = require('./EditorState'); | ||
@@ -47,3 +46,2 @@ var React = require('react'); | ||
var getDefaultKeyBinding = require('./getDefaultKeyBinding'); | ||
var getScrollPosition = require('fbjs/lib/getScrollPosition'); | ||
@@ -89,2 +87,3 @@ var invariant = require('fbjs/lib/invariant'); | ||
_this._latestEditorState = props.editorState; | ||
_this._latestCommittedEditorState = props.editorState; | ||
@@ -172,5 +171,5 @@ _this._onBeforeInput = _this._buildHandler('onBeforeInput'); | ||
DraftEditor.prototype.render = function render() { | ||
var _props = this.props; | ||
var readOnly = _props.readOnly; | ||
var textAlignment = _props.textAlignment; | ||
var _props = this.props, | ||
readOnly = _props.readOnly, | ||
textAlignment = _props.textAlignment; | ||
@@ -208,2 +207,3 @@ var rootClass = cx({ | ||
'aria-label': this.props.ariaLabel, | ||
'aria-multiline': this.props.ariaMultiline, | ||
'aria-owns': readOnly ? null : this.props.ariaOwneeID, | ||
@@ -296,2 +296,3 @@ autoCapitalize: this.props.autoCapitalize, | ||
this._blockSelectEvents = false; | ||
this._latestCommittedEditorState = this.props.editorState; | ||
}; | ||
@@ -320,8 +321,6 @@ | ||
var _ref = scrollPosition || getScrollPosition(scrollParent); | ||
var _ref = scrollPosition || getScrollPosition(scrollParent), | ||
x = _ref.x, | ||
y = _ref.y; | ||
var x = _ref.x; | ||
var y = _ref.y; | ||
!(editorNode instanceof HTMLElement) ? process.env.NODE_ENV !== 'production' ? invariant(false, 'editorNode is not an HTMLElement') : invariant(false) : void 0; | ||
@@ -328,0 +327,0 @@ editorNode.focus(); |
@@ -31,3 +31,2 @@ /** | ||
var Scroll = require('fbjs/lib/Scroll'); | ||
var Style = require('fbjs/lib/Style'); | ||
@@ -180,5 +179,5 @@ var UnicodeBidi = require('fbjs/lib/UnicodeBidi'); | ||
DraftEditorBlock.prototype.render = function render() { | ||
var _props = this.props; | ||
var direction = _props.direction; | ||
var offsetKey = _props.offsetKey; | ||
var _props = this.props, | ||
direction = _props.direction, | ||
offsetKey = _props.offsetKey; | ||
@@ -185,0 +184,0 @@ var className = cx({ |
@@ -91,8 +91,8 @@ /** | ||
DraftEditorContents.prototype.render = function render() { | ||
var _props = this.props; | ||
var blockRenderMap = _props.blockRenderMap; | ||
var blockRendererFn = _props.blockRendererFn; | ||
var customStyleMap = _props.customStyleMap; | ||
var customStyleFn = _props.customStyleFn; | ||
var editorState = _props.editorState; | ||
var _props = this.props, | ||
blockRenderMap = _props.blockRenderMap, | ||
blockRendererFn = _props.blockRendererFn, | ||
customStyleMap = _props.customStyleMap, | ||
customStyleFn = _props.customStyleFn, | ||
editorState = _props.editorState; | ||
@@ -99,0 +99,0 @@ |
@@ -23,6 +23,5 @@ /** | ||
var getUpdatedSelectionState = require('./getUpdatedSelectionState'); | ||
var isEventHandled = require('./isEventHandled'); | ||
var nullthrows = require('fbjs/lib/nullthrows'); | ||
var isEventHandled = require('./isEventHandled'); | ||
/** | ||
@@ -29,0 +28,0 @@ * Get a SelectionState for the supplied mouse event. |
@@ -68,6 +68,6 @@ /** | ||
var _props = this.props; | ||
var block = _props.block; | ||
var start = _props.start; | ||
var text = _props.text; | ||
var _props = this.props, | ||
block = _props.block, | ||
start = _props.start, | ||
text = _props.text; | ||
@@ -128,7 +128,7 @@ var blockKey = block.getKey(); | ||
var _props2 = this.props; | ||
var customStyleMap = _props2.customStyleMap; | ||
var customStyleFn = _props2.customStyleFn; | ||
var offsetKey = _props2.offsetKey; | ||
var styleSet = _props2.styleSet; | ||
var _props2 = this.props, | ||
customStyleMap = _props2.customStyleMap, | ||
customStyleFn = _props2.customStyleFn, | ||
offsetKey = _props2.offsetKey, | ||
styleSet = _props2.styleSet; | ||
@@ -135,0 +135,0 @@ var styleObj = styleSet.reduce(function (map, styleName) { |
@@ -15,7 +15,4 @@ /** | ||
var DraftFeatureFlags = { | ||
draft_killswitch_allow_nontextnodes: false, | ||
draft_segmented_entities_behavior: false | ||
}; | ||
var DraftFeatureFlags = require('./DraftFeatureFlags-core'); | ||
module.exports = DraftFeatureFlags; |
@@ -23,8 +23,7 @@ /** | ||
decode: function decode(offsetKey) { | ||
var _offsetKey$split = offsetKey.split(KEY_DELIMITER); | ||
var _offsetKey$split = offsetKey.split(KEY_DELIMITER), | ||
blockKey = _offsetKey$split[0], | ||
decoratorKey = _offsetKey$split[1], | ||
leafKey = _offsetKey$split[2]; | ||
var blockKey = _offsetKey$split[0]; | ||
var decoratorKey = _offsetKey$split[1]; | ||
var leafKey = _offsetKey$split[2]; | ||
return { | ||
@@ -31,0 +30,0 @@ blockKey: blockKey, |
@@ -25,4 +25,4 @@ /** | ||
var List = Immutable.List; | ||
var Repeat = Immutable.Repeat; | ||
var List = Immutable.List, | ||
Repeat = Immutable.Repeat; | ||
@@ -29,0 +29,0 @@ |
@@ -21,2 +21,3 @@ /** | ||
var getEntityKeyForSelection = require('./getEntityKeyForSelection'); | ||
var isEventHandled = require('./isEventHandled'); | ||
var isSelectionAtLeafStart = require('./isSelectionAtLeafStart'); | ||
@@ -26,4 +27,2 @@ var nullthrows = require('fbjs/lib/nullthrows'); | ||
var isEventHandled = require('./isEventHandled'); | ||
// When nothing is focused, Firefox regards two characters, `'` and `/`, as | ||
@@ -92,2 +91,3 @@ // commands that should open and focus the "quickfind" search bar. This should | ||
var selection = editorState.getSelection(); | ||
var anchorKey = selection.getAnchorKey(); | ||
@@ -100,6 +100,39 @@ if (!selection.isCollapsed()) { | ||
var mayAllowNative = !isSelectionAtLeafStart(editorState); | ||
var newEditorState = replaceText(editorState, chars, editorState.getCurrentInlineStyle(), getEntityKeyForSelection(editorState.getCurrentContent(), editorState.getSelection())); | ||
if (!mayAllowNative) { | ||
// Bunch of different cases follow where we need to prevent native insertion. | ||
var mustPreventNative = false; | ||
if (!mustPreventNative) { | ||
// Browsers tend to insert text in weird places in the DOM when typing at | ||
// the start of a leaf, so we'll handle it ourselves. | ||
mustPreventNative = isSelectionAtLeafStart(editor._latestCommittedEditorState); | ||
} | ||
if (!mustPreventNative) { | ||
// Chrome will also split up a node into two pieces if it contains a Tab | ||
// char, for no explicable reason. Seemingly caused by this commit: | ||
// https://chromium.googlesource.com/chromium/src/+/013ac5eaf3%5E%21/ | ||
var nativeSelection = global.getSelection(); | ||
// Selection is necessarily collapsed at this point due to earlier check. | ||
if (nativeSelection.anchorNode !== null && nativeSelection.anchorNode.nodeType === Node.TEXT_NODE) { | ||
// See isTabHTMLSpanElement in chromium EditingUtilities.cpp. | ||
var parentNode = nativeSelection.anchorNode.parentNode; | ||
mustPreventNative = parentNode.nodeName === 'SPAN' && parentNode.firstChild.nodeType === Node.TEXT_NODE && parentNode.firstChild.nodeValue.indexOf('\t') !== -1; | ||
} | ||
} | ||
if (!mustPreventNative) { | ||
// Check the old and new "fingerprints" of the current block to determine | ||
// whether this insertion requires any addition or removal of text nodes, | ||
// in which case we would prevent the native character insertion. | ||
var originalFingerprint = BlockTree.getFingerprint(editorState.getBlockTree(anchorKey)); | ||
var newFingerprint = BlockTree.getFingerprint(newEditorState.getBlockTree(anchorKey)); | ||
mustPreventNative = originalFingerprint !== newFingerprint; | ||
} | ||
if (!mustPreventNative) { | ||
mustPreventNative = mustPreventDefaultForCharacter(chars); | ||
} | ||
if (!mustPreventNative) { | ||
mustPreventNative = nullthrows(newEditorState.getDirectionMap()).get(anchorKey) !== nullthrows(editorState.getDirectionMap()).get(anchorKey); | ||
} | ||
if (mustPreventNative) { | ||
e.preventDefault(); | ||
@@ -110,32 +143,19 @@ editor.update(newEditorState); | ||
var anchorKey = selection.getAnchorKey(); | ||
var anchorTree = editorState.getBlockTree(anchorKey); | ||
// Check the old and new "fingerprints" of the current block to determine | ||
// whether this insertion requires any addition or removal of text nodes, | ||
// in which case we would prevent the native character insertion. | ||
var originalFingerprint = BlockTree.getFingerprint(anchorTree); | ||
var newFingerprint = BlockTree.getFingerprint(newEditorState.getBlockTree(anchorKey)); | ||
if (mustPreventDefaultForCharacter(chars) || originalFingerprint !== newFingerprint || nullthrows(newEditorState.getDirectionMap()).get(anchorKey) !== nullthrows(editorState.getDirectionMap()).get(anchorKey)) { | ||
e.preventDefault(); | ||
editor.update(newEditorState); | ||
} else { | ||
newEditorState = EditorState.set(newEditorState, { | ||
nativelyRenderedContent: newEditorState.getCurrentContent() | ||
}); | ||
// The native event is allowed to occur. To allow user onChange handlers to | ||
// change the inserted text, we wait until the text is actually inserted | ||
// before we actually update our state. That way when we rerender, the text | ||
// we see in the DOM will already have been inserted properly. | ||
editor._pendingStateFromBeforeInput = newEditorState; | ||
setImmediate(function () { | ||
if (editor._pendingStateFromBeforeInput !== undefined) { | ||
editor.update(editor._pendingStateFromBeforeInput); | ||
editor._pendingStateFromBeforeInput = undefined; | ||
} | ||
}); | ||
} | ||
// We made it all the way! Let the browser do its thing and insert the char. | ||
newEditorState = EditorState.set(newEditorState, { | ||
nativelyRenderedContent: newEditorState.getCurrentContent() | ||
}); | ||
// The native event is allowed to occur. To allow user onChange handlers to | ||
// change the inserted text, we wait until the text is actually inserted | ||
// before we actually update our state. That way when we rerender, the text | ||
// we see in the DOM will already have been inserted properly. | ||
editor._pendingStateFromBeforeInput = newEditorState; | ||
setImmediate(function () { | ||
if (editor._pendingStateFromBeforeInput !== undefined) { | ||
editor.update(editor._pendingStateFromBeforeInput); | ||
editor._pendingStateFromBeforeInput = undefined; | ||
} | ||
}); | ||
} | ||
module.exports = editOnBeforeInput; |
@@ -43,10 +43,9 @@ /** | ||
// after the editor regains control of the DOM. | ||
// $FlowFixMe e.target should be an instanceof Node | ||
var scrollParent = Style.getScrollParent(e.target); | ||
var _getScrollPosition = getScrollPosition(scrollParent); | ||
var _getScrollPosition = getScrollPosition(scrollParent), | ||
x = _getScrollPosition.x, | ||
y = _getScrollPosition.y; | ||
var x = _getScrollPosition.x; | ||
var y = _getScrollPosition.y; | ||
var fragment = getFragmentFromSelection(editorState); | ||
@@ -53,0 +52,0 @@ editor.setClipboard(fragment); |
@@ -15,2 +15,3 @@ /** | ||
var DraftFeatureFlags = require('./DraftFeatureFlags'); | ||
var EditorState = require('./EditorState'); | ||
@@ -34,5 +35,10 @@ | ||
// old cursor position. See https://crbug.com/540004. | ||
editor.update(EditorState.forceSelection(editorState, selection)); | ||
// But it looks like this is fixed in Chrome 60.0.3081.0. | ||
if (DraftFeatureFlags.draft_accept_selection_after_refocus) { | ||
editor.update(EditorState.acceptSelection(editorState, selection)); | ||
} else { | ||
editor.update(EditorState.forceSelection(editorState, selection)); | ||
} | ||
} | ||
module.exports = editOnFocus; |
@@ -48,4 +48,4 @@ /** | ||
var anchorNode = domSelection.anchorNode; | ||
var isCollapsed = domSelection.isCollapsed; | ||
var anchorNode = domSelection.anchorNode, | ||
isCollapsed = domSelection.isCollapsed; | ||
@@ -84,14 +84,11 @@ var isNotTextNode = anchorNode.nodeType !== Node.TEXT_NODE; | ||
var _DraftOffsetKey$decod = DraftOffsetKey.decode(offsetKey); | ||
var _DraftOffsetKey$decod = DraftOffsetKey.decode(offsetKey), | ||
blockKey = _DraftOffsetKey$decod.blockKey, | ||
decoratorKey = _DraftOffsetKey$decod.decoratorKey, | ||
leafKey = _DraftOffsetKey$decod.leafKey; | ||
var blockKey = _DraftOffsetKey$decod.blockKey; | ||
var decoratorKey = _DraftOffsetKey$decod.decoratorKey; | ||
var leafKey = _DraftOffsetKey$decod.leafKey; | ||
var _editorState$getBlock = editorState.getBlockTree(blockKey).getIn([decoratorKey, 'leaves', leafKey]), | ||
start = _editorState$getBlock.start, | ||
end = _editorState$getBlock.end; | ||
var _editorState$getBlock = editorState.getBlockTree(blockKey).getIn([decoratorKey, 'leaves', leafKey]); | ||
var start = _editorState$getBlock.start; | ||
var end = _editorState$getBlock.end; | ||
var content = editorState.getCurrentContent(); | ||
@@ -111,2 +108,6 @@ var block = content.getBlockForKey(blockKey); | ||
if (domText === modelText) { | ||
// This can be buggy for some Android keyboards because they don't fire | ||
// standard onkeydown/pressed events and only fired editOnInput | ||
// so domText is already changed by the browser and ends up being equal | ||
// to modelText unexpectedly | ||
return; | ||
@@ -113,0 +114,0 @@ } |
@@ -22,2 +22,3 @@ /** | ||
var isEventHandled = require('./isEventHandled'); | ||
var keyCommandBackspaceToStartOfLine = require('./keyCommandBackspaceToStartOfLine'); | ||
@@ -27,11 +28,9 @@ var keyCommandBackspaceWord = require('./keyCommandBackspaceWord'); | ||
var keyCommandInsertNewline = require('./keyCommandInsertNewline'); | ||
var keyCommandMoveSelectionToEndOfBlock = require('./keyCommandMoveSelectionToEndOfBlock'); | ||
var keyCommandMoveSelectionToStartOfBlock = require('./keyCommandMoveSelectionToStartOfBlock'); | ||
var keyCommandPlainBackspace = require('./keyCommandPlainBackspace'); | ||
var keyCommandPlainDelete = require('./keyCommandPlainDelete'); | ||
var keyCommandMoveSelectionToEndOfBlock = require('./keyCommandMoveSelectionToEndOfBlock'); | ||
var keyCommandMoveSelectionToStartOfBlock = require('./keyCommandMoveSelectionToStartOfBlock'); | ||
var keyCommandTransposeCharacters = require('./keyCommandTransposeCharacters'); | ||
var keyCommandUndo = require('./keyCommandUndo'); | ||
var isEventHandled = require('./isEventHandled'); | ||
var isOptionKeyCommand = KeyBindingUtil.isOptionKeyCommand; | ||
@@ -38,0 +37,0 @@ |
@@ -116,4 +116,4 @@ /** | ||
if (htmlFragment) { | ||
var contentBlocks = htmlFragment.contentBlocks; | ||
var entityMap = htmlFragment.entityMap; | ||
var contentBlocks = htmlFragment.contentBlocks, | ||
entityMap = htmlFragment.entityMap; | ||
@@ -148,7 +148,6 @@ if (contentBlocks) { | ||
var newContent = DraftModifier.replaceWithFragment(editorState.getCurrentContent(), editorState.getSelection(), fragment); | ||
// TODO: merge the entity map once we stop using DraftEntity | ||
// like this: | ||
// const mergedEntityMap = newContent.getEntityMap().merge(entityMap); | ||
return EditorState.push(editorState, newContent.set('entityMap', entityMap), 'insert-fragment'); | ||
var mergedEntityMap = newContent.getEntityMap().merge(entityMap); | ||
return EditorState.push(editorState, newContent.set('entityMap', mergedEntityMap), 'insert-fragment'); | ||
} | ||
@@ -155,0 +154,0 @@ |
@@ -27,5 +27,5 @@ /** | ||
var OrderedSet = Immutable.OrderedSet; | ||
var Record = Immutable.Record; | ||
var Stack = Immutable.Stack; | ||
var OrderedSet = Immutable.OrderedSet, | ||
Record = Immutable.Record, | ||
Stack = Immutable.Stack; | ||
@@ -68,4 +68,4 @@ | ||
EditorState.create = function create(config) { | ||
var currentContent = config.currentContent; | ||
var decorator = config.decorator; | ||
var currentContent = config.currentContent, | ||
decorator = config.decorator; | ||
@@ -494,3 +494,3 @@ var recordConfig = _extends({}, config, { | ||
return previousTreeMap.merge(blockMap.toSeq().filter(function (block) { | ||
return decorator.getDecorations(block, content) !== existingDecorator.getDecorations(block, content); | ||
return decorator.getDecorations(content, block) !== existingDecorator.getDecorations(content, block); | ||
}).map(function (block) { | ||
@@ -497,0 +497,0 @@ return BlockTree.generate(content, block, decorator); |
@@ -68,3 +68,3 @@ /** | ||
var end = selectionState.getEndOffset(); | ||
var entity = entityMap.__get(entityKey); | ||
var entity = entityMap.get(entityKey); | ||
var mutability = entity.getMutability(); | ||
@@ -71,0 +71,0 @@ var sideToConsider = isEntityAtStart ? start : end; |
@@ -28,4 +28,4 @@ /** | ||
var hasCommandModifier = KeyBindingUtil.hasCommandModifier; | ||
var isCtrlKeyCommand = KeyBindingUtil.isCtrlKeyCommand; | ||
var hasCommandModifier = KeyBindingUtil.hasCommandModifier, | ||
isCtrlKeyCommand = KeyBindingUtil.isCtrlKeyCommand; | ||
@@ -32,0 +32,0 @@ |
@@ -49,3 +49,3 @@ /** | ||
if (entityKey) { | ||
var entity = entityMap.__get(entityKey); | ||
var entity = entityMap.get(entityKey); | ||
return entity.getMutability() === 'MUTABLE' ? entityKey : null; | ||
@@ -52,0 +52,0 @@ } |
@@ -25,4 +25,4 @@ /** | ||
var BOLD = SampleDraftInlineStyle.BOLD; | ||
var ITALIC = SampleDraftInlineStyle.ITALIC; | ||
var BOLD = SampleDraftInlineStyle.BOLD, | ||
ITALIC = SampleDraftInlineStyle.ITALIC; | ||
@@ -29,0 +29,0 @@ var ENTITY_KEY = '123'; |
@@ -15,2 +15,4 @@ /** | ||
var invariant = require('fbjs/lib/invariant'); | ||
var TEXT_CLIPPING_REGEX = /\.textClipping$/; | ||
@@ -68,3 +70,5 @@ | ||
reader.onload = function () { | ||
callback(reader.result); | ||
var result = reader.result; | ||
!(typeof result === 'string') ? process.env.NODE_ENV !== 'production' ? invariant(false, 'We should be calling "FileReader.readAsText" which returns a string') : invariant(false) : void 0; | ||
callback(result); | ||
}; | ||
@@ -71,0 +75,0 @@ reader.onerror = function () { |
@@ -31,6 +31,6 @@ /** | ||
var boundingRect = getRangeBoundingClientRect(range); | ||
var top = boundingRect.top; | ||
var right = boundingRect.right; | ||
var bottom = boundingRect.bottom; | ||
var left = boundingRect.left; | ||
var top = boundingRect.top, | ||
right = boundingRect.right, | ||
bottom = boundingRect.bottom, | ||
left = boundingRect.left; | ||
@@ -37,0 +37,0 @@ // When a re-render leads to a node being removed, the DOM selection will |
@@ -81,9 +81,8 @@ /** | ||
if (entityAfterCursor && entityAfterCursor === entityBeforeCursor) { | ||
var entity = entityMap.__get(entityAfterCursor); | ||
var entity = entityMap.get(entityAfterCursor); | ||
if (entity.getMutability() !== 'MUTABLE') { | ||
var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset); | ||
var _getRemovalRange = getRemovalRange(chars, entityAfterCursor, offset), | ||
start = _getRemovalRange.start, | ||
end = _getRemovalRange.end; | ||
var start = _getRemovalRange.start; | ||
var end = _getRemovalRange.end; | ||
var current; | ||
@@ -90,0 +89,0 @@ while (start < end) { |
@@ -30,3 +30,3 @@ /** | ||
var entity = v.getEntity(); | ||
return !!entity && entityMap.__get(entity).getType() === 'LINK'; | ||
return !!entity && entityMap.get(entity).getType() === 'LINK'; | ||
}); | ||
@@ -277,5 +277,5 @@ }, | ||
/** | ||
* When a collapsed cursor is at the start of an empty styled block, allow | ||
* certain key commands (newline, backspace) to simply change the | ||
* style of the block instead of the default behavior. | ||
* When a collapsed cursor is at the start of an empty styled block, | ||
* changes block to 'unstyled'. Returns null if block or selection does not | ||
* meet that criteria. | ||
*/ | ||
@@ -282,0 +282,0 @@ tryToRemoveBlockStyle: function tryToRemoveBlockStyle(editorState) { |
@@ -15,7 +15,5 @@ /** | ||
var _require = require('immutable'); | ||
var _require = require('immutable'), | ||
OrderedSet = _require.OrderedSet; | ||
var OrderedSet = _require.OrderedSet; | ||
module.exports = { | ||
@@ -22,0 +20,0 @@ BOLD: OrderedSet.of('BOLD'), |
@@ -17,2 +17,3 @@ /** | ||
var DraftJsDebugLogging = require('./DraftJsDebugLogging'); | ||
var containsNode = require('fbjs/lib/containsNode'); | ||
@@ -174,3 +175,16 @@ var getActiveElement = require('fbjs/lib/getActiveElement'); | ||
} | ||
selection.extend(node, offset); | ||
// logging to catch bug that is being reported in t18110632 | ||
try { | ||
selection.extend(node, offset); | ||
} catch (e) { | ||
DraftJsDebugLogging.logSelectionStateFailure({ | ||
anonymizedDom: getAnonymizedEditorDOM(node), | ||
extraParams: JSON.stringify({ offset: offset }), | ||
selectionState: JSON.stringify(selectionState.toJS()) | ||
}); | ||
// allow the error to be thrown - | ||
// better than continuing in a broken state | ||
throw e; | ||
} | ||
} else { | ||
@@ -177,0 +191,0 @@ // IE doesn't support extend. This will mean no backward selection. |
{ | ||
"name": "draft-js", | ||
"description": "A React framework for building text editors.", | ||
"version": "0.10.1", | ||
"version": "0.11.0-alpha", | ||
"keywords": [ | ||
@@ -33,3 +33,3 @@ "draftjs", | ||
"dependencies": { | ||
"fbjs": "^0.8.7", | ||
"fbjs": "^0.8.12", | ||
"immutable": "~3.7.4", | ||
@@ -54,3 +54,3 @@ "object-assign": "^4.1.0" | ||
"eslint-plugin-react": "^5.2.2", | ||
"fbjs-scripts": "^0.7.0", | ||
"fbjs-scripts": "^0.8.0", | ||
"flow-bin": "^0.42.0", | ||
@@ -78,4 +78,4 @@ "gulp": "^3.9.0", | ||
"devEngines": { | ||
"node": "4.x || 6.x", | ||
"npm": "2.x || 3.x" | ||
"node": "4.x || 6.x || 8.x", | ||
"npm": "2.x || 3.x || 5.x" | ||
}, | ||
@@ -82,0 +82,0 @@ "jest": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1299853
20390
37
Updatedfbjs@^0.8.12