draftmirror
Advanced tools
Comparing version 0.5.3 to 0.6.0
@@ -0,1 +1,3 @@ | ||
var clearDecorator = require('./clearDecorator'); | ||
/** | ||
@@ -10,24 +12,4 @@ * Apply a decorator to annotate text in an editor | ||
function applyDecorator(decorator, editor, blockNode, blockOffset) { | ||
var blockEndOffset = blockOffset + blockNode.nodeSize; | ||
clearDecorator(decorator, editor, blockNode, blockOffset); | ||
// Remove all range in this block | ||
// hack using private apis! | ||
var toRemove = []; | ||
editor.ranges.ranges.forEach(function(range) { | ||
if (range.options.decorator !== decorator.id) { | ||
return; | ||
} | ||
if ((range.from >= blockOffset && range.from <= blockEndOffset) | ||
|| (range.to >= blockOffset && range.to <= blockEndOffset)) { | ||
toRemove.push(range); | ||
} | ||
}); | ||
for (var i = 0; i < toRemove.length; i++) { | ||
editor.removeRange(toRemove[i]); | ||
} | ||
editor.ranges.sorted.resort(); | ||
blockNode.forEach(function(node, offset, index) { | ||
@@ -34,0 +16,0 @@ if (!node.isText) { |
@@ -35,4 +35,4 @@ | ||
var posToSignalOffset = (posB.atNodeBoundary && (changedB !== (maxB - 1)))? (changedB + 1) : posB.pos; | ||
var posToSignal = b.resolve(posToSignalOffset); | ||
var posToSignal = (posB.atNodeBoundary && changedB === (maxB - 2)) ? b.resolve(changedB + 1) : posB; | ||
var posToSignalOffset = posToSignal.pos; | ||
@@ -43,3 +43,4 @@ var posToSignalParent = posToSignalOffset - posToSignal.parentOffset; | ||
// Signal change | ||
fn(posToSignal.parent, offsetToSignal); | ||
if (offsetToSignal >= 0) fn(posToSignal.parent, offsetToSignal); | ||
else console.warn('invalid offset during compare of prosemirror nodes'); | ||
@@ -46,0 +47,0 @@ // Resolve position in old content to keep moving |
@@ -11,2 +11,3 @@ var React = require('react'); | ||
var compareNodes = require('./decorators/compareNodes'); | ||
var clearDecoratorInDoc = require('./decorators/clearDecoratorInDoc'); | ||
@@ -47,6 +48,6 @@ var TooltipUtils = require('./tooltips'); | ||
.merge({ | ||
doc: this.editor.doc, | ||
selection: this.editor.selection, | ||
doc: this.editor.doc, | ||
selection: this.editor.selection, | ||
activeMarks: this.editor.activeMarks(), | ||
transforms: Immutable.List() | ||
transforms: Immutable.List() | ||
}) | ||
@@ -56,5 +57,7 @@ .setHistory(this.editor.history); | ||
// Use applyDecorators on block that changed | ||
compareNodes(editorState.getDoc(), newEditorState.getDoc(), function(node, offset) { | ||
applyDecorators(that.props.decorators, that.editor, node, offset); | ||
}); | ||
if (that.props.decorators.length > 0) { | ||
compareNodes(editorState.getDoc(), newEditorState.getDoc(), function(node, offset) { | ||
applyDecorators(that.props.decorators, that.editor, node, offset); | ||
}); | ||
} | ||
@@ -74,6 +77,38 @@ if (!Immutable.is(editorState, newEditorState)) { | ||
/** | ||
* Update decorators | ||
*/ | ||
updateDecorators: function(newProps, forceUpdate) { | ||
var editor = this.editor; | ||
var oldDecorators = Immutable.List(this.props.decorators); | ||
var newDecorators = Immutable.List(newProps.decorators); | ||
if (!forceUpdate && Immutable.is(oldDecorators, newDecorators)) { | ||
return; | ||
} | ||
// Clear old decorators | ||
oldDecorators.forEach(function(decorator) { | ||
var exists = newDecorators.find(function(newDecorator) { | ||
return newDecorator.id === decorator.id; | ||
}); | ||
if (exists) { | ||
return; | ||
} | ||
clearDecoratorInDoc(decorator, editor); | ||
}); | ||
// Apply new ones | ||
applyDecoratorsToDoc(newDecorators, editor); | ||
}, | ||
/** | ||
* Update keymaps | ||
*/ | ||
updateKeymaps: function(newProps, forceUpdate) { | ||
if (!forceUpdate && Immutable.is(newProps.keymaps, this.props.keymaps)) { | ||
var oldKeymaps = Immutable.List(this.props.keymaps); | ||
var newKeymaps = Immutable.List(newProps.keymaps); | ||
if (!forceUpdate && Immutable.is(oldKeymaps, newKeymaps)) { | ||
return; | ||
@@ -83,3 +118,3 @@ } | ||
// Unbind old ones | ||
Immutable.List(this.props.keymaps) | ||
oldKeymaps | ||
.forEach(function(keymap) { | ||
@@ -90,3 +125,3 @@ keymap.unbindToEditor(this.editor); | ||
// Bind new ones | ||
Immutable.List(newProps.keymaps) | ||
newKeymaps | ||
.forEach(function(keymap) { | ||
@@ -101,3 +136,6 @@ keymap.bindToEditor(this.editor); | ||
updateInputRules: function(newProps, forceUpdate) { | ||
if (!forceUpdate && Immutable.is(newProps.inputRules, this.props.inputRules)) { | ||
var oldInputRules = Immutable.List(this.props.inputRules); | ||
var newInputRules = Immutable.List(newProps.inputRules); | ||
if (!forceUpdate && Immutable.is(oldInputRules, newInputRules)) { | ||
return; | ||
@@ -108,3 +146,3 @@ } | ||
Immutable.List(this.props.inputRules) | ||
oldInputRules | ||
.forEach(function(rule) { | ||
@@ -114,3 +152,3 @@ inputRules.removeRule(rule); | ||
Immutable.List(newProps.inputRules) | ||
newInputRules | ||
.forEach(function(rule) { | ||
@@ -143,6 +181,5 @@ inputRules.addRule(rule); | ||
applyDecoratorsToDoc(this.props.decorators, this.editor); | ||
this.updateKeymaps(newProps, true); | ||
this.updateInputRules(newProps, true); | ||
this.updateDecorators(newProps, true); | ||
}, | ||
@@ -176,2 +213,3 @@ | ||
this.updateInputRules(newProps); | ||
this.updateDecorators(newProps); | ||
@@ -178,0 +216,0 @@ // New instance of editorState, recreate the editor |
{ | ||
"name": "draftmirror", | ||
"version": "0.5.3", | ||
"version": "0.6.0", | ||
"description": "React component for ProseMirror providing a Draft.js like API", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
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
94875
37
2487