UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

539 lines (479 loc) 22.2 kB
/*! * jodit-pro - PRO Version of Jodit Editor * Author: Chupurnov Valerii <chupurnov@gmail.com> * Version: v4.9.27 * Url: https://xdsoft.net/jodit/pro/ * License(s): SEE LICENSE IN LICENSE.md */ (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define([], factory); else { var a = factory(); for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i]; } })(self, function() { return (self["webpackChunkjodit_pro"] = self["webpackChunkjodit_pro"] || []).push([[736],{ /***/ 6183: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ UIBackupList: function() { return /* binding */ UIBackupList; } /* harmony export */ }); /* harmony import */ var _swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(82749); /* harmony import */ var _swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(31635); /* harmony import */ var _item__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(38512); /* harmony import */ var jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(82758); /* harmony import */ var jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(65478); /* harmony import */ var jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(21537); /* harmony import */ var jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(67510); /*! * Jodit Editor PRO (https://xdsoft.net/jodit/) * See LICENSE.md in the project root for license information. * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net/jodit/pro/ */ class UIBackupList extends jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_6__.UIGroup { /** @override */ className() { return 'UIBackupList'; } /** @override */ createContainer(options) { const div = super.createContainer(options); (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_5__.attr)(div, 'tabIndex', '-1'); return div; } build(items) { this.clear(); items.forEach((data, index)=>{ const item = new _item__WEBPACK_IMPORTED_MODULE_2__.UIBackupItem(this.jodit, data); this.append(item); this.j.e.on(item.container, 'focus', ()=>this.onSelect(index)).on(item.container, 'click', ()=>this.onSelect(index)).on(item.container, 'dblclick', ()=>this.onChoose(index)); }); this.currentSelection = 0; this.onChangeCurrentSelection(void 0, -1, 0); } onChangeCurrentSelection(_, old, index) { this.elements[old]?.setMod('active', false); this.elements[index]?.setMod('active', true); this.elements[index]?.focus(); this.j.e.fire(this, 'select', this.elements[index].data); } onSelect(index) { this.currentSelection = index; } onChoose(index) { this.j.e.fire(this, 'choose', this.elements[index ?? this.currentSelection].data); } selectNext() { if (this.currentSelection + 1 <= this.elements.length - 1) { this.currentSelection += 1; } else { this.currentSelection = 0; } } selectPrevious() { if (this.currentSelection - 1 >= 0) { this.currentSelection -= 1; } else { this.currentSelection = this.elements.length - 1; } } constructor(jodit){ super(jodit), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "elements", []), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "currentSelection", -1); jodit.e.on(this.container, 'keydown', (e)=>{ switch(e.key){ case jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_3__.KEY_ENTER: e.preventDefault(); e.stopPropagation(); this.onChoose(this.currentSelection); break; case jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_3__.KEY_DOWN: this.selectNext(); break; case jodit_esm_core_constants__WEBPACK_IMPORTED_MODULE_3__.KEY_UP: this.selectPrevious(); break; } }); } } (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ (0,jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.watch)('currentSelection') ], UIBackupList.prototype, "onChangeCurrentSelection", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.autobind ], UIBackupList.prototype, "onSelect", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.autobind ], UIBackupList.prototype, "onChoose", null); UIBackupList = (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_4__.component ], UIBackupList); /***/ }), /***/ 29243: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ DefaultStorage: function() { return /* binding */ DefaultStorage; } /* harmony export */ }); /* harmony import */ var _swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(82749); /*! * Jodit Editor PRO (https://xdsoft.net/jodit/) * See LICENSE.md in the project root for license information. * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net/jodit/pro/ */ class DefaultStorage { async add(item) { if (!item.html.trim().length) { return false; } const items = this.jodit.storage.get(this.key) || []; if (items.find((elm)=>elm.html === item.html)) { return false; } items.unshift(item); if (items.length > this.jodit.o.backup.limit) { items.length = this.jodit.o.backup.limit; } this.jodit.storage.set(this.key, items); return false; } items() { return Promise.resolve(this.jodit.storage.get(this.key) || []); } clear() { this.jodit.storage.delete(this.key); return Promise.resolve(false); } constructor(jodit){ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "jodit", void 0); (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "key", void 0); this.jodit = jodit; this.key = 'backup.default.storage'; } } /***/ }), /***/ 29402: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); /*! * Jodit Editor PRO (https://xdsoft.net/jodit/) * See LICENSE.md in the project root for license information. * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net/jodit/pro/ */ /***/ }), /***/ 38512: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ UIBackupItem: function() { return /* binding */ UIBackupItem; } /* harmony export */ }); /* harmony import */ var _swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(82749); /* harmony import */ var jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(21537); /* harmony import */ var jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(67510); /*! * Jodit Editor PRO (https://xdsoft.net/jodit/) * See LICENSE.md in the project root for license information. * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net/jodit/pro/ */ class UIBackupItem extends jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_2__.UIElement { /** @override */ className() { return 'UIBackupItem'; } formatDate(timestamp) { const now = new Date(); const date = (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_1__.isString)(timestamp) ? new Date(timestamp) : timestamp, diff = (now.getTime() - date.getTime()) / 1000; if ((0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_1__.isFunction)(this.j.o.backup.formatDate)) { return this.j.o.backup.formatDate(date); } if (diff < 0.2) { return this.j.i18n('Current'); } if (diff < 60) { return this.j.i18n('Less minute'); } if (diff <= 3600) { return this.j.i18n('%s minutes ago', Math.floor(diff / 60)); } if (diff <= 3600 * 24) { return this.j.i18n('%s hours ago', Math.floor(diff / 3600)); } return `${date.toDateString()} ${date.toLocaleTimeString()}`; } focus() { this.container.focus(); } constructor(jodit, data){ super(jodit), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "data", void 0), this.data = data; this.container.innerHTML = this.formatDate(data.created); (0,jodit_esm_core_helpers__WEBPACK_IMPORTED_MODULE_1__.attr)(this.container, 'tabIndex', 0); } } /***/ }), /***/ 57056: /***/ (function(__unused_webpack_module, __unused_webpack___webpack_exports__, __webpack_require__) { "use strict"; /* harmony import */ var _assets_restore_svg__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(68583); /* harmony import */ var _assets_restore_svg__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_assets_restore_svg__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _langs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(29402); /* harmony import */ var jodit_esm_config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6441); /* harmony import */ var jodit_esm_core_global__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(580); /* harmony import */ var jodit_esm_core_ui_icon__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(12153); /*! * Jodit Editor PRO (https://xdsoft.net/jodit/) * See LICENSE.md in the project root for license information. * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net/jodit/pro/ */ // @ts-ignore jodit_esm_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.backup = { interval: 30, limit: 50, dialogWidth: 700, hotkeys: [ 'ctrl+shift+b', 'cmd+shift+b' ] }; jodit_esm_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.controls.backup = { store: { command: 'saveBackup', text: 'Save backup now' }, restore: { tooltip: 'Restore', list: [ 'backup.store' ], exec (editor) { editor.execCommand('openBackupDialog'); } } }; jodit_esm_core_ui_icon__WEBPACK_IMPORTED_MODULE_4__.Icon.set('restore', (_assets_restore_svg__WEBPACK_IMPORTED_MODULE_0___default())); (0,jodit_esm_core_global__WEBPACK_IMPORTED_MODULE_3__.extendLang)(_langs__WEBPACK_IMPORTED_MODULE_1__); /***/ }), /***/ 61328: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ backup: function() { return /* binding */ backup; } /* harmony export */ }); /* harmony import */ var _swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(82749); /* harmony import */ var _swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(31635); /* harmony import */ var _config__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(57056); /* harmony import */ var _modules_store__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(29243); /* harmony import */ var _ui_box__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(64262); /* harmony import */ var jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(65478); /* harmony import */ var jodit_esm_core_plugin__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(50911); /* harmony import */ var jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(67510); /* harmony import */ var jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(2692); /*! * Jodit Editor PRO (https://xdsoft.net/jodit/) * See LICENSE.md in the project root for license information. * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net/jodit/pro/ */ class backup extends jodit_esm_core_plugin__WEBPACK_IMPORTED_MODULE_6__.Plugin { /** @override */ afterInit(jodit) { jodit.registerCommand('saveBackup', this.onSaveBackup).registerCommand('openBackupDialog', { exec: this.onOpenBackupDialog, hotkeys: jodit.o.backup.hotkeys }); const startInterval = ()=>{ this.timeout = jodit.async.setTimeout(()=>{ this.onSaveBackup(); startInterval(); }, jodit.o.backup.interval * 1000); }; startInterval(); jodit.e.on(this.__box, 'choose', this.onSelectItem).on(jodit.ow, 'beforeunload.backup', ()=>{ this.onSaveBackup(); }); } prepareDialog() { if (!this.__dialog) { this.__dialog = this.j.dlg({ minWidth: this.j.o.backup.dialogWidth, buttons: [ 'fullsize', 'dialog.close' ] }).setContent(this.__box.container); } this.__dialog.setHeader(this.jodit.i18n('Restore')); this.addButtonsToDialog(); } onSaveBackup() { this.__storage.add({ created: new Date(), html: this.j.value }); } async onOpenBackupDialog() { this.prepareDialog(); const { __dialog } = this; if (!__dialog) { return; } __dialog.open().setModal(true); const items = await this.__storage.items(); this.__box.build([ { created: new Date(), html: this.j.value }, ...items ]); __dialog.calcAutoSize(); __dialog.setPosition(); } onSelectItem(data) { this.__dialog?.close(); this.j.value = data.html; this.j.s.focus(); } addButtonsToDialog() { const { jodit } = this; const ok = (0,jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_7__.Button)(jodit, { name: 'ok', tabIndex: 0, variant: 'primary', text: 'Ok' }), cancel = (0,jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_7__.Button)(jodit, { variant: 'secondary', tabIndex: 0, text: 'Cancel' }), clear = (0,jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_7__.Button)(jodit, { name: 'clear', tabIndex: 0, variant: 'secondary', text: 'Remove all' }); ok.onAction(()=>{ this.__box.chooseSelected(); }); cancel.onAction(()=>{ this.__dialog?.close(); }); clear.onAction(()=>{ jodit.confirm('Are you sure?', undefined, (confirm)=>{ if (confirm) { this.__storage.clear(); this.__dialog?.close(); } }); }); const block = new jodit_esm_core_ui__WEBPACK_IMPORTED_MODULE_7__.UIBlock(jodit, [ clear, cancel, ok ]); block.container.style.margin = '0'; block.container.style.justifyContent = 'flex-end'; block.container.style.width = '100%'; this.__dialog?.setFooter(block); } /** @override */ beforeDestruct() { const { j } = this; j.async.clearTimeout(this.timeout); j.e.off(this.__box, 'choose', this.onSelectItem).off(j.ow, 'beforeunload.backup'); this.__box.destruct(); this.__dialog?.destruct(); } constructor(...args){ super(...args), /** @override */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "hasStyle", !jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_8__.JoditPro.fatMode), /** @override */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "buttons", [ { name: 'backup.restore', group: 'history' } ]), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "__box", new _ui_box__WEBPACK_IMPORTED_MODULE_4__.UIBackupBox(this.j)), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "__dialog", null), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "__storage", this.jodit.o.backup.remoteStore ?? new _modules_store__WEBPACK_IMPORTED_MODULE_3__.DefaultStorage(this.jodit)), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "timeout", 0); } } /** @override */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(backup, "requires", [ 'license' ]); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_5__.autobind ], backup.prototype, "onSaveBackup", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_5__.autobind ], backup.prototype, "onOpenBackupDialog", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_5__.autobind ], backup.prototype, "onSelectItem", null); jodit_pro_jodit_pro__WEBPACK_IMPORTED_MODULE_8__.JoditPro.plugins.add('backup', backup); /***/ }), /***/ 64262: /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ UIBackupBox: function() { return /* binding */ UIBackupBox; } /* harmony export */ }); /* harmony import */ var _swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(82749); /* harmony import */ var _swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(31635); /* harmony import */ var _list__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6183); /* harmony import */ var jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(65478); /* harmony import */ var jodit_esm_core_ui_element__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(48538); /*! * Jodit Editor PRO (https://xdsoft.net/jodit/) * See LICENSE.md in the project root for license information. * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net/jodit/pro/ */ class UIBackupBox extends jodit_esm_core_ui_element__WEBPACK_IMPORTED_MODULE_4__.UIElement { /** @override */ className() { return 'UIBackupBox'; } build(items) { this.preview.innerHTML = ''; this.list.build(items); } /** @override */ destruct() { this.j.e.off(this.list, 'select', this.onSelectItem); this.list.destruct(); return super.destruct(); } /** * On select item inside list */ onSelectItem(item) { this.latestSelected = item; this.preview.innerHTML = item.html || `<div class="${this.getFullElName('empty')}">${this.j.i18n('Empty')}</div>`; } /** * On choose item inside list */ onChooseItem(item) { this.j.e.fire(this, 'choose', item); } chooseSelected() { this.onChooseItem(this.latestSelected); } constructor(jodit){ super(jodit), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "list", new _list__WEBPACK_IMPORTED_MODULE_2__.UIBackupList(this.j)), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "preview", this.j.c.div(this.getFullElName('preview'))), (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "latestSelected", void 0); this.container.appendChild(this.list.container); this.container.appendChild(this.preview); this.list.container.classList.add(this.getFullElName('list')); jodit.e.on(this.list, 'select', this.onSelectItem).on(this.list, 'choose', this.onChooseItem); } } (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_3__.autobind ], UIBackupBox.prototype, "onSelectItem", null); (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_3__.autobind ], UIBackupBox.prototype, "onChooseItem", null); UIBackupBox = (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__.__decorate)([ jodit_esm_core_decorators__WEBPACK_IMPORTED_MODULE_3__.component ], UIBackupBox); /***/ }), /***/ 68583: /***/ (function(module) { module.exports = "<?xml version=\"1.0\" ?><svg viewBox=\"0 0 64 64\" xmlns=\"http://www.w3.org/2000/svg\"><title/><g id=\"Upload\"><path d=\"M16,26h8V50a2,2,0,0,0,2,2H38a2,2,0,0,0,2-2V26h8a2,2,0,0,0,1.4946-3.3291l-16-18a2,2,0,0,0-2.9892,0l-16,18A2,2,0,0,0,16,26ZM32,9.0107,43.5464,22H38a2,2,0,0,0-2,2V48H28V24a2,2,0,0,0-2-2H20.4536Z\"/><path d=\"M53,42a2,2,0,0,0-2,2V54a2.0023,2.0023,0,0,1-2,2H15a2.0023,2.0023,0,0,1-2-2V44a2,2,0,0,0-4,0V54a6.0066,6.0066,0,0,0,6,6H49a6.0066,6.0066,0,0,0,6-6V44A2,2,0,0,0,53,42Z\"/></g></svg>" /***/ }) }, /******/ function(__webpack_require__) { // webpackRuntimeModules /******/ var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId); } /******/ var __webpack_exports__ = (__webpack_exec__(61328)); /******/ return __webpack_exports__; /******/ } ]); });