jodit 4.20.4 → 4.20.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/es2015/jodit.css +1 -1
  3. package/es2015/jodit.fat.min.js +4 -4
  4. package/es2015/jodit.js +72 -27
  5. package/es2015/jodit.min.js +4 -4
  6. package/es2015/plugins/debug/debug.css +1 -1
  7. package/es2015/plugins/debug/debug.js +1 -1
  8. package/es2015/plugins/debug/debug.min.js +1 -1
  9. package/es2015/plugins/speech-recognize/speech-recognize.css +1 -1
  10. package/es2015/plugins/speech-recognize/speech-recognize.js +1 -1
  11. package/es2015/plugins/speech-recognize/speech-recognize.min.js +1 -1
  12. package/es2018/jodit.fat.min.js +4 -4
  13. package/es2018/jodit.min.js +4 -4
  14. package/es2018/plugins/debug/debug.min.js +1 -1
  15. package/es2018/plugins/speech-recognize/speech-recognize.min.js +1 -1
  16. package/es2021/jodit.css +1 -1
  17. package/es2021/jodit.fat.min.js +4 -4
  18. package/es2021/jodit.js +72 -27
  19. package/es2021/jodit.min.js +4 -4
  20. package/es2021/plugins/debug/debug.css +1 -1
  21. package/es2021/plugins/debug/debug.js +1 -1
  22. package/es2021/plugins/debug/debug.min.js +1 -1
  23. package/es2021/plugins/speech-recognize/speech-recognize.css +1 -1
  24. package/es2021/plugins/speech-recognize/speech-recognize.js +1 -1
  25. package/es2021/plugins/speech-recognize/speech-recognize.min.js +1 -1
  26. package/es2021.en/jodit.css +1 -1
  27. package/es2021.en/jodit.fat.min.js +6 -6
  28. package/es2021.en/jodit.js +72 -27
  29. package/es2021.en/jodit.min.js +4 -4
  30. package/es2021.en/plugins/debug/debug.css +1 -1
  31. package/es2021.en/plugins/debug/debug.js +1 -1
  32. package/es2021.en/plugins/debug/debug.min.js +1 -1
  33. package/es2021.en/plugins/speech-recognize/speech-recognize.css +1 -1
  34. package/es2021.en/plugins/speech-recognize/speech-recognize.js +1 -1
  35. package/es2021.en/plugins/speech-recognize/speech-recognize.min.js +1 -1
  36. package/es5/jodit.css +2 -2
  37. package/es5/jodit.fat.min.js +2 -2
  38. package/es5/jodit.js +93 -26
  39. package/es5/jodit.min.css +2 -2
  40. package/es5/jodit.min.js +2 -2
  41. package/es5/plugins/debug/debug.css +1 -1
  42. package/es5/plugins/debug/debug.js +1 -1
  43. package/es5/plugins/debug/debug.min.js +1 -1
  44. package/es5/plugins/speech-recognize/speech-recognize.css +1 -1
  45. package/es5/plugins/speech-recognize/speech-recognize.js +1 -1
  46. package/es5/plugins/speech-recognize/speech-recognize.min.js +1 -1
  47. package/es5/polyfills.fat.min.js +1 -1
  48. package/es5/polyfills.js +1 -1
  49. package/es5/polyfills.min.js +1 -1
  50. package/esm/config.d.ts +2 -0
  51. package/esm/core/constants.js +1 -1
  52. package/esm/plugins/clean-html/clean-html.d.ts +1 -0
  53. package/esm/plugins/clean-html/clean-html.js +15 -0
  54. package/esm/plugins/file/file.js +12 -1
  55. package/esm/plugins/link/config.d.ts +2 -0
  56. package/esm/plugins/link/config.js +1 -0
  57. package/esm/plugins/link/link.js +49 -23
  58. package/esm/plugins/link/template.js +4 -4
  59. package/package.json +1 -1
  60. package/types/config.d.ts +2 -0
  61. package/types/plugins/clean-html/clean-html.d.ts +1 -0
  62. package/types/plugins/link/config.d.ts +2 -0
