1102 lines
38 KiB
JavaScript
1102 lines
38 KiB
JavaScript
import * as i0 from '@angular/core';
|
|
import { InjectionToken, EventEmitter, Component, Optional, Inject, Input, Output, Pipe, NgModule } from '@angular/core';
|
|
import suneditor from 'suneditor';
|
|
import * as i1$1 from '@angular/common';
|
|
import { CommonModule } from '@angular/common';
|
|
import * as i1 from '@angular/platform-browser';
|
|
|
|
/**
|
|
* Injection token for options object
|
|
*/
|
|
const SUNEDITOR_OPTIONS = new InjectionToken('SUNEDITOR_OPTIONS');
|
|
|
|
class NgxSuneditorComponent {
|
|
/**
|
|
* Content to show in the Editor. If this value is set the content will be set.
|
|
*/
|
|
set content(content) {
|
|
this._content = content;
|
|
if (this.editor) {
|
|
this.setContents(this._content);
|
|
}
|
|
}
|
|
/**
|
|
* Callback to replace the default imageUploadHandler function
|
|
*/
|
|
set imageUploadHandler(callback) {
|
|
const handlerCallback = (xmlHttp, info, core) => {
|
|
callback(xmlHttp, info, core);
|
|
};
|
|
this._imageUploadHandler = handlerCallback;
|
|
if (this.editor)
|
|
this.editor.imageUploadHandler = handlerCallback;
|
|
}
|
|
/**
|
|
* Callback to replace the default videoUploadHandler function
|
|
*/
|
|
set videoUploadHandler(callback) {
|
|
const handlerCallback = (xmlHttp, info, core) => {
|
|
callback(xmlHttp, info, core);
|
|
};
|
|
this._videoUploadHandler = handlerCallback;
|
|
if (this.editor)
|
|
this.editor.videoUploadHandler = handlerCallback;
|
|
}
|
|
/**
|
|
* Callback to replace the default audioUploadHandler function
|
|
*/
|
|
set audioUploadHandler(callback) {
|
|
const handlerCallback = (xmlHttp, info, core) => {
|
|
callback(xmlHttp, info, core);
|
|
};
|
|
this._audioUploadHandler = handlerCallback;
|
|
if (this.editor)
|
|
this.editor.audioUploadHandler = handlerCallback;
|
|
}
|
|
/**
|
|
* The localStorageConfig Object {id: string, autoSave: boolean, autoLoad: boolean}
|
|
* id is the localStorageKey where the Content gets saved.
|
|
* autoSave decides if the content should be automaticly saved in the onChange event
|
|
* autoLoad decides if the content should be automaticly loaded on startUp
|
|
* @Default = {id: 'ngxSunEditor', autoSave: false, autoLoad: false}
|
|
*/
|
|
set localStorageConfig(config) {
|
|
if (config.id) {
|
|
this.localStorageId = config.id;
|
|
}
|
|
if (config.autoSave !== undefined && config.autoSave !== null) {
|
|
this.isAutoSaveToLocalStorage = config.autoSave;
|
|
}
|
|
if (config.autoLoad !== undefined && config.autoLoad !== null) {
|
|
this.isAutoLoadToLocalStorage = config.autoLoad;
|
|
}
|
|
}
|
|
constructor(ngZone, options) {
|
|
this.ngZone = ngZone;
|
|
// the localStorageKey where the Content gets saved
|
|
this.localStorageId = 'ngxSunEditor';
|
|
// decides if autoSave to Local Storage is Activated.
|
|
this.isAutoSaveToLocalStorage = false;
|
|
// decides if the content should be loaded from teh LocalStorage on start
|
|
this.isAutoLoadToLocalStorage = false;
|
|
// disabled state of the SunEditor
|
|
this._disabled = false;
|
|
// hidden state of the SunEditor
|
|
this._hidden = false;
|
|
// loading state of the SunEditor
|
|
this._loading = false;
|
|
// readonly state of the SunEditor
|
|
this._readonly = false;
|
|
// Fullscreen mode state of SunEditor
|
|
this._fullScreenMode = false;
|
|
// DisplayBlocks state of SunEditor
|
|
this._displayBlocks = false;
|
|
// CodeView state of SunEditor
|
|
this._codeView = false;
|
|
/**
|
|
* HTML DOM id PropertyHTML DOM id Property
|
|
*/
|
|
this.editorID = this.generateID();
|
|
/**
|
|
* Parameter that is passed to the onDrop event to control the behavior.
|
|
* @default true
|
|
*/
|
|
this.onDrop_param = true;
|
|
/**
|
|
* Parameter that is passed to the onCopy event to control the behavior.
|
|
* @default true
|
|
*/
|
|
this.onCopy_param = true;
|
|
/**
|
|
* Parameter that is passed to the onCut event to control the behavior.
|
|
* @default true
|
|
*/
|
|
this.onCut_param = true;
|
|
/**
|
|
* Parameter that is passed to the onAudioUploadError event to control the behavior.
|
|
* @default true
|
|
*/
|
|
this.onAudioUploadError_param = true;
|
|
/**
|
|
* Parameter that is passed to the onImageUploadBefore event to control the behavior.
|
|
* @default true
|
|
*/
|
|
this.onImageUploadBefore_param = true;
|
|
/**
|
|
* Parameter that is passed to the onImageUploadError event to control the behavior.
|
|
* @default true
|
|
*/
|
|
this.onImageUploadError_param = true;
|
|
/**
|
|
* Parameter that is passed to the onVideoUploadBefore event to control the behavior.
|
|
* @default true
|
|
*/
|
|
this.onVideoUploadBefore_param = true;
|
|
/**
|
|
* Parameter that is passed to the onVideoUploadError event to control the behavior.
|
|
* @default true
|
|
*/
|
|
this.onVideoUploadError_param = true;
|
|
/**
|
|
* Parameter that is passed to the onAudioUploadBefore event to control the behavior.
|
|
* @default true
|
|
*/
|
|
this.onAudioUploadBefore_param = true;
|
|
/**
|
|
* Parameter that is passed to the onResizeEditor event to control the behavior.
|
|
* @default {}
|
|
*/
|
|
this.onResizeEditor_param = {};
|
|
/**
|
|
* Emitted after the editor compontent was created
|
|
*/
|
|
this.created = new EventEmitter();
|
|
/**
|
|
* When reloaded with the "setOptions" method
|
|
*/
|
|
this.onload = new EventEmitter();
|
|
/**
|
|
* Scroll event
|
|
*/
|
|
this.onScroll = new EventEmitter();
|
|
/**
|
|
* Mouse down
|
|
*/
|
|
this.onMouseDown = new EventEmitter();
|
|
/**
|
|
* clicked
|
|
*/
|
|
this.onClick = new EventEmitter();
|
|
/**
|
|
* Wysiwyg editor area Input event
|
|
*/
|
|
this.onInput = new EventEmitter();
|
|
/**
|
|
* keydown event
|
|
*/
|
|
this.onKeyDown = new EventEmitter();
|
|
/**
|
|
* keyup event
|
|
*/
|
|
this.onKeyUp = new EventEmitter();
|
|
/**
|
|
* Focus event
|
|
*/
|
|
this.onFocus = new EventEmitter();
|
|
/**
|
|
* Blur event
|
|
*/
|
|
this.onBlur = new EventEmitter();
|
|
/**
|
|
* Called when the editor is resized using the bottom bar
|
|
*/
|
|
this.onResizeEditor = new EventEmitter();
|
|
/**
|
|
* Called before the audio is uploaded
|
|
*/
|
|
this.onAudioUploadBefore = new EventEmitter();
|
|
/**
|
|
* Called on video upload error
|
|
*/
|
|
this.onVideoUploadError = new EventEmitter();
|
|
/**
|
|
* Called before the video is uploaded
|
|
*/
|
|
this.onVideoUploadBefore = new EventEmitter();
|
|
/**
|
|
* Called on image upload error
|
|
*/
|
|
this.onImageUploadError = new EventEmitter();
|
|
/**
|
|
* Called before the image is uploaded
|
|
*/
|
|
this.onImageUploadBefore = new EventEmitter();
|
|
/**
|
|
* Called on audio upload error
|
|
*/
|
|
this.onAudioUploadError = new EventEmitter();
|
|
/**
|
|
* Drop event
|
|
*/
|
|
this.onDrop = new EventEmitter();
|
|
/**
|
|
* Called when the contents changes
|
|
*/
|
|
this.onChange = new EventEmitter();
|
|
/**
|
|
* Called just after the controller is positioned and displayed on the screen
|
|
*/
|
|
this.showController = new EventEmitter();
|
|
/**
|
|
* Called when toggling full screen
|
|
*/
|
|
this.toggleFullScreen = new EventEmitter();
|
|
/**
|
|
* Called when toggling between code view and wysiwyg view
|
|
*/
|
|
this.toggleCodeView = new EventEmitter();
|
|
/**
|
|
* Called just before the inline toolbar is positioned and displayed on the screen
|
|
*/
|
|
this.showInline = new EventEmitter();
|
|
/**
|
|
* Called on audio upload
|
|
*/
|
|
this.onAudioUpload = new EventEmitter();
|
|
/**
|
|
* Called on video upload
|
|
*/
|
|
this.onVideoUpload = new EventEmitter();
|
|
/**
|
|
* Called on image upload
|
|
*/
|
|
this.onImageUpload = new EventEmitter();
|
|
/**
|
|
* Called when cut to clipboard
|
|
*/
|
|
this.onCut = new EventEmitter();
|
|
/**
|
|
* Called when copy to clipboard
|
|
*/
|
|
this.onCopy = new EventEmitter();
|
|
if (options && typeof options === 'object') {
|
|
this.options = options;
|
|
}
|
|
}
|
|
ngAfterViewInit() {
|
|
this.ngZone.runOutsideAngular(() => {
|
|
if (this._content)
|
|
this.options.value = this._content;
|
|
this.editor = suneditor.create(document.getElementById(this.editorID) || this.editorID, this.options);
|
|
if (this._imageUploadHandler)
|
|
this.editor.imageUploadHandler = this._imageUploadHandler;
|
|
if (this._videoUploadHandler)
|
|
this.editor.videoUploadHandler = this._videoUploadHandler;
|
|
if (this._audioUploadHandler)
|
|
this.editor.audioUploadHandler = this._audioUploadHandler;
|
|
});
|
|
if (this.isAutoLoadToLocalStorage) {
|
|
this.loadLocalStorageContent();
|
|
}
|
|
this.registerEvents();
|
|
this.created.emit(this);
|
|
}
|
|
/**
|
|
* Returns the HTML id Attribute that is randomly generated on startup on every editor instance.
|
|
*/
|
|
getEditorID() {
|
|
return this.editorID;
|
|
}
|
|
/**
|
|
* Returns the raw editor instance.
|
|
* @returns SunEditor
|
|
*/
|
|
getEditor() {
|
|
return this.editor;
|
|
}
|
|
/**
|
|
* Set the toolbar buttons
|
|
* @param buttonList any[]
|
|
*/
|
|
setToolbarButtons(buttonList) {
|
|
this.editor.setToolbarButtons(buttonList);
|
|
}
|
|
/**
|
|
* Pass a `SunEditorOptions` object to the editor to change the options after the editor was created
|
|
* @param options SunEditorOptions
|
|
*/
|
|
setOptions(options) {
|
|
this.editor.setOptions(options);
|
|
}
|
|
/**
|
|
* Define the style of the edit area without re render
|
|
* @param style Style string
|
|
*/
|
|
setDefaultStyle(style) {
|
|
this.editor.setDefaultStyle(style);
|
|
}
|
|
/**
|
|
* Opens a message in the notice panel (Alert)
|
|
* @param message string
|
|
*/
|
|
noticeOpen(message) {
|
|
this.editor.noticeOpen(message);
|
|
}
|
|
/**
|
|
* Closes the notice panel (Alert)
|
|
*/
|
|
noticeClose() {
|
|
this.editor.noticeClose();
|
|
}
|
|
/**
|
|
* Copying the contents of the editor to the original textarea and return the content or the full textarea. When passed true as param it only returns the content.
|
|
* Otherwise the original `HTMLInputElement` is returned
|
|
* @param onlyContent boolean
|
|
* @returns string | HTMLInputElement - content or the full textarea
|
|
*/
|
|
save(onlyContent) {
|
|
this.editor.save();
|
|
if (onlyContent) {
|
|
return this._content;
|
|
}
|
|
return document.getElementById(this.editorID);
|
|
}
|
|
/**
|
|
* Gets the SunEditor's context object. Contains settings, plugins, and cached element objects
|
|
*/
|
|
getContext() {
|
|
return this.editor.getContext();
|
|
}
|
|
/**
|
|
* Gets the contents of the suneditor
|
|
* @param onlyContents boolean - Return only the contents of the body without headers when the "fullPage" option is true
|
|
* @returns string - editor content
|
|
*/
|
|
getContents(onlyContents) {
|
|
return this.editor.getContents(onlyContents);
|
|
}
|
|
/**
|
|
* Gets only the text of the suneditor contents
|
|
*/
|
|
getText() {
|
|
return this.editor.getText();
|
|
}
|
|
/**
|
|
* Get the editor's number of characters or binary data size. You can use the "charCounterType" option format.
|
|
* @param charCounterType charCounterType
|
|
* options - charCounterType ('char', 'byte', 'byte-html') If argument is no value, the currently set "charCounterType" option is used.
|
|
* @returns number
|
|
*/
|
|
getCharCount(charCounterType) {
|
|
return this.editor.getCharCount(charCounterType);
|
|
}
|
|
/**
|
|
* Gets uploaded images informations
|
|
* index: data index
|
|
* name: file name
|
|
* size: file size
|
|
* select: select function
|
|
* delete: delete function
|
|
* element: img element
|
|
* src: src attribute of img tag
|
|
* @returns fileInfo[]
|
|
*/
|
|
getImagesInfo() {
|
|
return this.editor.getImagesInfo();
|
|
}
|
|
/**
|
|
* Gets uploaded files(plugin using fileManager) information list. image: [img], video: [video, iframe],
|
|
* audio: [audio] When the argument value is 'image', it is the same function as "getImagesInfo".
|
|
* @param pluginName Plugin name (image, video, audio)
|
|
* @returns fileInfo[]
|
|
*/
|
|
getFilesInfo(pluginName) {
|
|
return this.editor.getFilesInfo(pluginName);
|
|
}
|
|
/**
|
|
* Upload images using image plugin
|
|
* @param files FileList
|
|
*/
|
|
insertImage(files) {
|
|
this.editor.insertImage(files);
|
|
}
|
|
/**
|
|
* Inserts an HTML element or HTML string or plain string at the current cursor position
|
|
* @param html HTML Element or HTML string or plain string
|
|
* @param notCleaningData If true, inserts the HTML string without refining it with core.cleanHTML.
|
|
* @param checkCharCount f true, if "options.maxCharCount" is exceeded when "element" is added, null is returned without addition.
|
|
* @param rangeSelection If true, range select the inserted node.
|
|
*/
|
|
insertHTML(html, notCleaningData, checkCharCount, rangeSelection) {
|
|
this.editor.insertHTML(html, notCleaningData, checkCharCount, rangeSelection);
|
|
}
|
|
/**
|
|
* Change the contents of the suneditor
|
|
* @param contents Contents to Input
|
|
*/
|
|
setContents(contents) {
|
|
this.editor.setContents(contents);
|
|
}
|
|
/**
|
|
* Add contents to the suneditor
|
|
* @param contents Contents to Input
|
|
*/
|
|
appendContents(contents) {
|
|
this.editor.appendContents(contents);
|
|
}
|
|
/**
|
|
* Switch to or off "ReadOnly" mode.
|
|
* @param value "readOnly" boolean value.
|
|
*/
|
|
readOnly(value) {
|
|
this._readonly = value;
|
|
this.editor.readOnly(value);
|
|
}
|
|
/**
|
|
* Returns the readonly state of the SunEditor
|
|
* @returns boolean
|
|
*/
|
|
isReadOnly() {
|
|
return this._readonly;
|
|
}
|
|
/**
|
|
* Disable the suneditor
|
|
*/
|
|
disabled() {
|
|
this._disabled = true;
|
|
this.editor.disabled();
|
|
}
|
|
/**
|
|
* Returns the disabled state of the SunEditor
|
|
* @returns boolean
|
|
*/
|
|
isDisabled() {
|
|
return this._disabled;
|
|
}
|
|
/**
|
|
* Enable the suneditor
|
|
*/
|
|
enabled() {
|
|
this._disabled = false;
|
|
this.editor.enabled();
|
|
}
|
|
/**
|
|
* Show the editor
|
|
*/
|
|
show() {
|
|
this._hidden = false;
|
|
this.editor.show();
|
|
}
|
|
/**
|
|
* Hide the editor
|
|
*/
|
|
hide() {
|
|
this._hidden = true;
|
|
this.editor.hide();
|
|
}
|
|
/**
|
|
* Returns the hidden state of the editor
|
|
* @returns boolean
|
|
*/
|
|
isHidden() {
|
|
return this._hidden;
|
|
}
|
|
/**
|
|
* Add or remove the class name of "body" so that the code block is visible
|
|
*/
|
|
toggleDisplayBlocks() {
|
|
this.editor.core.toggleDisplayBlocks();
|
|
this._displayBlocks = !this._displayBlocks;
|
|
}
|
|
/**
|
|
* Returns the displayBlocks state of the editor
|
|
* @returns boolean
|
|
*/
|
|
isDisplayBlocks() {
|
|
return this._displayBlocks;
|
|
}
|
|
/**
|
|
* Changes to code view or wysiwyg view
|
|
*/
|
|
toggleCodeViewMode() {
|
|
this.editor.core.toggleCodeView();
|
|
this._codeView = !this._codeView;
|
|
}
|
|
/**
|
|
* Returns the CodeViewMode state of the editor
|
|
* @returns boolean
|
|
*/
|
|
isCodeViewMode() {
|
|
return this._codeView;
|
|
}
|
|
/**
|
|
* Undo changes
|
|
*/
|
|
undo() {
|
|
this.editor.core.history.undo();
|
|
}
|
|
/**
|
|
* Redo changes
|
|
*/
|
|
redo() {
|
|
this.editor.core.history.redo();
|
|
}
|
|
/**
|
|
* Remove format of the currently selected range
|
|
*/
|
|
removeFormat() {
|
|
this.editor.core.removeFormat();
|
|
}
|
|
/**
|
|
* Prints the current contents of the editor.
|
|
*/
|
|
print() {
|
|
this.editor.core.print();
|
|
}
|
|
/**
|
|
* Open a new tab as preview window.
|
|
*/
|
|
preview() {
|
|
this.editor.core.preview();
|
|
}
|
|
/**
|
|
* Get the actual history Stack
|
|
* @returns any[]
|
|
*/
|
|
getHistory() {
|
|
return this.editor.core.history.stack;
|
|
}
|
|
/**
|
|
* Select all in the editor
|
|
*/
|
|
selectAll() {
|
|
this.commandHandler(null, 'selectAll');
|
|
}
|
|
/**
|
|
* Get window selection obejct
|
|
* @returns Selection
|
|
*/
|
|
getSelection() {
|
|
return this.editor.core.getSelection();
|
|
}
|
|
/**
|
|
* Set the editor in loading mode. Show a loading spinner, disable inputs and grey out
|
|
*/
|
|
showLoading() {
|
|
this._loading = true;
|
|
this.editor.core.showLoading();
|
|
}
|
|
/**
|
|
* Remove the loading mode
|
|
*/
|
|
closeLoading() {
|
|
this._loading = false;
|
|
this.editor.core.closeLoading();
|
|
}
|
|
/**
|
|
* Returns the loading state of the SunEditor
|
|
* @returns boolean
|
|
*/
|
|
isLoading() {
|
|
return this._loading;
|
|
}
|
|
/**
|
|
* Enabled submenu
|
|
* @param element Submenu's button element to call
|
|
*/
|
|
submenuOn(element) {
|
|
this.editor.core.submenuOn(element);
|
|
}
|
|
/**
|
|
* Disable submenu
|
|
*/
|
|
submenuOff() {
|
|
this.editor.core.submenuOff();
|
|
}
|
|
/**
|
|
* Enabled container
|
|
* @param element Container's button element to call
|
|
*/
|
|
containerOn(element) {
|
|
this.editor.core.containerOn(element);
|
|
}
|
|
/**
|
|
* Disable container
|
|
*/
|
|
containerOff() {
|
|
this.editor.core.containerOff();
|
|
}
|
|
/**
|
|
* Append the className value of the argument value element
|
|
* @param element Elements to add class name
|
|
* @param className Class name to be add
|
|
*/
|
|
addClass(element, className) {
|
|
this.editor.util.addClass(element, className);
|
|
}
|
|
/**
|
|
* Class name to be add
|
|
* @param element Elements to remove class name
|
|
* @param className Class name to be remove
|
|
*/
|
|
removeClass(element, className) {
|
|
this.editor.util.removeClass(element, className);
|
|
}
|
|
/**
|
|
* Set style, if all styles are deleted, the style properties are deleted
|
|
* @param element Element to set style
|
|
* @param styleName Style attribute name (marginLeft, textAlign...)
|
|
* @param value Style value
|
|
*/
|
|
setStyle(element, styleName, value) {
|
|
this.editor.util.setStyle(element, styleName, value);
|
|
}
|
|
/**
|
|
* Add an event to document. When created as an Iframe, the same event is added to the document in the Iframe.
|
|
* @param type event type
|
|
* @param listener listener
|
|
* @param useCapture boolean
|
|
*/
|
|
addDocEvent(type, listener, useCapture) {
|
|
this.editor.core.addDocEvent(type, listener, useCapture);
|
|
}
|
|
/**
|
|
* Remove events from document. * When created as an Iframe, the event of the document inside the Iframe is also removed
|
|
* @param type Event type
|
|
* @param listener Event listener
|
|
*/
|
|
removeDocEvent(type, listener) {
|
|
this.editor.core.removeDocEvent(type, listener);
|
|
}
|
|
/**
|
|
* Run plugin calls and basic commands.
|
|
* @param command Command string
|
|
* @param display Display type string ('command', 'submenu', 'dialog', 'container')
|
|
* @param target The element of command button
|
|
*/
|
|
actionCall(command, display, target) {
|
|
this.editor.core.actionCall(command, display, target);
|
|
}
|
|
/**
|
|
* Set indentation separator "indent" or "outdent"
|
|
* @param command 'indent' | 'outdent'
|
|
*/
|
|
indent_outdent(command) {
|
|
this.commandHandler(null, command);
|
|
}
|
|
/**
|
|
* Display blocks in the editor
|
|
*/
|
|
showBlocks() {
|
|
const element = document.querySelector('[data-command="showBlocks"]');
|
|
if (element) {
|
|
this.commandHandler(element, 'showBlocks');
|
|
}
|
|
}
|
|
/**
|
|
* Toggle the editor fullscreen mode
|
|
*/
|
|
toggleFullScreenMode() {
|
|
const element = document.querySelector('[data-command="fullScreen"]');
|
|
if (element) {
|
|
this.commandHandler(element, 'fullScreen');
|
|
}
|
|
this._fullScreenMode = !this._fullScreenMode;
|
|
}
|
|
/**
|
|
* Returns the fullScreenMode state of the editor
|
|
* @returns boolean
|
|
*/
|
|
isFullScreenMode() {
|
|
return this._fullScreenMode;
|
|
}
|
|
/**
|
|
* Execute command of command button(All Buttons except submenu and dialog)
|
|
* (undo, redo, bold, underline, italic, strikethrough, subscript, superscript, removeFormat,
|
|
* indent, outdent, fullscreen, showBlocks, codeview, preview, print, copy, cut, paste)
|
|
* @param element The element of command button
|
|
* @param command Property of command button (data-value)
|
|
*/
|
|
commandHandler(element, command) {
|
|
this.editor.core.commandHandler(element, command);
|
|
}
|
|
/**
|
|
* loads the localStorageContent to the Editor
|
|
*/
|
|
loadLocalStorageContent() {
|
|
const localStorageContent = localStorage.getItem(this.localStorageId);
|
|
this.setContents(localStorageContent);
|
|
}
|
|
/**
|
|
* Save Content to LocalStorage
|
|
*/
|
|
saveToLocalStorage() {
|
|
localStorage.setItem(this.localStorageId, this._content);
|
|
}
|
|
/**
|
|
* returns the LocalStorageKey
|
|
*/
|
|
getLocalStorageKey() {
|
|
return this.localStorageId;
|
|
}
|
|
/**
|
|
* returns AutoSaveToLocalStorage
|
|
*/
|
|
getIsAutoSaveToLocalStorage() {
|
|
return this.isAutoSaveToLocalStorage;
|
|
}
|
|
/**
|
|
* returns AutoLoadToLocalStorage
|
|
*/
|
|
getIsAutoLoadToLocalStorage() {
|
|
return this.isAutoSaveToLocalStorage;
|
|
}
|
|
registerEvents() {
|
|
this.editor.onload = (core, reload) => {
|
|
this.onload.emit({ core, reload });
|
|
};
|
|
this.editor.onScroll = (e, core) => {
|
|
this.onScroll.emit({ e, core });
|
|
};
|
|
this.editor.onMouseDown = (e, core) => {
|
|
this.onMouseDown.emit({ e, core });
|
|
};
|
|
this.editor.onClick = (e, core) => {
|
|
this.onClick.emit({ e, core });
|
|
};
|
|
this.editor.onInput = (e, core) => {
|
|
this.onInput.emit({ e, core });
|
|
};
|
|
this.editor.onKeyDown = (e, core) => {
|
|
this.onKeyDown.emit({ e, core });
|
|
};
|
|
this.editor.onKeyUp = (e, core) => {
|
|
this.onKeyUp.emit({ e, core });
|
|
};
|
|
this.editor.onChange = (content, core) => {
|
|
this._content = content;
|
|
this.onChange.emit({ content: this._content, core });
|
|
if (this.isAutoSaveToLocalStorage) {
|
|
this.saveToLocalStorage();
|
|
}
|
|
};
|
|
this.editor.onFocus = (e, core) => {
|
|
this.onFocus.emit({ e, core });
|
|
};
|
|
this.editor.showController = (name, controllers, core) => {
|
|
this.showController.emit({ name, controllers, core });
|
|
};
|
|
this.editor.toggleFullScreen = (isFullScreen, core) => {
|
|
this.toggleFullScreen.emit({ isFullScreen, core });
|
|
};
|
|
this.editor.toggleCodeView = (isCodeView, core) => {
|
|
this.toggleCodeView.emit({ isCodeView, core });
|
|
};
|
|
this.editor.showInline = (toolbar, context, core) => {
|
|
this.showInline.emit({ toolbar, context, core });
|
|
};
|
|
this.editor.onAudioUpload = (targetElement, index, state, info, remainingFilesCount, core) => {
|
|
this.onAudioUpload.emit({
|
|
targetElement,
|
|
index,
|
|
state,
|
|
info,
|
|
remainingFilesCount,
|
|
core,
|
|
});
|
|
};
|
|
this.editor.onVideoUpload = (targetElement, index, state, info, remainingFilesCount, core) => {
|
|
this.onVideoUpload.emit({
|
|
targetElement,
|
|
index,
|
|
state,
|
|
info,
|
|
remainingFilesCount,
|
|
core,
|
|
});
|
|
};
|
|
this.editor.onImageUpload = (targetElement, index, state, info, remainingFilesCount, core) => {
|
|
this.onImageUpload.emit({
|
|
targetElement,
|
|
index,
|
|
state,
|
|
info,
|
|
remainingFilesCount,
|
|
core,
|
|
});
|
|
};
|
|
// This functions needs to return a boolean. The type definition is wrong here.
|
|
// https://github.com/JiHong88/SunEditor/pull/810
|
|
this.editor.onCut = (e, clipboardData, core) => {
|
|
this.onCut.emit({ e, clipboardData, core });
|
|
return this.onCut_param;
|
|
};
|
|
// This functions needs to return a boolean. The type definition is wrong here.
|
|
// https://github.com/JiHong88/SunEditor/pull/810
|
|
this.editor.onCopy = (e, clipboardData, core) => {
|
|
this.onCopy.emit({ e, clipboardData, core });
|
|
return this.onCopy_param;
|
|
};
|
|
this.editor.onDrop = (e, cleanData, maxCharCount, core) => {
|
|
this.onDrop.emit({ e, cleanData, maxCharCount, core });
|
|
return this.onDrop_param;
|
|
};
|
|
this.editor.onAudioUploadError = (errorMessage, result, core) => {
|
|
this.onAudioUploadError.emit({ errorMessage, result, core });
|
|
return this.onAudioUploadError_param;
|
|
};
|
|
this.editor.onImageUploadBefore = (files, info, core, uploadHandler) => {
|
|
this.onImageUploadBefore.emit({ files, info, core, uploadHandler });
|
|
return this.onImageUploadBefore_param;
|
|
};
|
|
this.editor.onImageUploadError = (errorMessage, result, core) => {
|
|
this.onImageUploadError.emit({ errorMessage, result, core });
|
|
return this.onImageUploadError_param;
|
|
};
|
|
this.editor.onVideoUploadBefore = (files, info, core, uploadHandler) => {
|
|
this.onVideoUploadBefore.emit({ files, info, core, uploadHandler });
|
|
return this.onVideoUploadBefore_param;
|
|
};
|
|
this.editor.onVideoUploadError = (errorMessage, result, core) => {
|
|
this.onVideoUploadError.emit({ errorMessage, result, core });
|
|
return this.onVideoUploadError_param;
|
|
};
|
|
this.editor.onAudioUploadBefore = (files, info, core, uploadHandler) => {
|
|
this.onAudioUploadBefore.emit({ files, info, core, uploadHandler });
|
|
return this.onAudioUploadBefore_param;
|
|
};
|
|
this.editor.onResizeEditor = (height, prevHeight, core) => {
|
|
this.onResizeEditor.emit({ height, prevHeight, core });
|
|
return this.onResizeEditor_param;
|
|
};
|
|
}
|
|
generateID() {
|
|
const min = Math.ceil(1);
|
|
const max = Math.floor(100000);
|
|
return `ngxsuneditor_${(Math.floor(Math.random() * (max - min)) + min).toString()}`;
|
|
}
|
|
}
|
|
NgxSuneditorComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgxSuneditorComponent, deps: [{ token: i0.NgZone }, { token: SUNEDITOR_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Component });
|
|
NgxSuneditorComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: NgxSuneditorComponent, selector: "ngx-suneditor", inputs: { content: "content", editorID: "editorID", options: "options", onDrop_param: "onDrop_param", onCopy_param: "onCopy_param", onCut_param: "onCut_param", onAudioUploadError_param: "onAudioUploadError_param", onImageUploadBefore_param: "onImageUploadBefore_param", onImageUploadError_param: "onImageUploadError_param", onVideoUploadBefore_param: "onVideoUploadBefore_param", onVideoUploadError_param: "onVideoUploadError_param", onAudioUploadBefore_param: "onAudioUploadBefore_param", onResizeEditor_param: "onResizeEditor_param", imageUploadHandler: "imageUploadHandler", videoUploadHandler: "videoUploadHandler", audioUploadHandler: "audioUploadHandler", localStorageConfig: "localStorageConfig" }, outputs: { created: "created", onload: "onload", onScroll: "onScroll", onMouseDown: "onMouseDown", onClick: "onClick", onInput: "onInput", onKeyDown: "onKeyDown", onKeyUp: "onKeyUp", onFocus: "onFocus", onBlur: "onBlur", onResizeEditor: "onResizeEditor", onAudioUploadBefore: "onAudioUploadBefore", onVideoUploadError: "onVideoUploadError", onVideoUploadBefore: "onVideoUploadBefore", onImageUploadError: "onImageUploadError", onImageUploadBefore: "onImageUploadBefore", onAudioUploadError: "onAudioUploadError", onDrop: "onDrop", onChange: "onChange", showController: "showController", toggleFullScreen: "toggleFullScreen", toggleCodeView: "toggleCodeView", showInline: "showInline", onAudioUpload: "onAudioUpload", onVideoUpload: "onVideoUpload", onImageUpload: "onImageUpload", onCut: "onCut", onCopy: "onCopy" }, ngImport: i0, template: ` <textarea id="{{ editorID }}"></textarea> `, isInline: true });
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgxSuneditorComponent, decorators: [{
|
|
type: Component,
|
|
args: [{
|
|
selector: 'ngx-suneditor',
|
|
template: ` <textarea id="{{ editorID }}"></textarea> `,
|
|
}]
|
|
}], ctorParameters: function () { return [{ type: i0.NgZone }, { type: undefined, decorators: [{
|
|
type: Optional
|
|
}, {
|
|
type: Inject,
|
|
args: [SUNEDITOR_OPTIONS]
|
|
}] }]; }, propDecorators: { content: [{
|
|
type: Input
|
|
}], editorID: [{
|
|
type: Input
|
|
}], options: [{
|
|
type: Input
|
|
}], onDrop_param: [{
|
|
type: Input
|
|
}], onCopy_param: [{
|
|
type: Input
|
|
}], onCut_param: [{
|
|
type: Input
|
|
}], onAudioUploadError_param: [{
|
|
type: Input
|
|
}], onImageUploadBefore_param: [{
|
|
type: Input
|
|
}], onImageUploadError_param: [{
|
|
type: Input
|
|
}], onVideoUploadBefore_param: [{
|
|
type: Input
|
|
}], onVideoUploadError_param: [{
|
|
type: Input
|
|
}], onAudioUploadBefore_param: [{
|
|
type: Input
|
|
}], onResizeEditor_param: [{
|
|
type: Input
|
|
}], imageUploadHandler: [{
|
|
type: Input
|
|
}], videoUploadHandler: [{
|
|
type: Input
|
|
}], audioUploadHandler: [{
|
|
type: Input
|
|
}], localStorageConfig: [{
|
|
type: Input
|
|
}], created: [{
|
|
type: Output
|
|
}], onload: [{
|
|
type: Output
|
|
}], onScroll: [{
|
|
type: Output
|
|
}], onMouseDown: [{
|
|
type: Output
|
|
}], onClick: [{
|
|
type: Output
|
|
}], onInput: [{
|
|
type: Output
|
|
}], onKeyDown: [{
|
|
type: Output
|
|
}], onKeyUp: [{
|
|
type: Output
|
|
}], onFocus: [{
|
|
type: Output
|
|
}], onBlur: [{
|
|
type: Output
|
|
}], onResizeEditor: [{
|
|
type: Output
|
|
}], onAudioUploadBefore: [{
|
|
type: Output
|
|
}], onVideoUploadError: [{
|
|
type: Output
|
|
}], onVideoUploadBefore: [{
|
|
type: Output
|
|
}], onImageUploadError: [{
|
|
type: Output
|
|
}], onImageUploadBefore: [{
|
|
type: Output
|
|
}], onAudioUploadError: [{
|
|
type: Output
|
|
}], onDrop: [{
|
|
type: Output
|
|
}], onChange: [{
|
|
type: Output
|
|
}], showController: [{
|
|
type: Output
|
|
}], toggleFullScreen: [{
|
|
type: Output
|
|
}], toggleCodeView: [{
|
|
type: Output
|
|
}], showInline: [{
|
|
type: Output
|
|
}], onAudioUpload: [{
|
|
type: Output
|
|
}], onVideoUpload: [{
|
|
type: Output
|
|
}], onImageUpload: [{
|
|
type: Output
|
|
}], onCut: [{
|
|
type: Output
|
|
}], onCopy: [{
|
|
type: Output
|
|
}] } });
|
|
|
|
/**
|
|
* Bypass the angular DomSantiziser and trust the given value to be safe HTML.
|
|
* The reason this pipe is needed is because there is no ability to trust a custom whitelist of HTML tags,
|
|
* attributes, and values with a DOM sanitizer, without bypassing the whole sanitizer.
|
|
* https://github.com/angular/angular/issues/19645
|
|
* https://github.com/angular/angular/issues/36650
|
|
*/
|
|
class SafeHtmlPipe {
|
|
constructor(sanitized) {
|
|
this.sanitized = sanitized;
|
|
}
|
|
transform(value) {
|
|
return this.sanitized.bypassSecurityTrustHtml(value);
|
|
}
|
|
}
|
|
SafeHtmlPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SafeHtmlPipe, deps: [{ token: i1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
SafeHtmlPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.10", ngImport: i0, type: SafeHtmlPipe, name: "safeHtml" });
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: SafeHtmlPipe, decorators: [{
|
|
type: Pipe,
|
|
args: [{ name: 'safeHtml' }]
|
|
}], ctorParameters: function () { return [{ type: i1.DomSanitizer }]; } });
|
|
|
|
class NgxSunViewComponent {
|
|
constructor() {
|
|
/**
|
|
* Bypass angular's DomSanitizer
|
|
* @default false
|
|
*/
|
|
this.bypassSantiziser = false;
|
|
}
|
|
}
|
|
NgxSunViewComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgxSunViewComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
NgxSunViewComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: NgxSunViewComponent, selector: "ngx-sunview", inputs: { content: "content", bypassSantiziser: "bypassSantiziser" }, ngImport: i0, template: `
|
|
<div
|
|
*ngIf="bypassSantiziser"
|
|
class="sun-editor-editable"
|
|
[innerHTML]="content | safeHtml"
|
|
></div>
|
|
<div
|
|
*ngIf="!bypassSantiziser"
|
|
class="sun-editor-editable"
|
|
[innerHTML]="content"
|
|
></div>
|
|
`, isInline: true, dependencies: [{ kind: "directive", type: i1$1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: SafeHtmlPipe, name: "safeHtml" }] });
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgxSunViewComponent, decorators: [{
|
|
type: Component,
|
|
args: [{
|
|
selector: 'ngx-sunview',
|
|
template: `
|
|
<div
|
|
*ngIf="bypassSantiziser"
|
|
class="sun-editor-editable"
|
|
[innerHTML]="content | safeHtml"
|
|
></div>
|
|
<div
|
|
*ngIf="!bypassSantiziser"
|
|
class="sun-editor-editable"
|
|
[innerHTML]="content"
|
|
></div>
|
|
`,
|
|
}]
|
|
}], propDecorators: { content: [{
|
|
type: Input
|
|
}], bypassSantiziser: [{
|
|
type: Input
|
|
}] } });
|
|
|
|
class NgxSuneditorModule {
|
|
/**
|
|
* Call this method once for editor configuration that should be used for every instance
|
|
* without the need to provide the options object again
|
|
*
|
|
* You can pass options to the options input property of the component directly to override
|
|
* a configuration for a single instance
|
|
*
|
|
* @example
|
|
* export class appModule {
|
|
* ...
|
|
* imports: [NgxSuneditorModule.forRoot(options)]
|
|
* }
|
|
*
|
|
* export class featureModule {
|
|
* ...
|
|
* imports: [NgxSuneditorModule]
|
|
* }
|
|
*
|
|
* // HTML in appModule
|
|
* // uses the 'default' options provided by froRoot(...)
|
|
* <ngx-suneditor></ngx-suneditor>
|
|
*
|
|
* // uses the options provided via input
|
|
* <ngx-suneditor [options]="opts"></ngx-suneditor>
|
|
*
|
|
* // uses the 'default' options provided by froRoot(...)
|
|
* <app-feature-comp-editor></app-feature-comp-editor>>
|
|
*
|
|
* // HTML in feature module
|
|
* // uses the 'default' options provided by froRoot(...)
|
|
* <ngx-suneditor></ngx-suneditor>
|
|
*
|
|
*
|
|
*
|
|
* @param sunEditorOptions editor options
|
|
*/
|
|
static forRoot(sunEditorOptions) {
|
|
return {
|
|
ngModule: NgxSuneditorModule,
|
|
providers: [
|
|
{
|
|
provide: SUNEDITOR_OPTIONS,
|
|
useValue: sunEditorOptions,
|
|
},
|
|
],
|
|
};
|
|
}
|
|
}
|
|
NgxSuneditorModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgxSuneditorModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
NgxSuneditorModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.10", ngImport: i0, type: NgxSuneditorModule, declarations: [NgxSuneditorComponent, NgxSunViewComponent, SafeHtmlPipe], imports: [CommonModule], exports: [NgxSuneditorComponent, NgxSunViewComponent] });
|
|
NgxSuneditorModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgxSuneditorModule, imports: [CommonModule] });
|
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: NgxSuneditorModule, decorators: [{
|
|
type: NgModule,
|
|
args: [{
|
|
declarations: [NgxSuneditorComponent, NgxSunViewComponent, SafeHtmlPipe],
|
|
imports: [CommonModule],
|
|
exports: [NgxSuneditorComponent, NgxSunViewComponent],
|
|
}]
|
|
}] });
|
|
|
|
/*
|
|
* Public API Surface of ngx-suneditor
|
|
*/
|
|
|
|
/**
|
|
* Generated bundle index. Do not edit.
|
|
*/
|
|
|
|
export { NgxSunViewComponent, NgxSuneditorComponent, NgxSuneditorModule, SUNEDITOR_OPTIONS, SafeHtmlPipe };
|
|
//# sourceMappingURL=ngx-sendune-editor.mjs.map
|