a.hyperscala-contenteditor_2.11.0.10.3.source-code.contenteditor.js Maven / Gradle / Ivy
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= 37) && e.shiftKey) { // (Alt-)Shift-arrow
setTimeout(dispatchIfChanged.bind(null, this), 0);
}
}
function onMouseDown(e) {
if (e.button === 0) {
on(this, 'mousemove', onMouseMove);
setTimeout(dispatchIfChanged.bind(null, this), 0);
}
}
function onMouseMove(e) { // only needed while primary button is down
if (e.buttons & 1) {
dispatchIfChanged(this);
} else {
off(this, 'mousemove', onMouseMove);
}
}
function onMouseUp(e) {
if (e.button === 0) {
setTimeout(dispatchIfChanged.bind(null, this), 0);
} else {
off(this, 'mousemove', onMouseMove);
}
}
function onFocus() {
setTimeout(dispatchIfChanged.bind(null, this.document), 0);
}
function dispatchIfChanged(doc) {
var rOld = ranges.get(doc);
var rNew = getSelectionRange(doc);
if (!sameRange(rNew, rOld)) {
ranges.set(doc, rNew);
setTimeout(doc.dispatchEvent.bind(doc, new Event('selectionchange')), 0);
}
}
function sameRange(r1, r2) {
return r1 === r2 || r1 && r2 && RANGE_PROPS.every(function (prop) {
return r1[prop] === r2[prop];
});
}
})();
},{}],3:[function(require,module,exports){
module.exports = {
createClassWrapper: createClassWrapper,
createHtmlWrapper: createHtmlWrapper
}
/**
* Creates ClassWrapper object with specified options
* @param {String} className Class name for ClassWrapper.
* @param {Object/String} options Either options object for ClassWrapper or CSS style string.
* @returns {Boolean} ClassWrapper object with adjustable properties, rangy ClassApplier reference and apply/undo/toggle methods.
*/
function createClassWrapper(className, options) {
var rangyClassApplier = rangy.createClassApplier(className, {applyToEditableOnly: true}),
classWrapper = {},
_context = {},
_scope;
classWrapper.rangy = rangyClassApplier;
rangyClassApplier.elementProperties.style = {};
Object.defineProperties(classWrapper, {
className: {
get: function() {return rangyClassApplier.className},
set: function(className) {
rangyClassApplier.className = className;
rangyClassApplier.cssClass = className;
rangyClassApplier.elementSortedClassName = className;
}
},
tagName: {
get: function() {return rangyClassApplier.elementTagName;},
set: function(tagName) {
tagName = tagName.toLowerCase();
rangyClassApplier.elementTagName = tagName;
rangyClassApplier.tagNames = [tagName];
}
},
style: {
get: function() {return rangyClassApplier.elementProperties.style;},
set: function(style) {
if (style.color && style.color[0] === "#") {
var cssDeclaration = document.createElement("style").style
cssDeclaration.color = style.color;
style.color = cssDeclaration.color;
console.log(cssDeclaration, cssDeclaration.color)
}
rangyClassApplier.elementProperties.style = style;
}
},
properties: {
get: function() {return rangyClassApplier.elementProperties;},
set: function(properties) {
rangyClassApplier.attrExceptions = [];
for (var prop in properties) {
rangyClassApplier.elementProperties[prop] = properties[prop];
rangyClassApplier.attrExceptions.push(prop);
}
}
},
normalize: {
get: function() {return rangyClassApplier.normalize;},
set: function(normalize) {rangyClassApplier.normalize = normalize;}
},
context: {
get: function() {return _context;},
set: function(context) {
for (var prop in context) {
_context[prop] = context[prop];
}
}
}
});
Object.defineProperties(_context, {
editableOnly: {
get: function() {return rangyClassApplier.applyToEditableOnly;},
set: function (editableOnly) {
rangyClassApplier.applyToEditableOnly = editableOnly;
}
},
scope: {
get: function () {return _scope;},
set: function (scope) {
if (typeof scope === "string") {
scope = document.querySelectorAll(scope);
}
_scope = Array.prototype.slice.call(scope);
}
},
tagNames: {
get: function () {return rangyClassApplier.tagNames},
set: function (tagNames) {
if (typeof tagNames === "string") {
if (tagNames === "*") {
rangyClassApplier.applyToAnyTagName = true;
} else {
tagNames = tagNames.replace(/\s+/g,"").split(",");
}
} else if (!Array.isArray(tagNames)) {
tagNames = [tagNames]
}
rangyClassApplier.tagNames = tagNames;
}
}
});
function checkScope(nodeList, range) {
for (var i = 0, nodeRange = rangy.createRange(); i < nodeList.length; i++) {
nodeRange.selectNodeContents(nodeList[i]);
if (nodeRange.containsRange(range)) return true;
}
return false;
}
function dispatchStyleChange(range, classWrapper) {
range.commonAncestorContainer.dispatchEvent(new CustomEvent('stylechange', {
bubbles : true,
detail: {range: range, classWrapper: classWrapper}
}));
}
classWrapper.apply = function(range, rangesToPreserve) {
if (range) {
if (Array.isArray(range)) {
range.forEach(function(rn) {
rn.refresh();
if (!_scope || checkScope(_scope, rn)) {
classWrapper.rangy.applyToRange(rn, range);
dispatchStyleChange(rn, this);
}
});
} else {
if (!_scope || checkScope(_scope, range)) {
classWrapper.rangy.applyToRange(range, rangesToPreserve);
dispatchStyleChange(range, this);
}
}
} else {
range = rangy.getSelection().getRangeAt(0);
if (!_scope || checkScope(_scope, range)) {
var className = this.className,
styles = this.style,
nodes, startNode, selection;
if (this.tagName.toLowerCase() === "a") document.execCommand("unlink");
classWrapper.rangy.applyToSelection();
selection = rangy.getSelection();
range = selection.getRangeAt(0);
nodes = range.getNodes([1], function(node) {return node.className === className});
if (nodes[0]) {
if (nodes.length > 1) {
if (selection.isBackwards()) {
startNode = nodes[nodes.length - 1];
for (var style in styles) { // check for style consistency
if (startNode.style[style] !== styles[style]) {
startNode = nodes[nodes.length - 2];
break;
}
}
} else {
startNode = nodes[0];
for (var style in styles) { // check for style consistency
if (startNode.style[style] !== styles[style]) {
startNode = nodes[1];
break;
}
}
}
range.setStart(startNode.childNodes[0]);
} else {
range.setStart(nodes[0].childNodes[0]);
}
selection.setSingleRange(range);
}
dispatchStyleChange(range, this);
}
}
}
classWrapper.undo = function(range, rangesToPreserve) {
if (range) {
if (Array.isArray(range)) {
range.forEach(function(rn) {
rn.refresh();
if (!_scope || checkScope(_scope, rn)) {
classWrapper.rangy.undoToRange(rn, range);
dispatchStyleChange(rn, this);
}
});
} else {
if (!_scope || checkScope(_scope, range)) {
classWrapper.rangy.undoToRange(range, rangesToPreserve);
dispatchStyleChange(range, this);
}
}
} else {
var selection = rangy.getSelection();
if ((!_scope || checkScope(_scope, range)) && selection.rangeCount) {
range = selection.getRangeAt(0);
this.tagName.toLowerCase() === "a" ? document.execCommand("unlink") : classWrapper.rangy.undoToSelection();
dispatchStyleChange(range, this);
}
}
}
classWrapper.toggle = function(range) {
if (range) {
if (Array.isArray(range)) {
range.forEach(function(rn) {
rn.refresh();
if (!_scope || checkScope(_scope, rn)) {
classWrapper.rangy.toggleRange(rn, range);
rn.commonAncestorContainer.dispatchEvent(new CustomEvent('style', { 'detail': {range: rn, classWrapper: this} }));
}
});
} else {
if (!_scope || checkScope(_scope, range)) {
classWrapper.rangy.toggleRange(range);
dispatchStyleChange(range, this);
}
}
} else {
range = rangy.getSelection().getRangeAt(0);
if (!_scope || checkScope(_scope, rangy.getSelection().getRangeAt(0))) {
var className = this.className,
styles = this.style,
nodes, startNode, selection;
if (this.rangy.isAppliedToSelection()) {
this.tagName.toLowerCase() === "a" ? document.execCommand("unlink") : classWrapper.rangy.undoToSelection();
} else {
classWrapper.rangy.applyToSelection();
selection = rangy.getSelection();
range = selection.getRangeAt(0);
nodes = range.getNodes([1], function(node) {return node.className === className});
if (nodes[0]) {
if (nodes.length > 1) {
if (selection.isBackwards()) {
startNode = nodes[nodes.length - 1];
for (var style in styles) { // check for style consistency
if (startNode.style[style] !== styles[style]) {
startNode = nodes[nodes.length - 2];
break;
}
}
} else {
startNode = nodes[0];
for (var style in styles) { // check for style consistency
if (startNode.style[style] !== styles[style]) {
startNode = nodes[1];
break;
}
}
}
range.setStart(startNode.childNodes[0]);
} else {
range.setStart(nodes[0].childNodes[0]);
}
selection.setSingleRange(range);
}
}
dispatchStyleChange(range, this);
}
}
}
if (options) {
if (typeof options === "string") {
classWrapper.style.cssText = options
} else {
for (var key in options) {
classWrapper[key] = options[key];
}
}
}
return classWrapper;
}
/**
* Creates HrmlWrapper object with specified options
* @param {String/Object} tagName Tag name that HtmlWrapper will use in insert, wrap and edit methods when creating and editing HtmlElements. Alternatively you can supply DOM fragment that be used instead creating new one.
* @param {Object/String} properties Either options object for ClassWrapper or src/href string (if tagName is "a" or "img").
* @param {String} title Title string (if tagName is either "a" or "img").
* @returns {Object} HtmlWrapper object with adjustable properties and insert/wrap/edit/clear methods.
*/
function createHtmlWrapper(tagName, properties, title) {
if (typeof properties === "string") {
if (tagName.toLowerCase() === "a") {
properties = {href: properties};
} else if (tagName.toLowerCase() === "img") {
properties = {src: properties};
}
if (title) properties.title = title;
}
return new HtmlWrapper(tagName, properties);
}
function HtmlWrapper(tagName, properties) {
if (typeof tagName === "object") {
this.predefined = tagName;
} else {
this.tagName = tagName;
this.properties = properties || {};
}
}
HtmlWrapper.prototype = {
insert: function(properties, range) {
var range = range || rangy.getSelection().getRangeAt(0),
selection = rangy.getSelection().getRangeAt(0),
newElements = [],
newElement;
if (this.predefined) {
newElement = this.predefined.nodeType === 11 ? this.predefined : this.predefined.cloneNode();
} else {
newElement = document.createElement(this.tagName);
}
if (properties) {
if (typeof properties === "string") {
if (this.tagName.toLowerCase() === "a") {
properties = {href: properties};
} else if (this.tagName.toLowerCase() === "img") {
properties = {src: properties};
}
}
}
for (var prop in this.properties) {
if (prop === "style") {
for (var styleProp in this.properties.style) {
newElement.style[styleProp] = this.properties.style[styleProp];
}
} else {
newElement[prop] = this.properties[prop];
}
}
for (var newProp in properties) {
if (prop === "style") {
for (var newStyleProp in properties.style) {
newElement.style[newStyleProp] = properties.style[newStyleProp];
}
} else {
newElement[newProp] = properties[newProp];
}
}
if (Array.isArray(range)) {
range.forEach(function(rn) {
var clonedElement = newElement.cloneNode()
rn.deleteContents();
rn.insertNode(clonedElement);
newElements.push(clonedElement);
});
return newElements;
} else {
range.deleteContents();
range.insertNode(newElement);
rangy.getSelection().setSingleRange(selection);
return newElement;
}
},
wrap: function(properties, range) {
var range = range || rangy.getSelection().getRangeAt(0),
newElements = [],
newElement;
if (this.predefined) {
if (this.predefined.nodeType === 11) return false;
newElement = this.predefined.cloneNode();
} else {
newElement = document.createElement(this.tagName);
}
if (properties) {
if (typeof properties === "string") {
if (this.tagName.toLowerCase() === "a") {
properties = {href: properties};
}
}
}
for (var prop in this.properties) {
if (prop === "style") {
for (var styleProp in this.properties.style) {
newElement.style[styleProp] = this.properties.style[styleProp];
}
} else {
newElement[prop] = this.properties[prop];
}
}
for (var newProp in properties) {
if (prop === "style") {
for (var newStyleProp in properties.style) {
newElement.style[newStyleProp] = properties.style[newStyleProp];
}
} else {
newElement[newProp] = properties[newProp];
}
}
if (Array.isArray(range)) {
range.forEach(function(rn) {
var clonedElement = newElement.cloneNode()
rn.surroundContents(clonedElement);
newElements.push(clonedElement);
});
return newElements;
} else {
if (!this.predefined && this.tagName.toLowerCase() === "a") {
document.execCommand("unlink");
range = rangy.getSelection().getRangeAt(0);
}
range.surroundContents(newElement);
rangy.getSelection().setSingleRange(range);
return newElement;
}
},
edit: function(properties, range) {
var range = range || rangy.getSelection().getRangeAt(0),
node;
if (Array.isArray(range)) {
range.forEach(function(rn) {
node = rn.startContainer;
if (node.tagName.toLowerCase() === this.tagName.toLowerCase()) {
if (typeof properties === "string") {
if (this.tagName.toLowerCase() === "a") {
node.href = properties;
} else if (this.tagName.toLowerCase() === "img") {
node.src = properties;
}
} else {
for (var prop in properties) {
if (prop === "style") {
for (var styleProp in properties.style) {
node.style[styleProp] = properties.style[styleProp];
}
} else {
node[prop] = properties[prop];
}
}
}
}
});
} else {
node = range.startContainer;
if (node.tagName.toLowerCase() === this.tagName.toLowerCase()) {
if (typeof properties === "string") {
if (this.tagName.toLowerCase() === "a") {
node.href = properties;
} else if (this.tagName.toLowerCase() === "img") {
node.src = properties;
}
} else {
for (var prop in properties) {
if (prop === "style") {
for (var styleProp in properties.style) {
node.style[styleProp] = properties.style[styleProp];
}
} else {
node[prop] = properties[prop];
}
}
}
}
}
},
clear: function() {
if (this.tagName.toLowerCase() === "a") document.execCommand("unlink"); // Clear is supported only by anchors
}
}
},{}]},{},[1]);
© 2015 - 2025 Weber Informatics LLC | Privacy Policy