angular-weblineindia-ck-editor
Version:
A simple, native and easy-to-use WYSIWYG / Rich Text editor built in AngularJS.
1,365 lines (1,336 loc) • 190 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/common/http'), require('@angular/common'), require('@angular/forms'), require('@angular/platform-browser')) :
typeof define === 'function' && define.amd ? define('@kolkov/angular-editor', ['exports', '@angular/core', '@angular/common/http', '@angular/common', '@angular/forms', '@angular/platform-browser'], factory) :
(global = global || self, factory((global.kolkov = global.kolkov || {}, global.kolkov['angular-editor'] = {}), global.ng.core, global.ng.common.http, global.ng.common, global.ng.forms, global.ng.platformBrowser));
}(this, (function (exports, core, http, common, forms, platformBrowser) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
}
function __classPrivateFieldSet(receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @record
*/
function UploadResponse() { }
if (false) {
/** @type {?} */
UploadResponse.prototype.imageUrl;
}
var AngularEditorService = /** @class */ (function () {
function AngularEditorService(http, doc) {
var _this = this;
this.http = http;
this.doc = doc;
/**
* save selection when the editor is focussed out
*/
this.saveSelection = (/**
* @return {?}
*/
function () {
if (_this.doc.getSelection) {
/** @type {?} */
var sel = _this.doc.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
_this.savedSelection = sel.getRangeAt(0);
_this.selectedText = sel.toString();
}
}
else if (_this.doc.getSelection && _this.doc.createRange) {
_this.savedSelection = document.createRange();
}
else {
_this.savedSelection = null;
}
});
}
/**
* Executed command from editor header buttons exclude toggleEditorMode
* @param command string from triggerCommand
*/
/**
* Executed command from editor header buttons exclude toggleEditorMode
* @param {?} command string from triggerCommand
* @return {?}
*/
AngularEditorService.prototype.executeCommand = /**
* Executed command from editor header buttons exclude toggleEditorMode
* @param {?} command string from triggerCommand
* @return {?}
*/
function (command) {
/** @type {?} */
var commands = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'pre'];
if (commands.includes(command)) {
this.doc.execCommand('formatBlock', false, command);
return;
}
this.doc.execCommand(command, false, null);
};
/**
* Create URL link
* @param url string from UI prompt
*/
/**
* Create URL link
* @param {?} url string from UI prompt
* @return {?}
*/
AngularEditorService.prototype.createLink = /**
* Create URL link
* @param {?} url string from UI prompt
* @return {?}
*/
function (url) {
if (!url.includes('http')) {
this.doc.execCommand('createlink', false, url);
}
else {
/** @type {?} */
var newUrl = '<a href="' + url + '" target="_blank">' + this.selectedText + '</a>';
this.insertHtml(newUrl);
}
};
/**
* insert color either font or background
*
* @param color color to be inserted
* @param where where the color has to be inserted either text/background
*/
/**
* insert color either font or background
*
* @param {?} color color to be inserted
* @param {?} where where the color has to be inserted either text/background
* @return {?}
*/
AngularEditorService.prototype.insertColor = /**
* insert color either font or background
*
* @param {?} color color to be inserted
* @param {?} where where the color has to be inserted either text/background
* @return {?}
*/
function (color, where) {
/** @type {?} */
var restored = this.restoreSelection();
if (restored) {
if (where === 'textColor') {
this.doc.execCommand('foreColor', false, color);
}
else {
this.doc.execCommand('hiliteColor', false, color);
}
}
};
/**
* Set font name
* @param fontName string
*/
/**
* Set font name
* @param {?} fontName string
* @return {?}
*/
AngularEditorService.prototype.setFontName = /**
* Set font name
* @param {?} fontName string
* @return {?}
*/
function (fontName) {
this.doc.execCommand('fontName', false, fontName);
};
/**
* Set font size
* @param fontSize string
*/
/**
* Set font size
* @param {?} fontSize string
* @return {?}
*/
AngularEditorService.prototype.setFontSize = /**
* Set font size
* @param {?} fontSize string
* @return {?}
*/
function (fontSize) {
this.doc.execCommand('fontSize', false, fontSize);
};
/**
* Create raw HTML
* @param html HTML string
*/
/**
* Create raw HTML
* @param {?} html HTML string
* @return {?}
*/
AngularEditorService.prototype.insertHtml = /**
* Create raw HTML
* @param {?} html HTML string
* @return {?}
*/
function (html) {
/** @type {?} */
var isHTMLInserted = this.doc.execCommand('insertHTML', false, html);
if (!isHTMLInserted) {
throw new Error('Unable to perform the operation');
}
};
/**
* restore selection when the editor is focused in
*
* saved selection when the editor is focused out
*/
/**
* restore selection when the editor is focused in
*
* saved selection when the editor is focused out
* @return {?}
*/
AngularEditorService.prototype.restoreSelection = /**
* restore selection when the editor is focused in
*
* saved selection when the editor is focused out
* @return {?}
*/
function () {
if (this.savedSelection) {
if (this.doc.getSelection) {
/** @type {?} */
var sel = this.doc.getSelection();
sel.removeAllRanges();
sel.addRange(this.savedSelection);
return true;
}
else if (this.doc.getSelection /*&& this.savedSelection.select*/) {
// this.savedSelection.select();
return true;
}
}
else {
return false;
}
};
/**
* setTimeout used for execute 'saveSelection' method in next event loop iteration
*/
/**
* setTimeout used for execute 'saveSelection' method in next event loop iteration
* @param {?} callbackFn
* @param {?=} timeout
* @return {?}
*/
AngularEditorService.prototype.executeInNextQueueIteration = /**
* setTimeout used for execute 'saveSelection' method in next event loop iteration
* @param {?} callbackFn
* @param {?=} timeout
* @return {?}
*/
function (callbackFn, timeout) {
if (timeout === void 0) { timeout = 1e2; }
setTimeout(callbackFn, timeout);
};
/** check any selection is made or not */
/**
* check any selection is made or not
* @private
* @return {?}
*/
AngularEditorService.prototype.checkSelection = /**
* check any selection is made or not
* @private
* @return {?}
*/
function () {
/** @type {?} */
var selectedText = this.savedSelection.toString();
if (selectedText.length === 0) {
throw new Error('No Selection Made');
}
return true;
};
/**
* Upload file to uploadUrl
* @param file The file
*/
/**
* Upload file to uploadUrl
* @param {?} file The file
* @return {?}
*/
AngularEditorService.prototype.uploadImage = /**
* Upload file to uploadUrl
* @param {?} file The file
* @return {?}
*/
function (file) {
/** @type {?} */
var uploadData = new FormData();
uploadData.append('file', file, file.name);
return this.http.post(this.uploadUrl, uploadData, {
reportProgress: true,
observe: 'events',
withCredentials: this.uploadWithCredentials,
});
};
/**
* Insert image with Url
* @param imageUrl The imageUrl.
*/
/**
* Insert image with Url
* @param {?} imageUrl The imageUrl.
* @return {?}
*/
AngularEditorService.prototype.insertImage = /**
* Insert image with Url
* @param {?} imageUrl The imageUrl.
* @return {?}
*/
function (imageUrl) {
this.doc.execCommand('insertImage', false, imageUrl);
};
/**
* @param {?} separator
* @return {?}
*/
AngularEditorService.prototype.setDefaultParagraphSeparator = /**
* @param {?} separator
* @return {?}
*/
function (separator) {
this.doc.execCommand('defaultParagraphSeparator', false, separator);
};
/**
* @param {?} customClass
* @return {?}
*/
AngularEditorService.prototype.createCustomClass = /**
* @param {?} customClass
* @return {?}
*/
function (customClass) {
/** @type {?} */
var newTag = this.selectedText;
if (customClass) {
/** @type {?} */
var tagName = customClass.tag ? customClass.tag : 'span';
newTag = '<' + tagName + ' class="' + customClass.class + '">' + this.selectedText + '</' + tagName + '>';
}
this.insertHtml(newTag);
};
/**
* @param {?} videoUrl
* @return {?}
*/
AngularEditorService.prototype.insertVideo = /**
* @param {?} videoUrl
* @return {?}
*/
function (videoUrl) {
if (videoUrl.match('www.youtube.com')) {
this.insertYouTubeVideoTag(videoUrl);
}
if (videoUrl.match('vimeo.com')) {
this.insertVimeoVideoTag(videoUrl);
}
};
/**
* @private
* @param {?} videoUrl
* @return {?}
*/
AngularEditorService.prototype.insertYouTubeVideoTag = /**
* @private
* @param {?} videoUrl
* @return {?}
*/
function (videoUrl) {
/** @type {?} */
var id = videoUrl.split('v=')[1];
/** @type {?} */
var imageUrl = "https://img.youtube.com/vi/" + id + "/0.jpg";
/** @type {?} */
var thumbnail = "\n <div style='position: relative'>\n <img style='position: absolute; left:200px; top:140px'\n src=\"https://img.icons8.com/color/96/000000/youtube-play.png\"/>\n <a href='" + videoUrl + "' target='_blank'>\n <img src=\"" + imageUrl + "\" alt=\"click to watch\"/>\n </a>\n </div>";
this.insertHtml(thumbnail);
};
/**
* @private
* @param {?} videoUrl
* @return {?}
*/
AngularEditorService.prototype.insertVimeoVideoTag = /**
* @private
* @param {?} videoUrl
* @return {?}
*/
function (videoUrl) {
var _this = this;
/** @type {?} */
var sub = this.http.get("https://vimeo.com/api/oembed.json?url=" + videoUrl).subscribe((/**
* @param {?} data
* @return {?}
*/
function (data) {
/** @type {?} */
var imageUrl = data.thumbnail_url_with_play_button;
/** @type {?} */
var thumbnail = "<div>\n <a href='" + videoUrl + "' target='_blank'>\n <img src=\"" + imageUrl + "\" alt=\"" + data.title + "\"/>\n </a>\n </div>";
_this.insertHtml(thumbnail);
sub.unsubscribe();
}));
};
/**
* @param {?} node
* @return {?}
*/
AngularEditorService.prototype.nextNode = /**
* @param {?} node
* @return {?}
*/
function (node) {
if (node.hasChildNodes()) {
return node.firstChild;
}
else {
while (node && !node.nextSibling) {
node = node.parentNode;
}
if (!node) {
return null;
}
return node.nextSibling;
}
};
/**
* @param {?} range
* @param {?} includePartiallySelectedContainers
* @return {?}
*/
AngularEditorService.prototype.getRangeSelectedNodes = /**
* @param {?} range
* @param {?} includePartiallySelectedContainers
* @return {?}
*/
function (range, includePartiallySelectedContainers) {
/** @type {?} */
var node = range.startContainer;
/** @type {?} */
var endNode = range.endContainer;
/** @type {?} */
var rangeNodes = [];
// Special case for a range that is contained within a single node
if (node === endNode) {
rangeNodes = [node];
}
else {
// Iterate nodes until we hit the end container
while (node && node !== endNode) {
rangeNodes.push(node = this.nextNode(node));
}
// Add partially selected nodes at the start of the range
node = range.startContainer;
while (node && node !== range.commonAncestorContainer) {
rangeNodes.unshift(node);
node = node.parentNode;
}
}
// Add ancestors of the range container, if required
if (includePartiallySelectedContainers) {
node = range.commonAncestorContainer;
while (node) {
rangeNodes.push(node);
node = node.parentNode;
}
}
return rangeNodes;
};
/**
* @return {?}
*/
AngularEditorService.prototype.getSelectedNodes = /**
* @return {?}
*/
function () {
/** @type {?} */
var nodes = [];
if (this.doc.getSelection) {
/** @type {?} */
var sel = this.doc.getSelection();
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
nodes.push.apply(nodes, this.getRangeSelectedNodes(sel.getRangeAt(i), true));
}
}
return nodes;
};
/**
* @param {?} el
* @return {?}
*/
AngularEditorService.prototype.replaceWithOwnChildren = /**
* @param {?} el
* @return {?}
*/
function (el) {
/** @type {?} */
var parent = el.parentNode;
while (el.hasChildNodes()) {
parent.insertBefore(el.firstChild, el);
}
parent.removeChild(el);
};
/**
* @param {?} tagNames
* @return {?}
*/
AngularEditorService.prototype.removeSelectedElements = /**
* @param {?} tagNames
* @return {?}
*/
function (tagNames) {
var _this = this;
/** @type {?} */
var tagNamesArray = tagNames.toLowerCase().split(',');
this.getSelectedNodes().forEach((/**
* @param {?} node
* @return {?}
*/
function (node) {
if (node.nodeType === 1 &&
tagNamesArray.indexOf(node.tagName.toLowerCase()) > -1) {
// Remove the node and replace it with its children
_this.replaceWithOwnChildren(node);
}
}));
};
AngularEditorService.decorators = [
{ type: core.Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
AngularEditorService.ctorParameters = function () { return [
{ type: http.HttpClient },
{ type: undefined, decorators: [{ type: core.Inject, args: [common.DOCUMENT,] }] }
]; };
/** @nocollapse */ AngularEditorService.ngInjectableDef = core.ɵɵdefineInjectable({ factory: function AngularEditorService_Factory() { return new AngularEditorService(core.ɵɵinject(http.HttpClient), core.ɵɵinject(common.DOCUMENT)); }, token: AngularEditorService, providedIn: "root" });
return AngularEditorService;
}());
if (false) {
/** @type {?} */
AngularEditorService.prototype.savedSelection;
/** @type {?} */
AngularEditorService.prototype.selectedText;
/** @type {?} */
AngularEditorService.prototype.uploadUrl;
/** @type {?} */
AngularEditorService.prototype.uploadWithCredentials;
/**
* save selection when the editor is focussed out
* @type {?}
*/
AngularEditorService.prototype.saveSelection;
/**
* @type {?}
* @private
*/
AngularEditorService.prototype.http;
/**
* @type {?}
* @private
*/
AngularEditorService.prototype.doc;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @record
*/
function CustomClass() { }
if (false) {
/** @type {?} */
CustomClass.prototype.name;
/** @type {?} */
CustomClass.prototype.class;
/** @type {?|undefined} */
CustomClass.prototype.tag;
}
/**
* @record
*/
function Font() { }
if (false) {
/** @type {?} */
Font.prototype.name;
/** @type {?} */
Font.prototype.class;
}
/**
* @record
*/
function AngularEditorConfig() { }
if (false) {
/** @type {?|undefined} */
AngularEditorConfig.prototype.editable;
/** @type {?|undefined} */
AngularEditorConfig.prototype.spellcheck;
/** @type {?|undefined} */
AngularEditorConfig.prototype.height;
/** @type {?|undefined} */
AngularEditorConfig.prototype.minHeight;
/** @type {?|undefined} */
AngularEditorConfig.prototype.maxHeight;
/** @type {?|undefined} */
AngularEditorConfig.prototype.width;
/** @type {?|undefined} */
AngularEditorConfig.prototype.minWidth;
/** @type {?|undefined} */
AngularEditorConfig.prototype.translate;
/** @type {?|undefined} */
AngularEditorConfig.prototype.enableToolbar;
/** @type {?|undefined} */
AngularEditorConfig.prototype.showToolbar;
/** @type {?|undefined} */
AngularEditorConfig.prototype.placeholder;
/** @type {?|undefined} */
AngularEditorConfig.prototype.defaultParagraphSeparator;
/** @type {?|undefined} */
AngularEditorConfig.prototype.defaultFontName;
/** @type {?|undefined} */
AngularEditorConfig.prototype.defaultFontSize;
/** @type {?|undefined} */
AngularEditorConfig.prototype.uploadUrl;
/** @type {?|undefined} */
AngularEditorConfig.prototype.uploadWithCredentials;
/** @type {?|undefined} */
AngularEditorConfig.prototype.fonts;
/** @type {?|undefined} */
AngularEditorConfig.prototype.customClasses;
/** @type {?|undefined} */
AngularEditorConfig.prototype.sanitize;
/** @type {?|undefined} */
AngularEditorConfig.prototype.toolbarPosition;
/** @type {?|undefined} */
AngularEditorConfig.prototype.outline;
/** @type {?|undefined} */
AngularEditorConfig.prototype.toolbarHiddenButtons;
}
/** @type {?} */
var angularEditorConfig = {
editable: true,
spellcheck: true,
height: 'auto',
minHeight: '0',
maxHeight: 'auto',
width: 'auto',
minWidth: '0',
translate: 'yes',
enableToolbar: true,
showToolbar: true,
placeholder: 'Enter text here...',
defaultParagraphSeparator: '',
defaultFontName: '',
defaultFontSize: '',
fonts: [
{ class: 'arial', name: 'Arial' },
{ class: 'times-new-roman', name: 'Times New Roman' },
{ class: 'calibri', name: 'Calibri' },
{ class: 'comic-sans-ms', name: 'Comic Sans MS' }
],
uploadUrl: 'v1/image',
uploadWithCredentials: false,
sanitize: true,
toolbarPosition: 'top',
outline: true,
};
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var AngularEditorToolbarComponent = /** @class */ (function () {
function AngularEditorToolbarComponent(r, editorService, doc) {
this.r = r;
this.editorService = editorService;
this.doc = doc;
this.htmlMode = false;
this.linkSelected = false;
this.block = 'default';
this.fontName = 'Times New Roman';
this.fontSize = '3';
this.headings = [
{
label: 'Heading 1',
value: 'h1',
},
{
label: 'Heading 2',
value: 'h2',
},
{
label: 'Heading 3',
value: 'h3',
},
{
label: 'Heading 4',
value: 'h4',
},
{
label: 'Heading 5',
value: 'h5',
},
{
label: 'Heading 6',
value: 'h6',
},
{
label: 'Heading 7',
value: 'h7',
},
{
label: 'Paragraph',
value: 'p',
},
{
label: 'Predefined',
value: 'pre'
},
{
label: 'Standard',
value: 'div'
},
{
label: 'default',
value: 'default'
}
];
this.fontSizes = [
{
label: '1',
value: '1',
},
{
label: '2',
value: '2',
},
{
label: '3',
value: '3',
},
{
label: '4',
value: '4',
},
{
label: '5',
value: '5',
},
{
label: '6',
value: '6',
},
{
label: '7',
value: '7',
}
];
this.customClassId = '-1';
this.customClassList = [{ label: '', value: '' }];
// uploadUrl: string;
this.tagMap = {
BLOCKQUOTE: 'indent',
A: 'link'
};
this.select = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'P', 'PRE', 'DIV'];
this.buttons = ['bold', 'italic', 'underline', 'strikeThrough', 'subscript', 'superscript', 'justifyLeft', 'justifyCenter',
'justifyRight', 'justifyFull', 'indent', 'outdent', 'insertUnorderedList', 'insertOrderedList', 'link'];
this.fonts = [{ label: '', value: '' }];
this.execute = new core.EventEmitter();
}
Object.defineProperty(AngularEditorToolbarComponent.prototype, "customClasses", {
set: /**
* @param {?} classes
* @return {?}
*/
function (classes) {
if (classes) {
this._customClasses = classes;
this.customClassList = this._customClasses.map((/**
* @param {?} x
* @param {?} i
* @return {?}
*/
function (x, i) { return ({ label: x.name, value: i.toString() }); }));
this.customClassList.unshift({ label: 'Clear Class', value: '-1' });
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(AngularEditorToolbarComponent.prototype, "defaultFontName", {
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
if (value) {
this.fontName = value;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(AngularEditorToolbarComponent.prototype, "defaultFontSize", {
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
if (value) {
this.fontSize = value;
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(AngularEditorToolbarComponent.prototype, "isLinkButtonDisabled", {
get: /**
* @return {?}
*/
function () {
return this.htmlMode || !Boolean(this.editorService.selectedText);
},
enumerable: true,
configurable: true
});
/**
* Trigger command from editor header buttons
* @param command string from toolbar buttons
*/
/**
* Trigger command from editor header buttons
* @param {?} command string from toolbar buttons
* @return {?}
*/
AngularEditorToolbarComponent.prototype.triggerCommand = /**
* Trigger command from editor header buttons
* @param {?} command string from toolbar buttons
* @return {?}
*/
function (command) {
this.execute.emit(command);
};
/**
* highlight editor buttons when cursor moved or positioning
*/
/**
* highlight editor buttons when cursor moved or positioning
* @return {?}
*/
AngularEditorToolbarComponent.prototype.triggerButtons = /**
* highlight editor buttons when cursor moved or positioning
* @return {?}
*/
function () {
var _this = this;
if (!this.showToolbar) {
return;
}
this.buttons.forEach((/**
* @param {?} e
* @return {?}
*/
function (e) {
/** @type {?} */
var result = _this.doc.queryCommandState(e);
/** @type {?} */
var elementById = _this.doc.getElementById(e + '-' + _this.id);
if (result) {
_this.r.addClass(elementById, 'active');
}
else {
_this.r.removeClass(elementById, 'active');
}
}));
};
/**
* trigger highlight editor buttons when cursor moved or positioning in block
*/
/**
* trigger highlight editor buttons when cursor moved or positioning in block
* @param {?} nodes
* @return {?}
*/
AngularEditorToolbarComponent.prototype.triggerBlocks = /**
* trigger highlight editor buttons when cursor moved or positioning in block
* @param {?} nodes
* @return {?}
*/
function (nodes) {
var _this = this;
if (!this.showToolbar) {
return;
}
this.linkSelected = nodes.findIndex((/**
* @param {?} x
* @return {?}
*/
function (x) { return x.nodeName === 'A'; })) > -1;
/** @type {?} */
var found = false;
this.select.forEach((/**
* @param {?} y
* @return {?}
*/
function (y) {
/** @type {?} */
var node = nodes.find((/**
* @param {?} x
* @return {?}
*/
function (x) { return x.nodeName === y; }));
if (node !== undefined && y === node.nodeName) {
if (found === false) {
_this.block = node.nodeName.toLowerCase();
found = true;
}
}
else if (found === false) {
_this.block = 'default';
}
}));
found = false;
if (this._customClasses) {
this._customClasses.forEach((/**
* @param {?} y
* @param {?} index
* @return {?}
*/
function (y, index) {
/** @type {?} */
var node = nodes.find((/**
* @param {?} x
* @return {?}
*/
function (x) {
if (x instanceof Element) {
return x.className === y.class;
}
}));
if (node !== undefined) {
if (found === false) {
_this.customClassId = index.toString();
found = true;
}
}
else if (found === false) {
_this.customClassId = '-1';
}
}));
}
Object.keys(this.tagMap).map((/**
* @param {?} e
* @return {?}
*/
function (e) {
/** @type {?} */
var elementById = _this.doc.getElementById(_this.tagMap[e] + '-' + _this.id);
/** @type {?} */
var node = nodes.find((/**
* @param {?} x
* @return {?}
*/
function (x) { return x.nodeName === e; }));
if (node !== undefined && e === node.nodeName) {
_this.r.addClass(elementById, 'active');
}
else {
_this.r.removeClass(elementById, 'active');
}
}));
this.foreColour = this.doc.queryCommandValue('ForeColor');
this.fontSize = this.doc.queryCommandValue('FontSize');
this.fontName = this.doc.queryCommandValue('FontName').replace(/"/g, '');
this.backColor = this.doc.queryCommandValue('backColor');
};
/**
* insert URL link
*/
/**
* insert URL link
* @return {?}
*/
AngularEditorToolbarComponent.prototype.insertUrl = /**
* insert URL link
* @return {?}
*/
function () {
/** @type {?} */
var url = 'https:\/\/';
/** @type {?} */
var selection = this.editorService.savedSelection;
if (selection && selection.commonAncestorContainer.parentElement.nodeName === 'A') {
/** @type {?} */
var parent_1 = (/** @type {?} */ (selection.commonAncestorContainer.parentElement));
if (parent_1.href !== '') {
url = parent_1.href;
}
}
url = prompt('Insert URL link', url);
if (url && url !== '' && url !== 'https://') {
this.editorService.createLink(url);
}
};
/**
* insert Video link
*/
/**
* insert Video link
* @return {?}
*/
AngularEditorToolbarComponent.prototype.insertVideo = /**
* insert Video link
* @return {?}
*/
function () {
this.execute.emit('');
/** @type {?} */
var url = prompt('Insert Video link', "https://");
if (url && url !== '' && url !== "https://") {
this.editorService.insertVideo(url);
}
};
/** insert color */
/**
* insert color
* @param {?} color
* @param {?} where
* @return {?}
*/
AngularEditorToolbarComponent.prototype.insertColor = /**
* insert color
* @param {?} color
* @param {?} where
* @return {?}
*/
function (color, where) {
this.editorService.insertColor(color, where);
this.execute.emit('');
};
/**
* set font Name/family
* @param foreColor string
*/
/**
* set font Name/family
* @param {?} foreColor string
* @return {?}
*/
AngularEditorToolbarComponent.prototype.setFontName = /**
* set font Name/family
* @param {?} foreColor string
* @return {?}
*/
function (foreColor) {
this.editorService.setFontName(foreColor);
this.execute.emit('');
};
/**
* set font Size
* @param fontSize string
*/
/**
* set font Size
* @param {?} fontSize string
* @return {?}
*/
AngularEditorToolbarComponent.prototype.setFontSize = /**
* set font Size
* @param {?} fontSize string
* @return {?}
*/
function (fontSize) {
this.editorService.setFontSize(fontSize);
this.execute.emit('');
};
/**
* toggle editor mode (WYSIWYG or SOURCE)
* @param m boolean
*/
/**
* toggle editor mode (WYSIWYG or SOURCE)
* @param {?} m boolean
* @return {?}
*/
AngularEditorToolbarComponent.prototype.setEditorMode = /**
* toggle editor mode (WYSIWYG or SOURCE)
* @param {?} m boolean
* @return {?}
*/
function (m) {
/** @type {?} */
var toggleEditorModeButton = this.doc.getElementById('toggleEditorMode' + '-' + this.id);
if (m) {
this.r.addClass(toggleEditorModeButton, 'active');
}
else {
this.r.removeClass(toggleEditorModeButton, 'active');
}
this.htmlMode = m;
};
/**
* Upload image when file is selected
*/
/**
* Upload image when file is selected
* @param {?} event
* @return {?}
*/
AngularEditorToolbarComponent.prototype.onFileChanged = /**
* Upload image when file is selected
* @param {?} event
* @return {?}
*/
function (event) {
var _this = this;
/** @type {?} */
var file = event.target.files[0];
if (file.type.includes('image/')) {
if (this.uploadUrl) {
this.editorService.uploadImage(file).subscribe((/**
* @param {?} e
* @return {?}
*/
function (e) {
if (e instanceof http.HttpResponse) {
_this.editorService.insertImage(e.body.imageUrl);
_this.fileReset();
}
}));
}
else {
/** @type {?} */
var reader = new FileReader();
reader.onload = (/**
* @param {?} e
* @return {?}
*/
function (e) {
/** @type {?} */
var fr = (/** @type {?} */ (e.currentTarget));
_this.editorService.insertImage(fr.result.toString());
});
reader.readAsDataURL(file);
}
}
};
/**
* Reset Input
*/
/**
* Reset Input
* @return {?}
*/
AngularEditorToolbarComponent.prototype.fileReset = /**
* Reset Input
* @return {?}
*/
function () {
this.myInputFile.nativeElement.value = '';
};
/**
* Set custom class
*/
/**
* Set custom class
* @param