Merge branch 'master' of github.com:codex-team/codex.editor

This commit is contained in:
Murod Khaydarov 2018-10-16 18:19:30 +03:00
commit 5188933ee3
No known key found for this signature in database
GPG key ID: C480BA53A8D274C5
4 changed files with 32 additions and 16 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "codex.editor",
"version": "2.1.2",
"version": "2.1.3",
"description": "Codex Editor. Native JS, based on API and Open Source",
"main": "build/codex-editor.js",
"scripts": {

View file

@ -91,6 +91,11 @@ export default class Paste extends Module {
*/
private toolsTags: {[tag: string]: ITagSubstitute} = {};
/**
* Store tags to substitute by tool name
*/
private tagsByTool: {[tools: string]: string[]} = {};
/** Patterns` substitutions parameters */
private toolsPatterns: IPatternSubstitute[] = [];
@ -242,6 +247,8 @@ export default class Paste extends Module {
tool: name,
};
});
this.tagsByTool[name] = tags.map((t) => t.toUpperCase());
}
/**
@ -687,23 +694,32 @@ export default class Paste extends Module {
case Node.ELEMENT_NODE:
const element = node as HTMLElement;
const {tool = ''} = this.toolsTags[element.tagName] || {};
const toolTags = this.tagsByTool[tool] || [];
const isSubstitutable = tags.includes(element.tagName);
const isBlockElement = $.blockElements.includes(element.tagName.toLowerCase());
const containsAnotherToolTags = Array
.from(element.children)
.some(
({tagName}) => tags.includes(tagName) && !toolTags.includes(tagName),
);
const containsBlockElements = Array.from(element.children).some(
({tagName}) => $.blockElements.includes(tagName.toLowerCase()),
);
/** Append inline elements to previous fragment */
if (
!$.blockElements.includes(element.tagName.toLowerCase()) &&
!tags.includes(element.tagName)
) {
if (!isBlockElement && !isSubstitutable) {
destNode.appendChild(element);
return [...nodes, destNode];
}
if (tags.includes(element.tagName) || (
$.blockElements.includes(element.tagName.toLowerCase()) &&
Array.from(element.children).every(
({tagName}) => !$.blockElements.includes(tagName.toLowerCase()),
)
)
if (
(isSubstitutable && !containsAnotherToolTags) ||
(isBlockElement && !containsBlockElements && !containsAnotherToolTags )
) {
return [...nodes, element];
return [...nodes, destNode, element];
}
break;