vue2-editor.core.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. /*!
  2. * vue2-editor v2.10.3
  3. * (c) 2021 David Royer
  4. * Released under the MIT License.
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('quill')) :
  8. typeof define === 'function' && define.amd ? define(['exports', 'quill'], factory) :
  9. (global = global || self, factory(global.Vue2Editor = {}, global.Quill));
  10. }(this, function (exports, Quill) { 'use strict';
  11. Quill = Quill && Quill.hasOwnProperty('default') ? Quill['default'] : Quill;
  12. var defaultToolbar = [[{
  13. header: [false, 1, 2, 3, 4, 5, 6]
  14. }], ["bold", "italic", "underline", "strike"], // toggled buttons
  15. [{
  16. align: ""
  17. }, {
  18. align: "center"
  19. }, {
  20. align: "right"
  21. }, {
  22. align: "justify"
  23. }], ["blockquote", "code-block"], [{
  24. list: "ordered"
  25. }, {
  26. list: "bullet"
  27. }, {
  28. list: "check"
  29. }], [{
  30. indent: "-1"
  31. }, {
  32. indent: "+1"
  33. }], // outdent/indent
  34. [{
  35. color: []
  36. }, {
  37. background: []
  38. }], // dropdown with defaults from theme
  39. ["link", "image", "video"], ["clean"] // remove formatting button
  40. ];
  41. var oldApi = {
  42. props: {
  43. customModules: Array
  44. },
  45. methods: {
  46. registerCustomModules: function registerCustomModules(Quill) {
  47. if (this.customModules !== undefined) {
  48. this.customModules.forEach(function (customModule) {
  49. Quill.register("modules/" + customModule.alias, customModule.module);
  50. });
  51. }
  52. }
  53. }
  54. };
  55. function _typeof(obj) {
  56. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  57. _typeof = function (obj) {
  58. return typeof obj;
  59. };
  60. } else {
  61. _typeof = function (obj) {
  62. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  63. };
  64. }
  65. return _typeof(obj);
  66. }
  67. function _classCallCheck(instance, Constructor) {
  68. if (!(instance instanceof Constructor)) {
  69. throw new TypeError("Cannot call a class as a function");
  70. }
  71. }
  72. function _defineProperties(target, props) {
  73. for (var i = 0; i < props.length; i++) {
  74. var descriptor = props[i];
  75. descriptor.enumerable = descriptor.enumerable || false;
  76. descriptor.configurable = true;
  77. if ("value" in descriptor) descriptor.writable = true;
  78. Object.defineProperty(target, descriptor.key, descriptor);
  79. }
  80. }
  81. function _createClass(Constructor, protoProps, staticProps) {
  82. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  83. if (staticProps) _defineProperties(Constructor, staticProps);
  84. return Constructor;
  85. }
  86. function _inherits(subClass, superClass) {
  87. if (typeof superClass !== "function" && superClass !== null) {
  88. throw new TypeError("Super expression must either be null or a function");
  89. }
  90. subClass.prototype = Object.create(superClass && superClass.prototype, {
  91. constructor: {
  92. value: subClass,
  93. writable: true,
  94. configurable: true
  95. }
  96. });
  97. if (superClass) _setPrototypeOf(subClass, superClass);
  98. }
  99. function _getPrototypeOf(o) {
  100. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
  101. return o.__proto__ || Object.getPrototypeOf(o);
  102. };
  103. return _getPrototypeOf(o);
  104. }
  105. function _setPrototypeOf(o, p) {
  106. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  107. o.__proto__ = p;
  108. return o;
  109. };
  110. return _setPrototypeOf(o, p);
  111. }
  112. function _assertThisInitialized(self) {
  113. if (self === void 0) {
  114. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  115. }
  116. return self;
  117. }
  118. function _possibleConstructorReturn(self, call) {
  119. if (call && (typeof call === "object" || typeof call === "function")) {
  120. return call;
  121. }
  122. return _assertThisInitialized(self);
  123. }
  124. function _slicedToArray(arr, i) {
  125. return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
  126. }
  127. function _arrayWithHoles(arr) {
  128. if (Array.isArray(arr)) return arr;
  129. }
  130. function _iterableToArrayLimit(arr, i) {
  131. var _arr = [];
  132. var _n = true;
  133. var _d = false;
  134. var _e = undefined;
  135. try {
  136. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  137. _arr.push(_s.value);
  138. if (i && _arr.length === i) break;
  139. }
  140. } catch (err) {
  141. _d = true;
  142. _e = err;
  143. } finally {
  144. try {
  145. if (!_n && _i["return"] != null) _i["return"]();
  146. } finally {
  147. if (_d) throw _e;
  148. }
  149. }
  150. return _arr;
  151. }
  152. function _nonIterableRest() {
  153. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  154. }
  155. /**
  156. * Performs a deep merge of `source` into `target`.
  157. * Mutates `target` only but not its objects and arrays.
  158. *
  159. */
  160. function mergeDeep(target, source) {
  161. var isObject = function isObject(obj) {
  162. return obj && _typeof(obj) === "object";
  163. };
  164. if (!isObject(target) || !isObject(source)) {
  165. return source;
  166. }
  167. Object.keys(source).forEach(function (key) {
  168. var targetValue = target[key];
  169. var sourceValue = source[key];
  170. if (Array.isArray(targetValue) && Array.isArray(sourceValue)) {
  171. target[key] = targetValue.concat(sourceValue);
  172. } else if (isObject(targetValue) && isObject(sourceValue)) {
  173. target[key] = mergeDeep(Object.assign({}, targetValue), sourceValue);
  174. } else {
  175. target[key] = sourceValue;
  176. }
  177. });
  178. return target;
  179. }
  180. var BlockEmbed = Quill.import("blots/block/embed");
  181. var HorizontalRule =
  182. /*#__PURE__*/
  183. function (_BlockEmbed) {
  184. _inherits(HorizontalRule, _BlockEmbed);
  185. function HorizontalRule() {
  186. _classCallCheck(this, HorizontalRule);
  187. return _possibleConstructorReturn(this, _getPrototypeOf(HorizontalRule).apply(this, arguments));
  188. }
  189. return HorizontalRule;
  190. }(BlockEmbed);
  191. HorizontalRule.blotName = "hr";
  192. HorizontalRule.tagName = "hr";
  193. Quill.register("formats/horizontal", HorizontalRule);
  194. var MarkdownShortcuts =
  195. /*#__PURE__*/
  196. function () {
  197. function MarkdownShortcuts(quill, options) {
  198. var _this = this;
  199. _classCallCheck(this, MarkdownShortcuts);
  200. this.quill = quill;
  201. this.options = options;
  202. this.ignoreTags = ["PRE"];
  203. this.matches = [{
  204. name: "header",
  205. pattern: /^(#){1,6}\s/g,
  206. action: function action(text, selection, pattern) {
  207. var match = pattern.exec(text);
  208. if (!match) return;
  209. var size = match[0].length; // Need to defer this action https://github.com/quilljs/quill/issues/1134
  210. setTimeout(function () {
  211. _this.quill.formatLine(selection.index, 0, "header", size - 1);
  212. _this.quill.deleteText(selection.index - size, size);
  213. }, 0);
  214. }
  215. }, {
  216. name: "blockquote",
  217. pattern: /^(>)\s/g,
  218. action: function action(_text, selection) {
  219. // Need to defer this action https://github.com/quilljs/quill/issues/1134
  220. setTimeout(function () {
  221. _this.quill.formatLine(selection.index, 1, "blockquote", true);
  222. _this.quill.deleteText(selection.index - 2, 2);
  223. }, 0);
  224. }
  225. }, {
  226. name: "code-block",
  227. pattern: /^`{3}(?:\s|\n)/g,
  228. action: function action(_text, selection) {
  229. // Need to defer this action https://github.com/quilljs/quill/issues/1134
  230. setTimeout(function () {
  231. _this.quill.formatLine(selection.index, 1, "code-block", true);
  232. _this.quill.deleteText(selection.index - 4, 4);
  233. }, 0);
  234. }
  235. }, {
  236. name: "bolditalic",
  237. pattern: /(?:\*|_){3}(.+?)(?:\*|_){3}/g,
  238. action: function action(text, _selection, pattern, lineStart) {
  239. var match = pattern.exec(text);
  240. var annotatedText = match[0];
  241. var matchedText = match[1];
  242. var startIndex = lineStart + match.index;
  243. if (text.match(/^([*_ \n]+)$/g)) return;
  244. setTimeout(function () {
  245. _this.quill.deleteText(startIndex, annotatedText.length);
  246. _this.quill.insertText(startIndex, matchedText, {
  247. bold: true,
  248. italic: true
  249. });
  250. _this.quill.format("bold", false);
  251. }, 0);
  252. }
  253. }, {
  254. name: "bold",
  255. pattern: /(?:\*|_){2}(.+?)(?:\*|_){2}/g,
  256. action: function action(text, _selection, pattern, lineStart) {
  257. var match = pattern.exec(text);
  258. var annotatedText = match[0];
  259. var matchedText = match[1];
  260. var startIndex = lineStart + match.index;
  261. if (text.match(/^([*_ \n]+)$/g)) return;
  262. setTimeout(function () {
  263. _this.quill.deleteText(startIndex, annotatedText.length);
  264. _this.quill.insertText(startIndex, matchedText, {
  265. bold: true
  266. });
  267. _this.quill.format("bold", false);
  268. }, 0);
  269. }
  270. }, {
  271. name: "italic",
  272. pattern: /(?:\*|_){1}(.+?)(?:\*|_){1}/g,
  273. action: function action(text, _selection, pattern, lineStart) {
  274. var match = pattern.exec(text);
  275. var annotatedText = match[0];
  276. var matchedText = match[1];
  277. var startIndex = lineStart + match.index;
  278. if (text.match(/^([*_ \n]+)$/g)) return;
  279. setTimeout(function () {
  280. _this.quill.deleteText(startIndex, annotatedText.length);
  281. _this.quill.insertText(startIndex, matchedText, {
  282. italic: true
  283. });
  284. _this.quill.format("italic", false);
  285. }, 0);
  286. }
  287. }, {
  288. name: "strikethrough",
  289. pattern: /(?:~~)(.+?)(?:~~)/g,
  290. action: function action(text, _selection, pattern, lineStart) {
  291. var match = pattern.exec(text);
  292. var annotatedText = match[0];
  293. var matchedText = match[1];
  294. var startIndex = lineStart + match.index;
  295. if (text.match(/^([*_ \n]+)$/g)) return;
  296. setTimeout(function () {
  297. _this.quill.deleteText(startIndex, annotatedText.length);
  298. _this.quill.insertText(startIndex, matchedText, {
  299. strike: true
  300. });
  301. _this.quill.format("strike", false);
  302. }, 0);
  303. }
  304. }, {
  305. name: "code",
  306. pattern: /(?:`)(.+?)(?:`)/g,
  307. action: function action(text, _selection, pattern, lineStart) {
  308. var match = pattern.exec(text);
  309. var annotatedText = match[0];
  310. var matchedText = match[1];
  311. var startIndex = lineStart + match.index;
  312. if (text.match(/^([*_ \n]+)$/g)) return;
  313. setTimeout(function () {
  314. _this.quill.deleteText(startIndex, annotatedText.length);
  315. _this.quill.insertText(startIndex, matchedText, {
  316. code: true
  317. });
  318. _this.quill.format("code", false);
  319. _this.quill.insertText(_this.quill.getSelection(), " ");
  320. }, 0);
  321. }
  322. }, {
  323. name: "hr",
  324. pattern: /^([-*]\s?){3}/g,
  325. action: function action(text, selection) {
  326. var startIndex = selection.index - text.length;
  327. setTimeout(function () {
  328. _this.quill.deleteText(startIndex, text.length);
  329. _this.quill.insertEmbed(startIndex + 1, "hr", true, Quill.sources.USER);
  330. _this.quill.insertText(startIndex + 2, "\n", Quill.sources.SILENT);
  331. _this.quill.setSelection(startIndex + 2, Quill.sources.SILENT);
  332. }, 0);
  333. }
  334. }, {
  335. name: "asterisk-ul",
  336. pattern: /^(\*|\+)\s$/g,
  337. // eslint-disable-next-line no-unused-vars
  338. action: function action(_text, selection, _pattern) {
  339. setTimeout(function () {
  340. _this.quill.formatLine(selection.index, 1, "list", "unordered");
  341. _this.quill.deleteText(selection.index - 2, 2);
  342. }, 0);
  343. }
  344. }, {
  345. name: "image",
  346. pattern: /(?:!\[(.+?)\])(?:\((.+?)\))/g,
  347. action: function action(text, selection, pattern) {
  348. var startIndex = text.search(pattern);
  349. var matchedText = text.match(pattern)[0]; // const hrefText = text.match(/(?:!\[(.*?)\])/g)[0]
  350. var hrefLink = text.match(/(?:\((.*?)\))/g)[0];
  351. var start = selection.index - matchedText.length - 1;
  352. if (startIndex !== -1) {
  353. setTimeout(function () {
  354. _this.quill.deleteText(start, matchedText.length);
  355. _this.quill.insertEmbed(start, "image", hrefLink.slice(1, hrefLink.length - 1));
  356. }, 0);
  357. }
  358. }
  359. }, {
  360. name: "link",
  361. pattern: /(?:\[(.+?)\])(?:\((.+?)\))/g,
  362. action: function action(text, selection, pattern) {
  363. var startIndex = text.search(pattern);
  364. var matchedText = text.match(pattern)[0];
  365. var hrefText = text.match(/(?:\[(.*?)\])/g)[0];
  366. var hrefLink = text.match(/(?:\((.*?)\))/g)[0];
  367. var start = selection.index - matchedText.length - 1;
  368. if (startIndex !== -1) {
  369. setTimeout(function () {
  370. _this.quill.deleteText(start, matchedText.length);
  371. _this.quill.insertText(start, hrefText.slice(1, hrefText.length - 1), "link", hrefLink.slice(1, hrefLink.length - 1));
  372. }, 0);
  373. }
  374. }
  375. }]; // Handler that looks for insert deltas that match specific characters
  376. // eslint-disable-next-line no-unused-vars
  377. this.quill.on("text-change", function (delta, _oldContents, _source) {
  378. for (var i = 0; i < delta.ops.length; i++) {
  379. if (delta.ops[i].hasOwnProperty("insert")) {
  380. if (delta.ops[i].insert === " ") {
  381. _this.onSpace();
  382. } else if (delta.ops[i].insert === "\n") {
  383. _this.onEnter();
  384. }
  385. }
  386. }
  387. });
  388. }
  389. _createClass(MarkdownShortcuts, [{
  390. key: "isValid",
  391. value: function isValid(text, tagName) {
  392. return typeof text !== "undefined" && text && this.ignoreTags.indexOf(tagName) === -1;
  393. }
  394. }, {
  395. key: "onSpace",
  396. value: function onSpace() {
  397. var selection = this.quill.getSelection();
  398. if (!selection) return;
  399. var _this$quill$getLine = this.quill.getLine(selection.index),
  400. _this$quill$getLine2 = _slicedToArray(_this$quill$getLine, 2),
  401. line = _this$quill$getLine2[0],
  402. offset = _this$quill$getLine2[1];
  403. var text = line.domNode.textContent;
  404. var lineStart = selection.index - offset;
  405. if (this.isValid(text, line.domNode.tagName)) {
  406. var _iteratorNormalCompletion = true;
  407. var _didIteratorError = false;
  408. var _iteratorError = undefined;
  409. try {
  410. for (var _iterator = this.matches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  411. var match = _step.value;
  412. var matchedText = text.match(match.pattern);
  413. if (matchedText) {
  414. // We need to replace only matched text not the whole line
  415. console.log("matched:", match.name, text);
  416. match.action(text, selection, match.pattern, lineStart);
  417. return;
  418. }
  419. }
  420. } catch (err) {
  421. _didIteratorError = true;
  422. _iteratorError = err;
  423. } finally {
  424. try {
  425. if (!_iteratorNormalCompletion && _iterator.return != null) {
  426. _iterator.return();
  427. }
  428. } finally {
  429. if (_didIteratorError) {
  430. throw _iteratorError;
  431. }
  432. }
  433. }
  434. }
  435. }
  436. }, {
  437. key: "onEnter",
  438. value: function onEnter() {
  439. var selection = this.quill.getSelection();
  440. if (!selection) return;
  441. var _this$quill$getLine3 = this.quill.getLine(selection.index),
  442. _this$quill$getLine4 = _slicedToArray(_this$quill$getLine3, 2),
  443. line = _this$quill$getLine4[0],
  444. offset = _this$quill$getLine4[1];
  445. var text = line.domNode.textContent + " ";
  446. var lineStart = selection.index - offset;
  447. selection.length = selection.index++;
  448. if (this.isValid(text, line.domNode.tagName)) {
  449. var _iteratorNormalCompletion2 = true;
  450. var _didIteratorError2 = false;
  451. var _iteratorError2 = undefined;
  452. try {
  453. for (var _iterator2 = this.matches[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  454. var match = _step2.value;
  455. var matchedText = text.match(match.pattern);
  456. if (matchedText) {
  457. console.log("matched", match.name, text);
  458. match.action(text, selection, match.pattern, lineStart);
  459. return;
  460. }
  461. }
  462. } catch (err) {
  463. _didIteratorError2 = true;
  464. _iteratorError2 = err;
  465. } finally {
  466. try {
  467. if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
  468. _iterator2.return();
  469. }
  470. } finally {
  471. if (_didIteratorError2) {
  472. throw _iteratorError2;
  473. }
  474. }
  475. }
  476. }
  477. }
  478. }]);
  479. return MarkdownShortcuts;
  480. }(); // module.exports = MarkdownShortcuts;
  481. //
  482. var script = {
  483. name: "VueEditor",
  484. mixins: [oldApi],
  485. props: {
  486. id: {
  487. type: String,
  488. default: "quill-container"
  489. },
  490. placeholder: {
  491. type: String,
  492. default: ""
  493. },
  494. value: {
  495. type: String,
  496. default: ""
  497. },
  498. disabled: {
  499. type: Boolean
  500. },
  501. editorToolbar: {
  502. type: Array,
  503. default: function _default() {
  504. return [];
  505. }
  506. },
  507. editorOptions: {
  508. type: Object,
  509. required: false,
  510. default: function _default() {
  511. return {};
  512. }
  513. },
  514. useCustomImageHandler: {
  515. type: Boolean,
  516. default: false
  517. },
  518. useMarkdownShortcuts: {
  519. type: Boolean,
  520. default: false
  521. }
  522. },
  523. data: function data() {
  524. return {
  525. quill: null
  526. };
  527. },
  528. watch: {
  529. value: function value(val) {
  530. if (val != this.quill.root.innerHTML && !this.quill.hasFocus()) {
  531. this.quill.root.innerHTML = val;
  532. }
  533. },
  534. disabled: function disabled(status) {
  535. this.quill.enable(!status);
  536. }
  537. },
  538. mounted: function mounted() {
  539. this.registerCustomModules(Quill);
  540. this.registerPrototypes();
  541. this.initializeEditor();
  542. },
  543. beforeDestroy: function beforeDestroy() {
  544. this.quill = null;
  545. delete this.quill;
  546. },
  547. methods: {
  548. initializeEditor: function initializeEditor() {
  549. this.setupQuillEditor();
  550. this.checkForCustomImageHandler();
  551. this.handleInitialContent();
  552. this.registerEditorEventListeners();
  553. this.$emit("ready", this.quill);
  554. },
  555. setupQuillEditor: function setupQuillEditor() {
  556. var editorConfig = {
  557. debug: false,
  558. modules: this.setModules(),
  559. theme: "snow",
  560. placeholder: this.placeholder ? this.placeholder : "",
  561. readOnly: this.disabled ? this.disabled : false
  562. };
  563. this.prepareEditorConfig(editorConfig);
  564. this.quill = new Quill(this.$refs.quillContainer, editorConfig);
  565. },
  566. setModules: function setModules() {
  567. var modules = {
  568. toolbar: this.editorToolbar.length ? this.editorToolbar : defaultToolbar
  569. };
  570. if (this.useMarkdownShortcuts) {
  571. Quill.register("modules/markdownShortcuts", MarkdownShortcuts, true);
  572. modules["markdownShortcuts"] = {};
  573. }
  574. return modules;
  575. },
  576. prepareEditorConfig: function prepareEditorConfig(editorConfig) {
  577. if (Object.keys(this.editorOptions).length > 0 && this.editorOptions.constructor === Object) {
  578. if (this.editorOptions.modules && typeof this.editorOptions.modules.toolbar !== "undefined") {
  579. // We don't want to merge default toolbar with provided toolbar.
  580. delete editorConfig.modules.toolbar;
  581. }
  582. mergeDeep(editorConfig, this.editorOptions);
  583. }
  584. },
  585. registerPrototypes: function registerPrototypes() {
  586. Quill.prototype.getHTML = function () {
  587. return this.container.querySelector(".ql-editor").innerHTML;
  588. };
  589. Quill.prototype.getWordCount = function () {
  590. return this.container.querySelector(".ql-editor").innerText.length;
  591. };
  592. },
  593. registerEditorEventListeners: function registerEditorEventListeners() {
  594. this.quill.on("text-change", this.handleTextChange);
  595. this.quill.on("selection-change", this.handleSelectionChange);
  596. this.listenForEditorEvent("text-change");
  597. this.listenForEditorEvent("selection-change");
  598. this.listenForEditorEvent("editor-change");
  599. },
  600. listenForEditorEvent: function listenForEditorEvent(type) {
  601. var _this = this;
  602. this.quill.on(type, function () {
  603. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  604. args[_key] = arguments[_key];
  605. }
  606. _this.$emit.apply(_this, [type].concat(args));
  607. });
  608. },
  609. handleInitialContent: function handleInitialContent() {
  610. if (this.value) this.quill.root.innerHTML = this.value; // Set initial editor content
  611. },
  612. handleSelectionChange: function handleSelectionChange(range, oldRange) {
  613. if (!range && oldRange) this.$emit("blur", this.quill);else if (range && !oldRange) this.$emit("focus", this.quill);
  614. },
  615. handleTextChange: function handleTextChange(delta, oldContents) {
  616. var editorContent = this.quill.getHTML() === "<p><br></p>" ? "" : this.quill.getHTML();
  617. this.$emit("input", editorContent);
  618. if (this.useCustomImageHandler) this.handleImageRemoved(delta, oldContents);
  619. },
  620. handleImageRemoved: function handleImageRemoved(delta, oldContents) {
  621. var _this2 = this;
  622. var currrentContents = this.quill.getContents();
  623. var deletedContents = currrentContents.diff(oldContents);
  624. var operations = deletedContents.ops;
  625. operations.map(function (operation) {
  626. if (operation.insert && operation.insert.hasOwnProperty("image")) {
  627. var image = operation.insert.image;
  628. _this2.$emit("image-removed", image);
  629. }
  630. });
  631. },
  632. checkForCustomImageHandler: function checkForCustomImageHandler() {
  633. this.useCustomImageHandler === true ? this.setupCustomImageHandler() : "";
  634. },
  635. setupCustomImageHandler: function setupCustomImageHandler() {
  636. var toolbar = this.quill.getModule("toolbar");
  637. toolbar.addHandler("image", this.customImageHandler);
  638. },
  639. customImageHandler: function customImageHandler() {
  640. this.$refs.fileInput.click();
  641. },
  642. emitImageInfo: function emitImageInfo($event) {
  643. var resetUploader = function resetUploader() {
  644. var uploader = document.getElementById("file-upload");
  645. uploader.value = "";
  646. };
  647. var file = $event.target.files[0];
  648. var Editor = this.quill;
  649. var range = Editor.getSelection();
  650. var cursorLocation = range.index;
  651. this.$emit("image-added", file, Editor, cursorLocation, resetUploader);
  652. }
  653. }
  654. };
  655. function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier
  656. /* server only */
  657. , shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
  658. if (typeof shadowMode !== 'boolean') {
  659. createInjectorSSR = createInjector;
  660. createInjector = shadowMode;
  661. shadowMode = false;
  662. } // Vue.extend constructor export interop.
  663. var options = typeof script === 'function' ? script.options : script; // render functions
  664. if (template && template.render) {
  665. options.render = template.render;
  666. options.staticRenderFns = template.staticRenderFns;
  667. options._compiled = true; // functional template
  668. if (isFunctionalTemplate) {
  669. options.functional = true;
  670. }
  671. } // scopedId
  672. if (scopeId) {
  673. options._scopeId = scopeId;
  674. }
  675. var hook;
  676. if (moduleIdentifier) {
  677. // server build
  678. hook = function hook(context) {
  679. // 2.3 injection
  680. context = context || // cached call
  681. this.$vnode && this.$vnode.ssrContext || // stateful
  682. this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext; // functional
  683. // 2.2 with runInNewContext: true
  684. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  685. context = __VUE_SSR_CONTEXT__;
  686. } // inject component styles
  687. if (style) {
  688. style.call(this, createInjectorSSR(context));
  689. } // register component module identifier for async chunk inference
  690. if (context && context._registeredComponents) {
  691. context._registeredComponents.add(moduleIdentifier);
  692. }
  693. }; // used by ssr in case component is cached and beforeCreate
  694. // never gets called
  695. options._ssrRegister = hook;
  696. } else if (style) {
  697. hook = shadowMode ? function () {
  698. style.call(this, createInjectorShadow(this.$root.$options.shadowRoot));
  699. } : function (context) {
  700. style.call(this, createInjector(context));
  701. };
  702. }
  703. if (hook) {
  704. if (options.functional) {
  705. // register for functional component in vue file
  706. var originalRender = options.render;
  707. options.render = function renderWithStyleInjection(h, context) {
  708. hook.call(context);
  709. return originalRender(h, context);
  710. };
  711. } else {
  712. // inject component registration as beforeCreate hook
  713. var existing = options.beforeCreate;
  714. options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
  715. }
  716. }
  717. return script;
  718. }
  719. var normalizeComponent_1 = normalizeComponent;
  720. /* script */
  721. const __vue_script__ = script;
  722. /* template */
  723. var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"quillWrapper"},[_vm._t("toolbar"),_vm._v(" "),_c('div',{ref:"quillContainer",attrs:{"id":_vm.id}}),_vm._v(" "),(_vm.useCustomImageHandler)?_c('input',{ref:"fileInput",staticStyle:{"display":"none"},attrs:{"id":"file-upload","type":"file","accept":"image/*"},on:{"change":function($event){return _vm.emitImageInfo($event)}}}):_vm._e()],2)};
  724. var __vue_staticRenderFns__ = [];
  725. /* style */
  726. const __vue_inject_styles__ = undefined;
  727. /* scoped */
  728. const __vue_scope_id__ = undefined;
  729. /* module identifier */
  730. const __vue_module_identifier__ = undefined;
  731. /* functional template */
  732. const __vue_is_functional_template__ = false;
  733. /* style inject */
  734. /* style inject SSR */
  735. var VueEditor = normalizeComponent_1(
  736. { render: __vue_render__, staticRenderFns: __vue_staticRenderFns__ },
  737. __vue_inject_styles__,
  738. __vue_script__,
  739. __vue_scope_id__,
  740. __vue_is_functional_template__,
  741. __vue_module_identifier__,
  742. undefined,
  743. undefined
  744. );
  745. var version = "2.10.3"; // Declare install function executed by Vue.use()
  746. function install(Vue) {
  747. if (install.installed) return;
  748. install.installed = true;
  749. Vue.component("VueEditor", VueEditor);
  750. }
  751. var VPlugin = {
  752. install: install,
  753. version: version,
  754. Quill: Quill,
  755. VueEditor: VueEditor
  756. }; // Auto-install when vue is found (eg. in browser via <script> tag)
  757. var GlobalVue = null;
  758. if (typeof window !== "undefined") {
  759. GlobalVue = window.Vue;
  760. } else if (typeof global !== "undefined") {
  761. GlobalVue = global.Vue;
  762. }
  763. if (GlobalVue) {
  764. GlobalVue.use(VPlugin);
  765. }
  766. /*************************************************/
  767. exports.Quill = Quill;
  768. exports.VueEditor = VueEditor;
  769. exports.default = VPlugin;
  770. exports.install = install;
  771. Object.defineProperty(exports, '__esModule', { value: true });
  772. }));