package/es2021/jodit.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * jodit - Jodit is an awesome and useful wysiwyg editor with filebrowser
3
3
  * Author: Chupurnov <chupurnov@gmail.com> (https://xdsoft.net/jodit/)
4
- * Version: v4.20.4
4
+ * Version: v4.20.5
5
5
  * Url: https://xdsoft.net/jodit/
6
6
  * License(s): MIT
7
7
  */
@@ -1824,7 +1824,7 @@ __webpack_require__.r(__webpack_exports__);
1824
1824
  * ```
1825
1825
  * @packageDocumentation
1826
1826
  * @module constants
1827
- */ const APP_VERSION = "4.20.4";
1827
+ */ const APP_VERSION = "4.20.5";
1828
1828
  // prettier-ignore
1829
1829
  const ES = "es2021";
1830
1830
  const IS_ES_MODERN = true;
@@ -31821,8 +31821,18 @@ class cleanHtml extends jodit_core_plugin_plugin__WEBPACK_IMPORTED_MODULE_7__.Pl
31821
31821
  }
31822
31822
  ;(0,jodit_core_helpers_html_safe_html__WEBPACK_IMPORTED_MODULE_6__.safeHTML)(sandBox, this.j.o.cleanHTML);
31823
31823
  }
31824
+ onCleanHTML(sandBox) {
31825
+ const allow = (0,_helpers__WEBPACK_IMPORTED_MODULE_10__.getHash)(this.j.o.cleanHTML.allowTags);
31826
+ const deny = (0,_helpers__WEBPACK_IMPORTED_MODULE_10__.getHash)(this.j.o.cleanHTML.denyTags);
31827
+ const nodes = Array.from(sandBox.querySelectorAll('*'));
31828
+ for (const node of nodes){
31829
+ if (jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_3__.Dom.isOrContains(sandBox, node)) {
31830
+ (0,_helpers__WEBPACK_IMPORTED_MODULE_10__.visitNodeWalker)(this.j, node, allow, deny, null);
31831
+ }
31832
+ }
31833
+ }
31824
31834
  /** @override */ beforeDestruct() {
31825
- this.j.e.off('safeHTML', this.onSafeHTML).off('beforeSetNativeEditorValue', this.onBeforeSetNativeEditorValue).off('afterSetNativeEditorValue', this.onAfterSetNativeEditorValue);
31835
+ this.j.e.off('safeHTML', this.onSafeHTML).off('cleanHTML', this.onCleanHTML).off('beforeSetNativeEditorValue', this.onBeforeSetNativeEditorValue).off('afterSetNativeEditorValue', this.onAfterSetNativeEditorValue);
31826
31836
  this.walker.destruct();
31827
31837
  }
31828
31838
  constructor(jodit){
@@ -31839,7 +31849,7 @@ class cleanHtml extends jodit_core_plugin_plugin__WEBPACK_IMPORTED_MODULE_7__.Pl
31839
31849
  // markup out of the live tree have to be there from the start, or
31840
31850
  // event handlers in a textarea's content run before anything
31841
31851
  // sanitises them.
31842
- jodit.e.on('safeHTML', this.onSafeHTML).on('beforeSetNativeEditorValue', this.onBeforeSetNativeEditorValue).on('afterSetNativeEditorValue', this.onAfterSetNativeEditorValue);
31852
+ jodit.e.on('safeHTML', this.onSafeHTML).on('cleanHTML', this.onCleanHTML).on('beforeSetNativeEditorValue', this.onBeforeSetNativeEditorValue).on('afterSetNativeEditorValue', this.onAfterSetNativeEditorValue);
31843
31853
  }
31844
31854
  }
31845
31855
  ;(0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__._)([
@@ -31875,6 +31885,9 @@ class cleanHtml extends jodit_core_plugin_plugin__WEBPACK_IMPORTED_MODULE_7__.Pl
31875
31885
  (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__._)([
31876
31886
  jodit_core_decorators__WEBPACK_IMPORTED_MODULE_2__.autobind
31877
31887
  ], cleanHtml.prototype, "onSafeHTML", null);
31888
+ (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__._)([
31889
+ jodit_core_decorators__WEBPACK_IMPORTED_MODULE_2__.autobind
31890
+ ], cleanHtml.prototype, "onCleanHTML", null);
31878
31891
  jodit_core_global__WEBPACK_IMPORTED_MODULE_5__.pluginSystem.add('cleanHtml', cleanHtml);
31879
31892
 
31880
31893
 
@@ -35705,14 +35718,25 @@ jodit_config__WEBPACK_IMPORTED_MODULE_3__.Config.prototype.controls.file = {
35705
35718
  popup: (editor, current, close)=>{
35706
35719
  // The popup's first field takes the focus, so the selection the
35707
35720
  // popup was opened for is kept and put back before the link goes in
35708
- const selected = editor.s.isCollapsed() ? null : editor.s.range;
35721
+ let selected = editor.s.isCollapsed() ? null : editor.s.range;
35709
35722
  const restoreSelection = ()=>{
35710
35723
  if (selected) {
35711
35724
  editor.s.selectRange(selected);
35725
+ selected = null;
35712
35726
  }
35713
35727
  };
35714
35728
  const insert = (url, title = '')=>{
35715
35729
  restoreSelection();
35730
+ if (sourceAnchor && jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_0__.Dom.isOrContains(editor.editor, sourceAnchor)) {
35731
+ (0,jodit_core_helpers_utils_attr__WEBPACK_IMPORTED_MODULE_2__.attr)(sourceAnchor, 'href', url);
35732
+ if (title) {
35733
+ (0,jodit_core_helpers_utils_attr__WEBPACK_IMPORTED_MODULE_2__.attr)(sourceAnchor, 'title', title);
35734
+ }
35735
+ editor.s.setCursorAfter(sourceAnchor);
35736
+ sourceAnchor = null;
35737
+ editor.synchronizeValues();
35738
+ return;
35739
+ }
35716
35740
  if (wrapSelectionInLink(editor, url, title)) {
35717
35741
  return;
35718
35742
  }
@@ -42396,6 +42420,7 @@ jodit_core_global__WEBPACK_IMPORTED_MODULE_4__.pluginSystem.add('lineHeight', li
42396
42420
 
42397
42421
  jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.link = {
42398
42422
  formTemplate: jodit_plugins_link_template__WEBPACK_IMPORTED_MODULE_5__.formTemplate,
42423
+ contentMode: 'text',
42399
42424
  followOnDblClick: false,
42400
42425
  processVideoLink: true,
42401
42426
  processPastedLink: true,
@@ -42576,7 +42601,7 @@ jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.controls.link = {
42576
42601
  __generateForm(current, close) {
42577
42602
  const { jodit } = this;
42578
42603
  const i18n = jodit.i18n.bind(jodit);
42579
- const { openInNewTabCheckbox, openInNewTabCheckboxDefaultChecked, noFollowCheckbox, formTemplate, formClassName, modeClassName } = jodit.o.link;
42604
+ const { openInNewTabCheckbox, openInNewTabCheckboxDefaultChecked, noFollowCheckbox, formTemplate, formClassName, modeClassName, contentMode } = jodit.o.link;
42580
42605
  const html = formTemplate(jodit);
42581
42606
  const form = (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.isString)(html) ? jodit.c.fromHTML(html, {
42582
42607
  target_checkbox_box: openInNewTabCheckbox,
@@ -42587,7 +42612,7 @@ jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.controls.link = {
42587
42612
  const { insert, unlink, content_input_box } = elements;
42588
42613
  const { target_checkbox, nofollow_checkbox, url_input } = elements;
42589
42614
  const currentElement = current;
42590
- const isImageContent = jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isImage(currentElement);
42615
+ const isImageContent = contentMode !== 'html' && jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isImage(currentElement);
42591
42616
  let { content_input } = elements;
42592
42617
  const { className_input } = elements, { className_select } = elements, { aria_label_input } = elements;
42593
42618
  if (!content_input) {
@@ -42603,15 +42628,21 @@ jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.controls.link = {
42603
42628
  jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.hide(content_input_box);
42604
42629
  }
42605
42630
  let link;
42606
- const getSelectionText = ()=>link ? link.innerText : (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.stripTags)(jodit.s.range.cloneContents(), jodit.ed);
42631
+ const getSelectionContent = ()=>{
42632
+ if (contentMode === 'html') {
42633
+ return link ? link.innerHTML : jodit.s.html;
42634
+ }
42635
+ return link ? link.innerText : (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.stripTags)(jodit.s.range.cloneContents(), jodit.ed);
42636
+ };
42607
42637
  if (current && jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.closest(current, 'a', jodit.editor)) {
42608
42638
  link = jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.closest(current, 'a', jodit.editor);
42609
42639
  } else {
42610
42640
  link = false;
42611
42641
  }
42612
42642
  if (!isImageContent && current) {
42613
- content_input.value = getSelectionText();
42643
+ content_input.value = getSelectionContent();
42614
42644
  }
42645
+ const initialContent = content_input.value;
42615
42646
  if (aria_label_input) {
42616
42647
  aria_label_input.value = link ? (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.attr)(link, 'aria-label') || '' : '';
42617
42648
  }
@@ -42630,7 +42661,7 @@ jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.controls.link = {
42630
42661
  } else {
42631
42662
  jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.hide(unlink);
42632
42663
  if (jodit.o.link.deriveUrlFromText && url_input && !isImageContent && !url_input.value.trim()) {
42633
- url_input.value = guessUrlFromText(content_input.value);
42664
+ url_input.value = guessUrlFromText(contentMode === 'html' ? (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.stripTags)(content_input.value, jodit.ed) : content_input.value);
42634
42665
  }
42635
42666
  if (openInNewTabCheckbox && target_checkbox) {
42636
42667
  target_checkbox.checked = openInNewTabCheckboxDefaultChecked;
@@ -42662,7 +42693,7 @@ jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.controls.link = {
42662
42693
  jodit.s.removeMarkers();
42663
42694
  jodit.editor.normalize();
42664
42695
  jodit.history.snapshot.restore(snapshot);
42665
- const textWasChanged = getSelectionText() !== content_input.value.trim();
42696
+ const contentWasChanged = initialContent !== content_input.value;
42666
42697
  const ci = jodit.createInside;
42667
42698
  let caretAfter = null;
42668
42699
  if (!link || !jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isOrContains(jodit.editor, link)) {
@@ -42693,7 +42724,7 @@ jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.controls.link = {
42693
42724
  ;(0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.attr)(a, 'href', url_input.value);
42694
42725
  writeClasses(modeClassName, className_input, className_select, a);
42695
42726
  if (!isImageContent) {
42696
- writeImage(a, content_input, textWasChanged, url_input);
42727
+ writeContent(jodit, a, content_input.value, contentWasChanged, url_input.value, contentMode);
42697
42728
  }
42698
42729
  if (openInNewTabCheckbox && target_checkbox) {
42699
42730
  (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.attr)(a, 'target', target_checkbox.checked ? '_blank' : null);
@@ -42964,7 +42995,7 @@ jodit_core_global__WEBPACK_IMPORTED_MODULE_5__.pluginSystem.add('link', link);
42964
42995
  dropdown.close();
42965
42996
  url.value = '#' + name;
42966
42997
  if (!isImage && (!content.value.trim() || content.value === filled)) {
42967
- content.value = filled = text;
42998
+ content.value = filled = jodit.o.link.contentMode === 'html' ? (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.htmlspecialchars)(text) : text;
42968
42999
  }
42969
43000
  url.focus();
42970
43001
  });
@@ -43097,19 +43128,33 @@ function readClassnames(modeClassName, className_input, link, className_select)
43097
43128
  break;
43098
43129
  }
43099
43130
  }
43100
- function writeImage(a, content_input, textWasChanged, url_input) {
43101
- let newContent = a.textContent;
43102
- if (content_input.value.trim().length) {
43103
- if (textWasChanged) {
43104
- newContent = content_input.value;
43105
- }
43106
- } else {
43107
- newContent = url_input.value;
43131
+ function writeContent(editor, anchor, value, changed, url, mode) {
43132
+ if (!changed && anchor.hasChildNodes()) {
43133
+ return;
43108
43134
  }
43109
- const content = a.textContent;
43110
- if (newContent !== content) {
43111
- a.textContent = newContent;
43135
+ if (mode === 'text' || !value.trim()) {
43136
+ anchor.textContent = value.trim() ? value : url;
43137
+ return;
43112
43138
  }
43139
+ const sandboxDocument = editor.od.implementation.createHTMLDocument('');
43140
+ const sandbox = sandboxDocument.createElement('div');
43141
+ sandbox.innerHTML = value;
43142
+ editor.e.fire('safeHTML', sandbox);
43143
+ sanitizeLinkHTML(sandbox);
43144
+ sandboxDocument.body.appendChild(sandbox);
43145
+ editor.e.fire('cleanHTML', sandbox);
43146
+ sanitizeLinkHTML(sandbox);
43147
+ sandbox.querySelectorAll('a').forEach((link)=>jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.unwrap(link));
43148
+ jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.detach(anchor);
43149
+ jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.moveContent(sandbox, anchor);
43150
+ }
43151
+ function sanitizeLinkHTML(sandbox) {
43152
+ sandbox.querySelectorAll('script,style,iframe,frame,frameset,object,embed,base,link,meta,template').forEach((node)=>jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.safeRemove(node));
43153
+ (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.safeHTML)(sandbox, {
43154
+ removeEventAttributes: true,
43155
+ removeOnError: true,
43156
+ safeJavaScriptLink: true
43157
+ });
43113
43158
  }
43114
43159
 
43115
43160
 
@@ -43130,7 +43175,7 @@ function writeImage(a, content_input, textWasChanged, url_input) {
43130
43175
  */
43131
43176
 
43132
43177
  const formTemplate = (editor)=>{
43133
- const { openInNewTabCheckbox, noFollowCheckbox, ariaLabelInput, modeClassName, selectSizeClassName, selectMultipleClassName, selectOptionsClassName } = editor.o.link;
43178
+ const { openInNewTabCheckbox, noFollowCheckbox, ariaLabelInput, modeClassName, contentMode, selectSizeClassName, selectMultipleClassName, selectOptionsClassName } = editor.o.link;
43134
43179
  return new jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UIForm(editor, [
43135
43180
  new jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UIBlock(editor, [
43136
43181
  new jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UIInput(editor, {
@@ -43152,10 +43197,10 @@ const formTemplate = (editor)=>{
43152
43197
  })
43153
43198
  ]) : null,
43154
43199
  new jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UIBlock(editor, [
43155
- new jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UIInput(editor, {
43200
+ new (contentMode === 'html' ? jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UITextArea : jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UIInput)(editor, {
43156
43201
  name: 'content',
43157
43202
  ref: 'content_input',
43158
- label: 'Text'
43203
+ label: contentMode === 'html' ? 'HTML' : 'Text'
43159
43204
  })
43160
43205
  ], {
43161
43206
  ref: 'content_input_box'