suneditor
Advanced tools
Comparing version 2.2.7 to 2.3.0
{ | ||
"name": "suneditor", | ||
"version": "2.2.7", | ||
"version": "2.3.0", | ||
"description": "Pure JavaScript based WYSIWYG web editor", | ||
@@ -5,0 +5,0 @@ "main": "src/suneditor.js", |
@@ -6,3 +6,3 @@ { | ||
], | ||
"version": "2.2.7", | ||
"version": "2.3.0", | ||
"description": "Pure JavaScript based WYSIWYG web editor", | ||
@@ -9,0 +9,0 @@ "main": "src/suneditor.js", |
@@ -11,4 +11,4 @@ # Suneditor | ||
[](https://www.npmjs.com/package/suneditor) | ||
[](https://github.com/JiHong88/SunEditor/stargazers) | ||
[](https://david-dm.org/jihong88/suneditor?type=dev) | ||
 | ||
 | ||
@@ -15,0 +15,0 @@ |
@@ -50,3 +50,4 @@ /* | ||
tag_h: 'Header', | ||
tag_quote: 'Quote' | ||
tag_quote: 'Quote', | ||
pre: 'Code' | ||
}, | ||
@@ -53,0 +54,0 @@ dialogBox: { |
@@ -43,3 +43,4 @@ export default { | ||
tag_h: '제목', | ||
tag_quote: '인용문' | ||
tag_quote: '인용문', | ||
pre: '코드' | ||
}, | ||
@@ -46,0 +47,0 @@ dialogBox: { |
@@ -142,3 +142,3 @@ 'use strict'; | ||
/** | ||
* @description It is judged whether it is the range format element. (blockquote, TABLE, TR, TD, OL, UL) | ||
* @description It is judged whether it is the range format element. (blockquote, TABLE, TR, TD, OL, UL, PRE) | ||
* * Range format element is wrap the format element (P, DIV, H1-6, LI) | ||
@@ -149,3 +149,3 @@ * @param {Element} element - The element to check | ||
isRangeFormatElement: function (element) { | ||
if (element && element.nodeType === 1 && /^BLOCKQUOTE|TABLE|TD|TR|OL|UL$/i.test(element.nodeName)) return true; | ||
if (element && element.nodeType === 1 && /^(?:BLOCKQUOTE|TABLE|TBODY|THEAD|TFOOT|TR|TD|OL|UL|PRE)$/i.test(element.nodeName)) return true; | ||
return false; | ||
@@ -155,4 +155,3 @@ }, | ||
/** | ||
* @description Get format element of the argument value (P, DIV, H[1-6]) | ||
* Or a tag whose parent tag is the editing area. (table, blockquote) | ||
* @description Get format element of the argument value (P, DIV, H[1-6], LI) | ||
* @param {Element} element - Reference element if null or no value, it is relative to the current focus node. | ||
@@ -164,3 +163,7 @@ * @returns {Element} | ||
if (this.isWysiwygDiv(element)) { | ||
while (!this.isFormatElement(element) && !this.isWysiwygDiv(element.parentNode)) { | ||
element = element.parentNode; | ||
} | ||
if (this.isWysiwygDiv(element) || this.isRangeFormatElement(element)) { | ||
const firstFormatElement = this.getListChildren(element, function (current) { | ||
@@ -173,7 +176,18 @@ return this.isFormatElement(current); | ||
while (!this.isFormatElement(element) && !this.isWysiwygDiv(element.parentNode)) { | ||
return element; | ||
}, | ||
/** | ||
* @description Get range format element of the argument value (blockquote, TABLE, TR, TD, OL, UL, PRE) | ||
* @param {Element} element - Reference element if null or no value, it is relative to the current focus node. | ||
* @returns {Element|null} | ||
*/ | ||
getRangeFormatElement: function (element) { | ||
if (!element) return null; | ||
while (!this.isRangeFormatElement(element) && !this.isWysiwygDiv(element)) { | ||
element = element.parentNode; | ||
} | ||
return element; | ||
return this.isWysiwygDiv(element) ? null : element; | ||
}, | ||
@@ -420,2 +434,19 @@ | ||
} | ||
}, | ||
/** | ||
* @description Delete a empty child node of argument element | ||
* @param {Element} element - Element node | ||
*/ | ||
removeEmptyNode: function (element) { | ||
(function recursionFunc(current) { | ||
if ((current.textContent.trim().length === 0 || current.textContent === '') && !/^BR$/i.test(current.nodeName)) { | ||
current.parentNode.removeChild(current); | ||
} else { | ||
for (let i = 0, len = current.children.length; i < len; i++) { | ||
if (!current.children[i]) break; | ||
recursionFunc(current.children[i]); | ||
} | ||
} | ||
})(element); | ||
} | ||
@@ -422,0 +453,0 @@ }; |
@@ -40,2 +40,6 @@ /* | ||
' </li>' + | ||
' <li><button type="button" class="btn_edit" data-command="range" data-value="PRE" title="' + lang.toolbar.pre + '">' + | ||
' <pre style="font-size:13px; padding:8px; background-color:#f6f8fa; border:1px solid #dce5e5; border-radius:3px;">' + lang.toolbar.pre + '</pre>' + | ||
' </button>' + | ||
' </li>' + | ||
' <li><button type="button" class="btn_edit" data-command="replace" data-value="H1" title="' + lang.toolbar.tag_h + ' 1" style="height:40px;"><h1>' + lang.toolbar.tag_h + ' 1</h1></button></li>' + | ||
@@ -68,8 +72,8 @@ ' <li><button type="button" class="btn_edit" data-command="replace" data-value="H2" title="' + lang.toolbar.tag_h + ' 2" style="height:34px;"><h2>' + lang.toolbar.tag_h + ' 2</h2></button></li>' + | ||
// blockquote | ||
// blockquote, pre | ||
if (command === 'range') { | ||
const oQuote = document.createElement(value); | ||
this.wrapToTags(oQuote); | ||
this.setRange(oQuote.firstChild, 0, oQuote.firstChild, 0); | ||
this.appendP(oQuote); | ||
const rangeElement = document.createElement(value); | ||
this.wrapToTags(rangeElement); | ||
this.setRange(rangeElement.firstChild, 0, rangeElement.firstChild, 0); | ||
this.appendP(rangeElement); | ||
} | ||
@@ -76,0 +80,0 @@ // others |
@@ -66,7 +66,21 @@ import { format } from "path"; | ||
} else { | ||
const rightNode = formatElement.nextSibling; | ||
let rightNode = formatElement.nextSibling; | ||
let pNode = formatElement.parentNode; | ||
const list = document.createElement(value); | ||
list.innerHTML = '<li>' + formatElement.innerHTML + '</li>'; | ||
this.util.removeItem(formatElement); | ||
this.insertNode(list, rightNode); | ||
const formatElementList = this.getSelectedFormatElements(); | ||
for (let i = 0, len = formatElementList.length, fTag = null; i < len; i++) { | ||
fTag = formatElementList[i]; | ||
if (i === len - 1) { | ||
rightNode = fTag.nextSibling; | ||
pNode = fTag.parentNode; | ||
} | ||
list.innerHTML += '<li>' + fTag.innerHTML + '</li>'; | ||
this.util.removeItem(fTag); | ||
} | ||
pNode.insertBefore(list, rightNode); | ||
} | ||
@@ -73,0 +87,0 @@ |
@@ -214,3 +214,3 @@ /* | ||
resizeDiv.style.left = offset.left + 'px'; | ||
resizeDiv.style.top = (offset.top + tdElement.offsetHeight + 10) + 'px'; | ||
resizeDiv.style.top = (offset.top + tdElement.offsetHeight + 12) + 'px'; | ||
}, | ||
@@ -217,0 +217,0 @@ |
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 too big to display
2676786
36910