UNPKG

42.5 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('@angular/common')) :
3 typeof define === 'function' && define.amd ? define('ngx-wig', ['exports', '@angular/core', '@angular/forms', '@angular/common'], factory) :
4 (global = global || self, factory(global['ngx-wig'] = {}, global.ng.core, global.ng.forms, global.ng.common));
5}(this, (function (exports, core, forms, common) { 'use strict';
6
7 /*! *****************************************************************************
8 Copyright (c) Microsoft Corporation. All rights reserved.
9 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
10 this file except in compliance with the License. You may obtain a copy of the
11 License at http://www.apache.org/licenses/LICENSE-2.0
12
13 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16 MERCHANTABLITY OR NON-INFRINGEMENT.
17
18 See the Apache Version 2.0 License for specific language governing permissions
19 and limitations under the License.
20 ***************************************************************************** */
21 /* global Reflect, Promise */
22
23 var extendStatics = function(d, b) {
24 extendStatics = Object.setPrototypeOf ||
25 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
26 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
27 return extendStatics(d, b);
28 };
29
30 function __extends(d, b) {
31 extendStatics(d, b);
32 function __() { this.constructor = d; }
33 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34 }
35
36 var __assign = function() {
37 __assign = Object.assign || function __assign(t) {
38 for (var s, i = 1, n = arguments.length; i < n; i++) {
39 s = arguments[i];
40 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
41 }
42 return t;
43 };
44 return __assign.apply(this, arguments);
45 };
46
47 function __rest(s, e) {
48 var t = {};
49 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
50 t[p] = s[p];
51 if (s != null && typeof Object.getOwnPropertySymbols === "function")
52 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
53 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
54 t[p[i]] = s[p[i]];
55 }
56 return t;
57 }
58
59 function __decorate(decorators, target, key, desc) {
60 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
61 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
62 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;
63 return c > 3 && r && Object.defineProperty(target, key, r), r;
64 }
65
66 function __param(paramIndex, decorator) {
67 return function (target, key) { decorator(target, key, paramIndex); }
68 }
69
70 function __metadata(metadataKey, metadataValue) {
71 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
72 }
73
74 function __awaiter(thisArg, _arguments, P, generator) {
75 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
76 return new (P || (P = Promise))(function (resolve, reject) {
77 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
78 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
79 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
80 step((generator = generator.apply(thisArg, _arguments || [])).next());
81 });
82 }
83
84 function __generator(thisArg, body) {
85 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
86 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
87 function verb(n) { return function (v) { return step([n, v]); }; }
88 function step(op) {
89 if (f) throw new TypeError("Generator is already executing.");
90 while (_) try {
91 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;
92 if (y = 0, t) op = [op[0] & 2, t.value];
93 switch (op[0]) {
94 case 0: case 1: t = op; break;
95 case 4: _.label++; return { value: op[1], done: false };
96 case 5: _.label++; y = op[1]; op = [0]; continue;
97 case 7: op = _.ops.pop(); _.trys.pop(); continue;
98 default:
99 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
100 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
101 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
102 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
103 if (t[2]) _.ops.pop();
104 _.trys.pop(); continue;
105 }
106 op = body.call(thisArg, _);
107 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
108 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
109 }
110 }
111
112 function __exportStar(m, exports) {
113 for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
114 }
115
116 function __values(o) {
117 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
118 if (m) return m.call(o);
119 if (o && typeof o.length === "number") return {
120 next: function () {
121 if (o && i >= o.length) o = void 0;
122 return { value: o && o[i++], done: !o };
123 }
124 };
125 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
126 }
127
128 function __read(o, n) {
129 var m = typeof Symbol === "function" && o[Symbol.iterator];
130 if (!m) return o;
131 var i = m.call(o), r, ar = [], e;
132 try {
133 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
134 }
135 catch (error) { e = { error: error }; }
136 finally {
137 try {
138 if (r && !r.done && (m = i["return"])) m.call(i);
139 }
140 finally { if (e) throw e.error; }
141 }
142 return ar;
143 }
144
145 function __spread() {
146 for (var ar = [], i = 0; i < arguments.length; i++)
147 ar = ar.concat(__read(arguments[i]));
148 return ar;
149 }
150
151 function __spreadArrays() {
152 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
153 for (var r = Array(s), k = 0, i = 0; i < il; i++)
154 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
155 r[k] = a[j];
156 return r;
157 };
158
159 function __await(v) {
160 return this instanceof __await ? (this.v = v, this) : new __await(v);
161 }
162
163 function __asyncGenerator(thisArg, _arguments, generator) {
164 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
165 var g = generator.apply(thisArg, _arguments || []), i, q = [];
166 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
167 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); }); }; }
168 function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
169 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
170 function fulfill(value) { resume("next", value); }
171 function reject(value) { resume("throw", value); }
172 function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
173 }
174
175 function __asyncDelegator(o) {
176 var i, p;
177 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
178 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; }
179 }
180
181 function __asyncValues(o) {
182 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
183 var m = o[Symbol.asyncIterator], i;
184 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);
185 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); }); }; }
186 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
187 }
188
189 function __makeTemplateObject(cooked, raw) {
190 if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
191 return cooked;
192 };
193
194 function __importStar(mod) {
195 if (mod && mod.__esModule) return mod;
196 var result = {};
197 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
198 result.default = mod;
199 return result;
200 }
201
202 function __importDefault(mod) {
203 return (mod && mod.__esModule) ? mod : { default: mod };
204 }
205
206 function __classPrivateFieldGet(receiver, privateMap) {
207 if (!privateMap.has(receiver)) {
208 throw new TypeError("attempted to get private field on non-instance");
209 }
210 return privateMap.get(receiver);
211 }
212
213 function __classPrivateFieldSet(receiver, privateMap, value) {
214 if (!privateMap.has(receiver)) {
215 throw new TypeError("attempted to set private field on non-instance");
216 }
217 privateMap.set(receiver, value);
218 return value;
219 }
220
221 var DEFAULT_LIBRARY_BUTTONS = {
222 list1: {
223 label: 'UL',
224 title: 'Unordered List',
225 command: 'insertunorderedlist',
226 styleClass: 'list-ul',
227 icon: 'icon-list-ul'
228 },
229 list2: {
230 label: 'OL',
231 title: 'Ordered List',
232 command: 'insertorderedlist',
233 styleClass: 'list-ol',
234 icon: 'icon-list-ol'
235 },
236 bold: {
237 label: 'B',
238 title: 'Bold',
239 command: 'bold',
240 styleClass: 'bold',
241 icon: 'icon-bold'
242 },
243 italic: {
244 label: 'I',
245 title: 'Italic',
246 command: 'italic',
247 styleClass: 'italic',
248 icon: 'icon-italic'
249 },
250 link: {
251 label: 'Link',
252 title: 'Link',
253 command: 'createlink',
254 styleClass: 'link',
255 icon: 'icon-link'
256 },
257 underline: {
258 label: 'U',
259 title: 'Underline',
260 command: 'underline',
261 styleClass: 'format-underlined',
262 icon: 'icon-underline'
263 }
264 };
265 var CUSTOM_LIBRARY_BUTTONS = {
266 edithtml: {
267 label: 'Edit HTML',
268 title: 'Edit HTML',
269 command: function (ctx) {
270 ctx.editMode = !ctx.editMode;
271 },
272 styleClass: 'nw-button--source',
273 icon: '',
274 }
275 };
276 var BUTTONS = new core.InjectionToken('BUTTONS');
277
278 var NgxWigToolbarService = /** @class */ (function () {
279 function NgxWigToolbarService(buttonLibraryConfig) {
280 this._defaultButtonsList = [];
281 this._buttonLibrary = buttonLibraryConfig.reduce(function (acc, val) { return (__assign(__assign({}, acc), val)); }, {});
282 this._defaultButtonsList = Object.keys(this._buttonLibrary);
283 }
284 NgxWigToolbarService.prototype.setButtons = function (buttons) {
285 if (!Array.isArray(buttons)) {
286 throw new Error('Argument "buttons" should be an array');
287 }
288 this._defaultButtonsList = buttons;
289 };
290 NgxWigToolbarService.prototype.addStandardButton = function (name, title, command, styleClass, icon) {
291 if (!name || !title || !command) {
292 throw new Error('Arguments "name", "title" and "command" are required');
293 }
294 styleClass = styleClass || '';
295 this._buttonLibrary[name] = { title: title, command: command, styleClass: styleClass, icon: icon };
296 this._defaultButtonsList.push(name);
297 };
298 NgxWigToolbarService.prototype.getToolbarButtons = function (buttonsList) {
299 var _this = this;
300 var buttons = this._defaultButtonsList;
301 var toolbarButtons = [];
302 if (typeof buttonsList !== 'undefined') {
303 buttons = string2array(buttonsList);
304 }
305 buttons.forEach(function (buttonKey) {
306 if (!buttonKey) {
307 return;
308 }
309 if (!_this._buttonLibrary[buttonKey]) {
310 throw new Error("There is no \"" + buttonKey + "\" in your library. Possible variants: " + Object.keys(_this._buttonLibrary));
311 }
312 var button = Object.assign({}, _this._buttonLibrary[buttonKey]);
313 // button.isActive = () => {return !!this.command && document.queryCommandState(this.command);}
314 toolbarButtons.push(button);
315 });
316 return toolbarButtons;
317 };
318 NgxWigToolbarService.ɵfac = function NgxWigToolbarService_Factory(t) { return new (t || NgxWigToolbarService)(core["ɵɵinject"](BUTTONS)); };
319 NgxWigToolbarService.ɵprov = core["ɵɵdefineInjectable"]({ token: NgxWigToolbarService, factory: NgxWigToolbarService.ɵfac, providedIn: 'root' });
320 return NgxWigToolbarService;
321 }());
322 /*@__PURE__*/ (function () { core["ɵsetClassMetadata"](NgxWigToolbarService, [{
323 type: core.Injectable,
324 args: [{
325 providedIn: 'root'
326 }]
327 }], function () { return [{ type: undefined, decorators: [{
328 type: core.Inject,
329 args: [BUTTONS]
330 }] }]; }, null); })();
331 function string2array(keysString) {
332 return keysString
333 .split(',')
334 .map(Function.prototype.call, String.prototype.trim);
335 }
336
337 var _c0 = ["ngWigEditable"];
338 function NgxWigComponent_li_2_ng_container_3_Template(rf, ctx) { if (rf & 1) {
339 core["ɵɵelementContainerStart"](0);
340 core["ɵɵtext"](1);
341 core["ɵɵelementContainerEnd"]();
342 } if (rf & 2) {
343 var button_r19 = core["ɵɵnextContext"]().$implicit;
344 core["ɵɵadvance"](1);
345 core["ɵɵtextInterpolate"](button_r19.label);
346 } }
347 var _c1 = function (a0) { return [a0]; };
348 function NgxWigComponent_li_2_div_4_Template(rf, ctx) { if (rf & 1) {
349 core["ɵɵelement"](0, "div", 13);
350 } if (rf & 2) {
351 var button_r19 = core["ɵɵnextContext"]().$implicit;
352 core["ɵɵproperty"]("ngClass", core["ɵɵpureFunction1"](1, _c1, button_r19.icon));
353 } }
354 function NgxWigComponent_li_2_Template(rf, ctx) { if (rf & 1) {
355 var _r25 = core["ɵɵgetCurrentView"]();
356 core["ɵɵelementStart"](0, "li", 9);
357 core["ɵɵelementStart"](1, "div");
358 core["ɵɵelementStart"](2, "button", 10);
359 core["ɵɵlistener"]("click", function NgxWigComponent_li_2_Template_button_click_2_listener() { core["ɵɵrestoreView"](_r25); var button_r19 = ctx.$implicit; var ctx_r24 = core["ɵɵnextContext"](); return ctx_r24.execCommand(button_r19.command); });
360 core["ɵɵtemplate"](3, NgxWigComponent_li_2_ng_container_3_Template, 2, 1, "ng-container", 11);
361 core["ɵɵtemplate"](4, NgxWigComponent_li_2_div_4_Template, 1, 3, "div", 12);
362 core["ɵɵelementEnd"]();
363 core["ɵɵelementEnd"]();
364 core["ɵɵelementEnd"]();
365 } if (rf & 2) {
366 var button_r19 = ctx.$implicit;
367 var ctx_r15 = core["ɵɵnextContext"]();
368 core["ɵɵadvance"](2);
369 core["ɵɵproperty"]("ngClass", core["ɵɵpureFunction1"](5, _c1, button_r19.styleClass))("title", button_r19.title)("disabled", ctx_r15.disabled);
370 core["ɵɵadvance"](1);
371 core["ɵɵproperty"]("ngIf", !button_r19.icon);
372 core["ɵɵadvance"](1);
373 core["ɵɵproperty"]("ngIf", button_r19.icon);
374 } }
375 function NgxWigComponent_div_4_Template(rf, ctx) { if (rf & 1) {
376 var _r27 = core["ɵɵgetCurrentView"]();
377 core["ɵɵelementStart"](0, "div", 14);
378 core["ɵɵelementStart"](1, "textarea", 15);
379 core["ɵɵlistener"]("ngModelChange", function NgxWigComponent_div_4_Template_textarea_ngModelChange_1_listener($event) { core["ɵɵrestoreView"](_r27); var ctx_r26 = core["ɵɵnextContext"](); return ctx_r26.onTextareaChange($event); })("blur", function NgxWigComponent_div_4_Template_textarea_blur_1_listener() { core["ɵɵrestoreView"](_r27); var ctx_r28 = core["ɵɵnextContext"](); return ctx_r28.propagateTouched(); });
380 core["ɵɵtext"](2, " ");
381 core["ɵɵelementEnd"]();
382 core["ɵɵelementEnd"]();
383 } if (rf & 2) {
384 var ctx_r16 = core["ɵɵnextContext"]();
385 core["ɵɵadvance"](1);
386 core["ɵɵproperty"]("ngModel", ctx_r16.content);
387 } }
388 function NgxWigComponent_div_6_Template(rf, ctx) { if (rf & 1) {
389 core["ɵɵelement"](0, "div", 16);
390 } if (rf & 2) {
391 var ctx_r17 = core["ɵɵnextContext"]();
392 core["ɵɵproperty"]("innerText", ctx_r17.placeholder);
393 } }
394 var _c2 = function (a0) { return { "nw-editor-container--with-toolbar": a0 }; };
395 var _c3 = function (a0, a1) { return { "nw-disabled": a0, "nw-invisible": a1 }; };
396 var _c4 = function (a0) { return { disabled: a0 }; };
397 /** @dynamic */
398 var NgxWigComponent = /** @class */ (function () {
399 function NgxWigComponent(_ngWigToolbarService, document, // cannot set Document here - Angular issue - https://github.com/angular/angular/issues/20351
400 window) {
401 this._ngWigToolbarService = _ngWigToolbarService;
402 this.document = document;
403 this.window = window;
404 this.contentChange = new core.EventEmitter();
405 this.editMode = false;
406 this.toolbarButtons = [];
407 this.hasFocus = false;
408 this.propagateChange = function (_) { };
409 this.propagateTouched = function () { };
410 }
411 NgxWigComponent.prototype.execCommand = function (command, options) {
412 if (typeof command === 'function') {
413 command(this);
414 return true;
415 }
416 if (this.editMode) {
417 return false;
418 }
419 if (this.document.queryCommandSupported && !this.document.queryCommandSupported(command)) {
420 throw new Error("The command \"" + command + "\" is not supported");
421 }
422 if (command === 'createlink' || command === 'insertImage') {
423 options = window.prompt('Please enter the URL', 'http://') || '';
424 if (!options) {
425 return false;
426 }
427 }
428 this.container.focus();
429 // use insertHtml for `createlink` command to account for IE/Edge purposes, in case there is no selection
430 var selection = this.document.getSelection().toString();
431 if (command === 'createlink' && selection === '') {
432 this.document.execCommand('insertHtml', false, '<a href="' + options + '">' + options + '</a>');
433 }
434 else {
435 this.document.execCommand(command, false, options);
436 }
437 this.onContentChange(this.container.innerHTML);
438 return true;
439 };
440 NgxWigComponent.prototype.ngOnInit = function () {
441 this.toolbarButtons = this._ngWigToolbarService.getToolbarButtons(this.buttons);
442 this.container = this.ngxWigEditable.nativeElement;
443 if (this.content) {
444 this.container.innerHTML = this.content;
445 }
446 };
447 NgxWigComponent.prototype.ngAfterViewInit = function () {
448 // Workaround for IE11 which doesn't fire 'input' event on
449 // contenteditable
450 // https://stackoverflow.com/a/49287032/7369511
451 var _this = this;
452 // check if the browser is IE:
453 if (window.document['documentMode']) {
454 this._mutationObserver = new MutationObserver(function () {
455 _this.onContentChange(_this.container.innerHTML);
456 });
457 this._mutationObserver.observe(this.container, { childList: true, subtree: true, characterData: true });
458 }
459 };
460 NgxWigComponent.prototype.ngOnDestroy = function () {
461 if (this._mutationObserver) {
462 this._mutationObserver.disconnect();
463 }
464 };
465 NgxWigComponent.prototype.onContentChange = function (newContent) {
466 this.content = newContent;
467 this.contentChange.emit(this.content);
468 this.propagateChange(this.content);
469 };
470 NgxWigComponent.prototype.ngOnChanges = function (changes) {
471 if (this.container && changes['content']) {
472 // clear the previous content
473 this.container.innerHTML = '';
474 // add the new content
475 this.pasteHtmlAtCaret(changes['content'].currentValue);
476 }
477 };
478 NgxWigComponent.prototype.onTextareaChange = function (newContent) {
479 // model -> view
480 this.container.innerHTML = newContent;
481 this.onContentChange(newContent);
482 };
483 NgxWigComponent.prototype.writeValue = function (value) {
484 if (!value) {
485 value = '';
486 }
487 this.container.innerHTML = value;
488 this.content = value;
489 };
490 NgxWigComponent.prototype.shouldShowPlaceholder = function () {
491 return !!this.placeholder
492 && !this.container.innerText;
493 };
494 NgxWigComponent.prototype.pasteHtmlAtCaret = function (html) {
495 var sel, range;
496 if (window.getSelection) {
497 sel = window.getSelection();
498 if (sel.getRangeAt && sel.rangeCount) {
499 range = sel.getRangeAt(0);
500 range.deleteContents();
501 // append the content in a temporary div
502 var el = this.document.createElement('div');
503 el.innerHTML = html;
504 var frag = this.document.createDocumentFragment();
505 var node = void 0, lastNode = void 0;
506 while ((node = el.firstChild)) {
507 lastNode = frag.appendChild(node);
508 }
509 range.insertNode(frag);
510 // Preserve the selection
511 if (lastNode) {
512 range = range.cloneRange();
513 range.setStartAfter(lastNode);
514 range.collapse(true);
515 sel.removeAllRanges();
516 sel.addRange(range);
517 }
518 }
519 }
520 };
521 NgxWigComponent.prototype.registerOnChange = function (fn) {
522 this.propagateChange = fn;
523 };
524 NgxWigComponent.prototype.registerOnTouched = function (fn) {
525 this.propagateTouched = fn;
526 };
527 NgxWigComponent.prototype.onBlur = function () {
528 this.hasFocus = false;
529 this.propagateTouched();
530 };
531 NgxWigComponent.prototype.setDisabledState = function (isDisabled) {
532 this.disabled = isDisabled;
533 };
534 NgxWigComponent.ɵfac = function NgxWigComponent_Factory(t) { return new (t || NgxWigComponent)(core["ɵɵdirectiveInject"](NgxWigToolbarService), core["ɵɵdirectiveInject"](common.DOCUMENT), core["ɵɵdirectiveInject"]('WINDOW')); };
535 NgxWigComponent.ɵcmp = core["ɵɵdefineComponent"]({ type: NgxWigComponent, selectors: [["ngx-wig"]], viewQuery: function NgxWigComponent_Query(rf, ctx) { if (rf & 1) {
536 core["ɵɵstaticViewQuery"](_c0, true, core.ElementRef);
537 } if (rf & 2) {
538 var _t;
539 core["ɵɵqueryRefresh"](_t = core["ɵɵloadQuery"]()) && (ctx.ngxWigEditable = _t.first);
540 } }, inputs: { content: "content", placeholder: "placeholder", buttons: "buttons", disabled: "disabled" }, outputs: { contentChange: "contentChange" }, features: [core["ɵɵProvidersFeature"]([
541 NgxWigToolbarService,
542 {
543 provide: forms.NG_VALUE_ACCESSOR,
544 useExisting: core.forwardRef(function () { return NgxWigComponent; }),
545 multi: true
546 }
547 ]), core["ɵɵNgOnChangesFeature"]], decls: 9, vars: 14, consts: [[1, "ng-wig"], [1, "nw-toolbar"], ["class", "nw-toolbar__item", 4, "ngFor", "ngForOf"], [1, "nw-editor-container", 3, "ngClass", "click"], ["class", "nw-editor__src-container", 4, "ngIf"], [1, "nw-editor", 3, "ngClass"], ["class", "nw-editor__placeholder", 3, "innerText", 4, "ngIf"], [1, "nw-editor__res", 3, "ngClass", "focus", "blur", "input"], ["ngWigEditable", ""], [1, "nw-toolbar__item"], ["type", "button", "tabindex", "-1", 1, "nw-button", 3, "ngClass", "title", "disabled", "click"], [4, "ngIf"], ["class", "icon", 3, "ngClass", 4, "ngIf"], [1, "icon", 3, "ngClass"], [1, "nw-editor__src-container"], [1, "nw-editor__src", 3, "ngModel", "ngModelChange", "blur"], [1, "nw-editor__placeholder", 3, "innerText"]], template: function NgxWigComponent_Template(rf, ctx) { if (rf & 1) {
548 var _r29 = core["ɵɵgetCurrentView"]();
549 core["ɵɵelementStart"](0, "div", 0);
550 core["ɵɵelementStart"](1, "ul", 1);
551 core["ɵɵtemplate"](2, NgxWigComponent_li_2_Template, 5, 7, "li", 2);
552 core["ɵɵelementEnd"]();
553 core["ɵɵelementStart"](3, "div", 3);
554 core["ɵɵlistener"]("click", function NgxWigComponent_Template_div_click_3_listener() { return ctx.container.focus(); });
555 core["ɵɵtemplate"](4, NgxWigComponent_div_4_Template, 3, 1, "div", 4);
556 core["ɵɵelementStart"](5, "div", 5);
557 core["ɵɵtemplate"](6, NgxWigComponent_div_6_Template, 1, 1, "div", 6);
558 core["ɵɵelementStart"](7, "div", 7, 8);
559 core["ɵɵlistener"]("focus", function NgxWigComponent_Template_div_focus_7_listener() { return ctx.hasFocus = true; })("blur", function NgxWigComponent_Template_div_blur_7_listener() { return ctx.onBlur(); })("input", function NgxWigComponent_Template_div_input_7_listener() { core["ɵɵrestoreView"](_r29); var _r18 = core["ɵɵreference"](8); return ctx.onContentChange(_r18.innerHTML); });
560 core["ɵɵelementEnd"]();
561 core["ɵɵelementEnd"]();
562 core["ɵɵelementEnd"]();
563 core["ɵɵelementEnd"]();
564 } if (rf & 2) {
565 core["ɵɵadvance"](2);
566 core["ɵɵproperty"]("ngForOf", ctx.toolbarButtons);
567 core["ɵɵadvance"](1);
568 core["ɵɵproperty"]("ngClass", core["ɵɵpureFunction1"](7, _c2, ctx.toolbarButtons.length));
569 core["ɵɵadvance"](1);
570 core["ɵɵproperty"]("ngIf", ctx.editMode);
571 core["ɵɵadvance"](1);
572 core["ɵɵproperty"]("ngClass", core["ɵɵpureFunction2"](9, _c3, ctx.disabled, ctx.editMode));
573 core["ɵɵadvance"](1);
574 core["ɵɵproperty"]("ngIf", ctx.shouldShowPlaceholder());
575 core["ɵɵadvance"](1);
576 core["ɵɵproperty"]("ngClass", core["ɵɵpureFunction1"](12, _c4, ctx.disabled));
577 core["ɵɵattribute"]("contenteditable", !ctx.disabled);
578 } }, directives: [common.NgForOf, common.NgClass, common.NgIf, forms.DefaultValueAccessor, forms.NgControlStatus, forms.NgModel], styles: [".ng-wig,[class^=nw-]{-o-box-sizing:border-box;-ms-box-sizing:border-box;box-sizing:border-box}.ng-wig{display:block;padding:0;margin:0}.nw-toolbar{display:block;margin:0;padding:0;list-style:none;font-size:12px;color:#6b7277;background:linear-gradient(180deg,#fff 0,#f9f9f9 100%);border:1px solid #ccc;border-radius:3px 3px 0 0}.nw-toolbar__item{display:inline-block;vertical-align:top;margin:0;border-right:1px solid #dedede}.nw-toolbar label{line-height:30px;display:inline-block;padding:0 6px 0 3px}.nw-toolbar input[type=checkbox]{vertical-align:-3px;margin-right:-1px}.nw-editor{display:block;position:relative;height:300px;background:#fff;cursor:text;width:100%;overflow-y:auto}.nw-editor-container{border:1px solid #ccc;border-radius:0 0 3px 3px;position:relative}.nw-editor-container--with-toolbar{border-top:none}.nw-editor__res{display:block;min-height:100%;padding:1px 8px}.nw-editor__placeholder{display:block;position:absolute;padding:1px 8px;color:#d3d3d3;width:100%}.nw-editor__res,.nw-editor__src{width:100%;outline:0;box-sizing:border-box;border:none;margin:0}.nw-editor__res.disabled{opacity:.5}.nw-editor__src-container{position:absolute;left:0;top:0;right:0;bottom:0}.nw-editor__src{height:100%;resize:none;padding:1px 8px}.nw-editor--fixed .nw-editor{display:block;overflow-y:auto}.nw-editor--fixed .nw-editor__res{padding:1px 8px;display:block}.nw-invisible{visibility:hidden}.nw-editor--fixed .nw-invisible{display:none}.nw-editor.nw-disabled{cursor:default}.nw-button{-webkit-appearance:none;-moz-appearance:none;appearance:none;display:block;width:30px;height:30px;margin:0;padding:0;opacity:.5;line-height:30px;background-color:transparent;background-position:center center;background-repeat:no-repeat;border:none;border-radius:2px;cursor:pointer}.nw-button:focus{outline:0;border-color:#d3d3d3;border-style:solid}.nw-button.nw-button--active,.nw-button:hover{opacity:1}.nw-button--active{background-color:#eee}.nw-button:disabled{cursor:default}.nw-button:disabled:hover{opacity:.5}.nw-content{padding:12px;margin:0;font-family:sans-serif;font-size:14px;line-height:24px}.nw-select{height:30px;padding:6px;color:#555;background-color:inherit;border:0}.nw-select:disabled{opacity:.5}.nw-select:focus{outline:0}[contenteditable]:empty:before{content:attr(placeholder);color:grey;display:inline-block}.icon{display:inline-block;height:1em;width:1em;vertical-align:-.125em}.icon-bold{background:url(\"data:image/svg+xml;charset=utf8,%3C?xml version='1.0' encoding='utf-8'?%3E%3Csvg width='11' height='11' viewBox='0 0 1792 1792' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M747 1521q74 32 140 32 376 0 376-335 0-114-41-180-27-44-61.5-74t-67.5-46.5-80.5-25-84-10.5-94.5-2q-73 0-101 10 0 53-.5 159t-.5 158q0 8-1 67.5t-.5 96.5 4.5 83.5 12 66.5zm-14-746q42 7 109 7 82 0 143-13t110-44.5 74.5-89.5 25.5-142q0-70-29-122.5t-79-82-108-43.5-124-14q-50 0-130 13 0 50 4 151t4 152q0 27-.5 80t-.5 79q0 46 1 69zm-541 889l2-94q15-4 85-16t106-27q7-12 12.5-27t8.5-33.5 5.5-32.5 3-37.5.5-34v-65.5q0-982-22-1025-4-8-22-14.5t-44.5-11-49.5-7-48.5-4.5-30.5-3l-4-83q98-2 340-11.5t373-9.5q23 0 68 .5t68 .5q70 0 136.5 13t128.5 42 108 71 74 104.5 28 137.5q0 52-16.5 95.5t-39 72-64.5 57.5-73 45-84 40q154 35 256.5 134t102.5 248q0 100-35 179.5t-93.5 130.5-138 85.5-163.5 48.5-176 14q-44 0-132-3t-132-3q-106 0-307 11t-231 12z'/%3E%3C/svg%3E\") no-repeat}.icon-check{background:url(\"data:image/svg+xml;charset=utf8,%3C?xml version='1.0' encoding='utf-8'?%3E%3Csvg width='11' height='11' viewBox='0 0 1792 1792' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1671 566q0 40-28 68l-724 724-136 136q-28 28-68 28t-68-28l-136-136-362-362q-28-28-28-68t28-68l136-136q28-28 68-28t68 28l294 295 656-657q28-28 68-28t68 28l136 136q28 28 28 68z'/%3E%3C/svg%3E\") no-repeat}.icon-italic{background:url(\"data:image/svg+xml;charset=utf8,%3C?xml version='1.0' encoding='utf-8'?%3E%3Csvg width='11' height='11' viewBox='0 0 1792 1792' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M384 1662l17-85q22-7 61.5-16.5t72-19 59.5-23.5q28-35 41-101 1-7 62-289t114-543.5 52-296.5v-25q-24-13-54.5-18.5t-69.5-8-58-5.5l19-103q33 2 120 6.5t149.5 7 120.5 2.5q48 0 98.5-2.5t121-7 98.5-6.5q-5 39-19 89-30 10-101.5 28.5t-108.5 33.5q-8 19-14 42.5t-9 40-7.5 45.5-6.5 42q-27 148-87.5 419.5t-77.5 355.5q-2 9-13 58t-20 90-16 83.5-6 57.5l1 18q17 4 185 31-3 44-16 99-11 0-32.5 1.5t-32.5 1.5q-29 0-87-10t-86-10q-138-2-206-2-51 0-143 9t-121 11z'/%3E%3C/svg%3E\") no-repeat}.icon-link{background:url(\"data:image/svg+xml;charset=utf8,%3C?xml version='1.0' encoding='utf-8'?%3E%3Csvg width='11' height='11' viewBox='0 0 1792 1792' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1520 1216q0-40-28-68l-208-208q-28-28-68-28-42 0-72 32 3 3 19 18.5t21.5 21.5 15 19 13 25.5 3.5 27.5q0 40-28 68t-68 28q-15 0-27.5-3.5t-25.5-13-19-15-21.5-21.5-18.5-19q-33 31-33 73 0 40 28 68l206 207q27 27 68 27 40 0 68-26l147-146q28-28 28-67zm-703-705q0-40-28-68l-206-207q-28-28-68-28-39 0-68 27l-147 146q-28 28-28 67 0 40 28 68l208 208q27 27 68 27 42 0 72-31-3-3-19-18.5t-21.5-21.5-15-19-13-25.5-3.5-27.5q0-40 28-68t68-28q15 0 27.5 3.5t25.5 13 19 15 21.5 21.5 18.5 19q33-31 33-73zm895 705q0 120-85 203l-147 146q-83 83-203 83-121 0-204-85l-206-207q-83-83-83-203 0-123 88-209l-88-88q-86 88-208 88-120 0-204-84l-208-208q-84-84-84-204t85-203l147-146q83-83 203-83 121 0 204 85l206 207q83 83 83 203 0 123-88 209l88 88q86-88 208-88 120 0 204 84l208 208q84 84 84 204z'/%3E%3C/svg%3E\") no-repeat}.icon-list-ol{background:url(\"data:image/svg+xml;charset=utf8,%3C?xml version='1.0' encoding='utf-8'?%3E%3Csvg width='11' height='11' viewBox='0 0 1792 1792' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M381 1620q0 80-54.5 126t-135.5 46q-106 0-172-66l57-88q49 45 106 45 29 0 50.5-14.5t21.5-42.5q0-64-105-56l-26-56q8-10 32.5-43.5t42.5-54 37-38.5v-1q-16 0-48.5 1t-48.5 1v53h-106v-152h333v88l-95 115q51 12 81 49t30 88zm2-627v159h-362q-6-36-6-54 0-51 23.5-93t56.5-68 66-47.5 56.5-43.5 23.5-45q0-25-14.5-38.5t-39.5-13.5q-46 0-81 58l-85-59q24-51 71.5-79.5t105.5-28.5q73 0 123 41.5t50 112.5q0 50-34 91.5t-75 64.5-75.5 50.5-35.5 52.5h127v-60h105zm1409 319v192q0 13-9.5 22.5t-22.5 9.5h-1216q-13 0-22.5-9.5t-9.5-22.5v-192q0-14 9-23t23-9h1216q13 0 22.5 9.5t9.5 22.5zm-1408-899v99h-335v-99h107q0-41 .5-121.5t.5-121.5v-12h-2q-8 17-50 54l-71-76 136-127h106v404h108zm1408 387v192q0 13-9.5 22.5t-22.5 9.5h-1216q-13 0-22.5-9.5t-9.5-22.5v-192q0-14 9-23t23-9h1216q13 0 22.5 9.5t9.5 22.5zm0-512v192q0 13-9.5 22.5t-22.5 9.5h-1216q-13 0-22.5-9.5t-9.5-22.5v-192q0-13 9.5-22.5t22.5-9.5h1216q13 0 22.5 9.5t9.5 22.5z'/%3E%3C/svg%3E\") no-repeat}.icon-list-ul{background:url(\"data:image/svg+xml;charset=utf8,%3C?xml version='1.0' encoding='utf-8'?%3E%3Csvg width='11' height='11' viewBox='0 0 1792 1792' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M384 1408q0 80-56 136t-136 56-136-56-56-136 56-136 136-56 136 56 56 136zm0-512q0 80-56 136t-136 56-136-56-56-136 56-136 136-56 136 56 56 136zm1408 416v192q0 13-9.5 22.5t-22.5 9.5h-1216q-13 0-22.5-9.5t-9.5-22.5v-192q0-13 9.5-22.5t22.5-9.5h1216q13 0 22.5 9.5t9.5 22.5zm-1408-928q0 80-56 136t-136 56-136-56-56-136 56-136 136-56 136 56 56 136zm1408 416v192q0 13-9.5 22.5t-22.5 9.5h-1216q-13 0-22.5-9.5t-9.5-22.5v-192q0-13 9.5-22.5t22.5-9.5h1216q13 0 22.5 9.5t9.5 22.5zm0-512v192q0 13-9.5 22.5t-22.5 9.5h-1216q-13 0-22.5-9.5t-9.5-22.5v-192q0-13 9.5-22.5t22.5-9.5h1216q13 0 22.5 9.5t9.5 22.5z'/%3E%3C/svg%3E\") no-repeat}.icon-underline{background:url(\"data:image/svg+xml;charset=utf8,%3C?xml version='1.0' encoding='utf-8'?%3E%3Csvg width='11' height='11' viewBox='0 0 1792 1792' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M176 223q-37-2-45-4l-3-88q13-1 40-1 60 0 112 4 132 7 166 7 86 0 168-3 116-4 146-5 56 0 86-2l-1 14 2 64v9q-60 9-124 9-60 0-79 25-13 14-13 132 0 13 .5 32.5t.5 25.5l1 229 14 280q6 124 51 202 35 59 96 92 88 47 177 47 104 0 191-28 56-18 99-51 48-36 65-64 36-56 53-114 21-73 21-229 0-79-3.5-128t-11-122.5-13.5-159.5l-4-59q-5-67-24-88-34-35-77-34l-100 2-14-3 2-86h84l205 10q76 3 196-10l18 2q6 38 6 51 0 7-4 31-45 12-84 13-73 11-79 17-15 15-15 41 0 7 1.5 27t1.5 31q8 19 22 396 6 195-15 304-15 76-41 122-38 65-112 123-75 57-182 89-109 33-255 33-167 0-284-46-119-47-179-122-61-76-83-195-16-80-16-237v-333q0-188-17-213-25-36-147-39zm1488 1409v-64q0-14-9-23t-23-9h-1472q-14 0-23 9t-9 23v64q0 14 9 23t23 9h1472q14 0 23-9t9-23z'/%3E%3C/svg%3E\") no-repeat}"], encapsulation: 2 });
579 return NgxWigComponent;
580 }());
581 /*@__PURE__*/ (function () { core["ɵsetClassMetadata"](NgxWigComponent, [{
582 type: core.Component,
583 args: [{
584 selector: 'ngx-wig',
585 templateUrl: './ngx-wig-component.html',
586 styleUrls: ['./ngx-wig-component.css'],
587 providers: [
588 NgxWigToolbarService,
589 {
590 provide: forms.NG_VALUE_ACCESSOR,
591 useExisting: core.forwardRef(function () { return NgxWigComponent; }),
592 multi: true
593 }
594 ],
595 encapsulation: core.ViewEncapsulation.None
596 }]
597 }], function () { return [{ type: NgxWigToolbarService }, { type: undefined, decorators: [{
598 type: core.Inject,
599 args: [common.DOCUMENT]
600 }] }, { type: undefined, decorators: [{
601 type: core.Inject,
602 args: ['WINDOW']
603 }] }]; }, { content: [{
604 type: core.Input
605 }], placeholder: [{
606 type: core.Input
607 }], buttons: [{
608 type: core.Input
609 }], disabled: [{
610 type: core.Input
611 }], contentChange: [{
612 type: core.Output
613 }], ngxWigEditable: [{
614 type: core.ViewChild,
615 args: ['ngWigEditable', { read: core.ElementRef, static: true }]
616 }] }); })();
617
618 function getWindowObject() {
619 return window;
620 }
621 var NgxWigModule = /** @class */ (function () {
622 function NgxWigModule() {
623 }
624 NgxWigModule.forRoot = function (config) {
625 return {
626 ngModule: NgxWigModule,
627 providers: [
628 {
629 provide: BUTTONS,
630 multi: true, useValue: ((!config || !(config === null || config === void 0 ? void 0 : config.buttonsConfig)) ? DEFAULT_LIBRARY_BUTTONS : config === null || config === void 0 ? void 0 : config.buttonsConfig)
631 },
632 { provide: 'WINDOW', useFactory: getWindowObject },
633 ],
634 };
635 };
636 NgxWigModule.forChild = function () {
637 return { ngModule: NgxWigModule };
638 };
639 NgxWigModule.ɵmod = core["ɵɵdefineNgModule"]({ type: NgxWigModule });
640 NgxWigModule.ɵinj = core["ɵɵdefineInjector"]({ factory: function NgxWigModule_Factory(t) { return new (t || NgxWigModule)(); }, providers: [
641 { provide: BUTTONS, multi: true, useValue: DEFAULT_LIBRARY_BUTTONS },
642 { provide: 'WINDOW', useFactory: getWindowObject },
643 ], imports: [[
644 common.CommonModule,
645 forms.FormsModule,
646 ]] });
647 return NgxWigModule;
648 }());
649 (function () { (typeof ngJitMode === "undefined" || ngJitMode) && core["ɵɵsetNgModuleScope"](NgxWigModule, { declarations: [NgxWigComponent], imports: [common.CommonModule,
650 forms.FormsModule], exports: [NgxWigComponent] }); })();
651 /*@__PURE__*/ (function () { core["ɵsetClassMetadata"](NgxWigModule, [{
652 type: core.NgModule,
653 args: [{
654 declarations: [
655 NgxWigComponent
656 ],
657 imports: [
658 common.CommonModule,
659 forms.FormsModule,
660 ],
661 exports: [NgxWigComponent],
662 providers: [
663 { provide: BUTTONS, multi: true, useValue: DEFAULT_LIBRARY_BUTTONS },
664 { provide: 'WINDOW', useFactory: getWindowObject },
665 ]
666 }]
667 }], null, null); })();
668
669 exports.BUTTONS = BUTTONS;
670 exports.CUSTOM_LIBRARY_BUTTONS = CUSTOM_LIBRARY_BUTTONS;
671 exports.DEFAULT_LIBRARY_BUTTONS = DEFAULT_LIBRARY_BUTTONS;
672 exports.NgxWigComponent = NgxWigComponent;
673 exports.NgxWigModule = NgxWigModule;
674 exports.NgxWigToolbarService = NgxWigToolbarService;
675 exports.getWindowObject = getWindowObject;
676
677 Object.defineProperty(exports, '__esModule', { value: true });
678
679})));
680//# sourceMappingURL=ngx-wig.umd.js.map