mirror of
https://github.com/tabler/tabler.git
synced 2026-08-17 00:23:46 +04:00
Release 1.0.0-beta13
This commit is contained in:
+97
-101
@@ -1,11 +1,11 @@
|
||||
/**
|
||||
* TinyMCE version 6.1.2 (2022-07-29)
|
||||
* TinyMCE version 6.2.0 (2022-09-08)
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var global = tinymce.util.Tools.resolve('tinymce.PluginManager');
|
||||
var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
|
||||
|
||||
const link = () => /(?:[A-Za-z][A-Za-z\d.+-]{0,14}:\/\/(?:[-.~*+=!&;:'%@?^${}(),\w]+@)?|www\.|[-;:&=+$,.\w]+@)[A-Za-z\d-]+(?:\.[A-Za-z\d-]+)*(?::\d+)?(?:\/(?:[-.~*+=!;:'%@$(),\/\w]*[-~*+=%@$()\/\w])?)?(?:\?(?:[-.~*+=!&;:'%@?^${}(),\/\w]+))?(?:#(?:[-.~*+=!&;:'%@?^${}(),\/\w]+))?/g;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
const getAutoLinkPattern = option('autolink_pattern');
|
||||
const getDefaultLinkTarget = option('link_default_target');
|
||||
const getDefaultLinkProtocol = option('link_default_protocol');
|
||||
const allowUnsafeLinkTarget = option('allow_unsafe_link_target');
|
||||
|
||||
const hasProto = (v, constructor, predicate) => {
|
||||
var _a;
|
||||
@@ -47,123 +48,113 @@
|
||||
}
|
||||
};
|
||||
const isType = type => value => typeOf(value) === type;
|
||||
const eq = t => a => t === a;
|
||||
const isString = isType('string');
|
||||
const isUndefined = eq(undefined);
|
||||
const isNullable = a => a === null || a === undefined;
|
||||
const isNonNullable = a => !isNullable(a);
|
||||
|
||||
const not = f => t => !f(t);
|
||||
|
||||
const hasOwnProperty = Object.hasOwnProperty;
|
||||
const has = (obj, key) => hasOwnProperty.call(obj, key);
|
||||
|
||||
const checkRange = (str, substr, start) => substr === '' || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
|
||||
const contains = (str, substr) => {
|
||||
return str.indexOf(substr) !== -1;
|
||||
const contains = (str, substr, start = 0, end) => {
|
||||
const idx = str.indexOf(substr, start);
|
||||
if (idx !== -1) {
|
||||
return isUndefined(end) ? true : idx + substr.length <= end;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
const startsWith = (str, prefix) => {
|
||||
return checkRange(str, prefix, 0);
|
||||
};
|
||||
|
||||
const rangeEqualsBracketOrSpace = rangeString => /^[(\[{ \u00a0]$/.test(rangeString);
|
||||
const zeroWidth = '\uFEFF';
|
||||
const isZwsp = char => char === zeroWidth;
|
||||
const removeZwsp = s => s.replace(/\uFEFF/g, '');
|
||||
|
||||
var global = tinymce.util.Tools.resolve('tinymce.dom.TextSeeker');
|
||||
|
||||
const isTextNode = node => node.nodeType === 3;
|
||||
const isElement = node => node.nodeType === 1;
|
||||
const scopeIndex = (container, index) => {
|
||||
if (index < 0) {
|
||||
index = 0;
|
||||
}
|
||||
if (isTextNode(container)) {
|
||||
const len = container.data.length;
|
||||
if (index > len) {
|
||||
index = len;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
};
|
||||
const setStart = (rng, container, offset) => {
|
||||
if (!isElement(container) || container.hasChildNodes()) {
|
||||
rng.setStart(container, scopeIndex(container, offset));
|
||||
} else {
|
||||
rng.setStartBefore(container);
|
||||
}
|
||||
};
|
||||
const setEnd = (rng, container, offset) => {
|
||||
if (!isElement(container) || container.hasChildNodes()) {
|
||||
rng.setEnd(container, scopeIndex(container, offset));
|
||||
} else {
|
||||
rng.setEndAfter(container);
|
||||
}
|
||||
};
|
||||
const isBracketOrSpace = char => /^[(\[{ \u00a0]$/.test(char);
|
||||
const hasProtocol = url => /^([A-Za-z][A-Za-z\d.+-]*:\/\/)|mailto:/.test(url);
|
||||
const isPunctuation = char => /[?!,.;:]/.test(char);
|
||||
const parseCurrentLine = (editor, endOffset) => {
|
||||
let end, endContainer, text, prev, len, rngText;
|
||||
const findChar = (text, index, predicate) => {
|
||||
for (let i = index - 1; i >= 0; i--) {
|
||||
const char = text.charAt(i);
|
||||
if (!isZwsp(char) && predicate(char)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
const freefallRtl = (container, offset) => {
|
||||
let tempNode = container;
|
||||
let tempOffset = offset;
|
||||
while (isElement(tempNode) && tempNode.childNodes[tempOffset]) {
|
||||
tempNode = tempNode.childNodes[tempOffset];
|
||||
tempOffset = isTextNode(tempNode) ? tempNode.data.length : tempNode.childNodes.length;
|
||||
}
|
||||
return {
|
||||
container: tempNode,
|
||||
offset: tempOffset
|
||||
};
|
||||
};
|
||||
|
||||
const parseCurrentLine = (editor, offset) => {
|
||||
var _a;
|
||||
const voidElements = editor.schema.getVoidElements();
|
||||
const autoLinkPattern = getAutoLinkPattern(editor);
|
||||
if (editor.dom.getParent(editor.selection.getNode(), 'a[href]') !== null) {
|
||||
return;
|
||||
const {dom, selection} = editor;
|
||||
if (dom.getParent(selection.getNode(), 'a[href]') !== null) {
|
||||
return null;
|
||||
}
|
||||
const rng = editor.selection.getRng().cloneRange();
|
||||
if (rng.startOffset < 5) {
|
||||
prev = rng.endContainer.previousSibling;
|
||||
if (!prev) {
|
||||
if (!rng.endContainer.firstChild || !rng.endContainer.firstChild.nextSibling) {
|
||||
return;
|
||||
}
|
||||
prev = rng.endContainer.firstChild.nextSibling;
|
||||
}
|
||||
len = prev.length;
|
||||
setStart(rng, prev, len);
|
||||
setEnd(rng, prev, len);
|
||||
if (rng.endOffset < 5) {
|
||||
return;
|
||||
}
|
||||
end = rng.endOffset;
|
||||
endContainer = prev;
|
||||
const rng = selection.getRng();
|
||||
const textSeeker = global(dom, node => {
|
||||
return dom.isBlock(node) || has(voidElements, node.nodeName.toLowerCase()) || dom.getContentEditable(node) === 'false';
|
||||
});
|
||||
const {
|
||||
container: endContainer,
|
||||
offset: endOffset
|
||||
} = freefallRtl(rng.endContainer, rng.endOffset);
|
||||
const root = (_a = dom.getParent(endContainer, dom.isBlock)) !== null && _a !== void 0 ? _a : dom.getRoot();
|
||||
const endSpot = textSeeker.backwards(endContainer, endOffset + offset, (node, offset) => {
|
||||
const text = node.data;
|
||||
const idx = findChar(text, offset, not(isBracketOrSpace));
|
||||
return idx === -1 || isPunctuation(text[idx]) ? idx : idx + 1;
|
||||
}, root);
|
||||
if (!endSpot) {
|
||||
return null;
|
||||
}
|
||||
let lastTextNode = endSpot.container;
|
||||
const startSpot = textSeeker.backwards(endSpot.container, endSpot.offset, (node, offset) => {
|
||||
lastTextNode = node;
|
||||
const idx = findChar(node.data, offset, isBracketOrSpace);
|
||||
return idx === -1 ? idx : idx + 1;
|
||||
}, root);
|
||||
const newRng = dom.createRng();
|
||||
if (!startSpot) {
|
||||
newRng.setStart(lastTextNode, 0);
|
||||
} else {
|
||||
endContainer = rng.endContainer;
|
||||
if (!isTextNode(endContainer) && endContainer.firstChild) {
|
||||
while (!isTextNode(endContainer) && endContainer.firstChild) {
|
||||
endContainer = endContainer.firstChild;
|
||||
}
|
||||
if (isTextNode(endContainer)) {
|
||||
setStart(rng, endContainer, 0);
|
||||
setEnd(rng, endContainer, endContainer.nodeValue.length);
|
||||
}
|
||||
}
|
||||
if (rng.endOffset === 1) {
|
||||
end = 2;
|
||||
} else {
|
||||
end = rng.endOffset - 1 - endOffset;
|
||||
}
|
||||
newRng.setStart(startSpot.container, startSpot.offset);
|
||||
}
|
||||
const start = end;
|
||||
do {
|
||||
setStart(rng, endContainer, end >= 2 ? end - 2 : 0);
|
||||
setEnd(rng, endContainer, end >= 1 ? end - 1 : 0);
|
||||
end -= 1;
|
||||
rngText = rng.toString();
|
||||
} while (!rangeEqualsBracketOrSpace(rngText) && end - 2 >= 0);
|
||||
if (rangeEqualsBracketOrSpace(rng.toString())) {
|
||||
setStart(rng, endContainer, end);
|
||||
setEnd(rng, endContainer, start);
|
||||
end += 1;
|
||||
} else if (rng.startOffset === 0) {
|
||||
setStart(rng, endContainer, 0);
|
||||
setEnd(rng, endContainer, start);
|
||||
} else {
|
||||
setStart(rng, endContainer, end);
|
||||
setEnd(rng, endContainer, start);
|
||||
}
|
||||
text = rng.toString();
|
||||
if (isPunctuation(text.charAt(text.length - 1))) {
|
||||
setEnd(rng, endContainer, start - 1);
|
||||
}
|
||||
text = rng.toString().trim();
|
||||
const matches = text.match(autoLinkPattern);
|
||||
const protocol = getDefaultLinkProtocol(editor);
|
||||
newRng.setEnd(endSpot.container, endSpot.offset);
|
||||
const rngText = removeZwsp(newRng.toString());
|
||||
const matches = rngText.match(autoLinkPattern);
|
||||
if (matches) {
|
||||
let url = matches[0];
|
||||
if (startsWith(url, 'www.')) {
|
||||
const protocol = getDefaultLinkProtocol(editor);
|
||||
url = protocol + '://' + url;
|
||||
} else if (contains(url, '@') && !hasProtocol(url)) {
|
||||
url = 'mailto:' + url;
|
||||
}
|
||||
return {
|
||||
rng,
|
||||
rng: newRng,
|
||||
url
|
||||
};
|
||||
} else {
|
||||
@@ -171,10 +162,10 @@
|
||||
}
|
||||
};
|
||||
const convertToLink = (editor, result) => {
|
||||
const defaultLinkTarget = getDefaultLinkTarget(editor);
|
||||
const {dom, selection} = editor;
|
||||
const {rng, url} = result;
|
||||
const bookmark = editor.selection.getBookmark();
|
||||
editor.selection.setRng(rng);
|
||||
const bookmark = selection.getBookmark();
|
||||
selection.setRng(rng);
|
||||
const command = 'createlink';
|
||||
const args = {
|
||||
command,
|
||||
@@ -185,22 +176,27 @@
|
||||
if (!beforeExecEvent.isDefaultPrevented()) {
|
||||
editor.getDoc().execCommand(command, false, url);
|
||||
editor.dispatch('ExecCommand', args);
|
||||
const defaultLinkTarget = getDefaultLinkTarget(editor);
|
||||
if (isString(defaultLinkTarget)) {
|
||||
editor.dom.setAttrib(editor.selection.getNode(), 'target', defaultLinkTarget);
|
||||
const anchor = selection.getNode();
|
||||
dom.setAttrib(anchor, 'target', defaultLinkTarget);
|
||||
if (defaultLinkTarget === '_blank' && !allowUnsafeLinkTarget(editor)) {
|
||||
dom.setAttrib(anchor, 'rel', 'noopener');
|
||||
}
|
||||
}
|
||||
}
|
||||
editor.selection.moveToBookmark(bookmark);
|
||||
selection.moveToBookmark(bookmark);
|
||||
editor.nodeChanged();
|
||||
};
|
||||
const handleSpacebar = editor => {
|
||||
const result = parseCurrentLine(editor, 0);
|
||||
const result = parseCurrentLine(editor, -1);
|
||||
if (isNonNullable(result)) {
|
||||
convertToLink(editor, result);
|
||||
}
|
||||
};
|
||||
const handleBracket = handleSpacebar;
|
||||
const handleEnter = editor => {
|
||||
const result = parseCurrentLine(editor, -1);
|
||||
const result = parseCurrentLine(editor, 0);
|
||||
if (isNonNullable(result)) {
|
||||
convertToLink(editor, result);
|
||||
}
|
||||
@@ -221,7 +217,7 @@
|
||||
};
|
||||
|
||||
var Plugin = () => {
|
||||
global.add('autolink', editor => {
|
||||
global$1.add('autolink', editor => {
|
||||
register(editor);
|
||||
setup(editor);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user