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/es2015/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
  */
@@ -1830,7 +1830,7 @@ __webpack_require__.r(__webpack_exports__);
1830
1830
  * ```
1831
1831
  * @packageDocumentation
1832
1832
  * @module constants
1833
- */ const APP_VERSION = "4.20.4";
1833
+ */ const APP_VERSION = "4.20.5";
1834
1834
  // prettier-ignore
1835
1835
  const ES = "es2015";
1836
1836
  const IS_ES_MODERN = true;
@@ -32081,8 +32081,18 @@ class cleanHtml extends jodit_core_plugin_plugin__WEBPACK_IMPORTED_MODULE_7__.Pl
32081
32081
  }
32082
32082
  ;(0,jodit_core_helpers_html_safe_html__WEBPACK_IMPORTED_MODULE_6__.safeHTML)(sandBox, this.j.o.cleanHTML);
32083
32083
  }
32084
+ onCleanHTML(sandBox) {
32085
+ const allow = (0,_helpers__WEBPACK_IMPORTED_MODULE_10__.getHash)(this.j.o.cleanHTML.allowTags);
32086
+ const deny = (0,_helpers__WEBPACK_IMPORTED_MODULE_10__.getHash)(this.j.o.cleanHTML.denyTags);
32087
+ const nodes = Array.from(sandBox.querySelectorAll('*'));
32088
+ for (const node of nodes){
32089
+ if (jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_3__.Dom.isOrContains(sandBox, node)) {
32090
+ (0,_helpers__WEBPACK_IMPORTED_MODULE_10__.visitNodeWalker)(this.j, node, allow, deny, null);
32091
+ }
32092
+ }
32093
+ }
32084
32094
  /** @override */ beforeDestruct() {
32085
- this.j.e.off('safeHTML', this.onSafeHTML).off('beforeSetNativeEditorValue', this.onBeforeSetNativeEditorValue).off('afterSetNativeEditorValue', this.onAfterSetNativeEditorValue);
32095
+ this.j.e.off('safeHTML', this.onSafeHTML).off('cleanHTML', this.onCleanHTML).off('beforeSetNativeEditorValue', this.onBeforeSetNativeEditorValue).off('afterSetNativeEditorValue', this.onAfterSetNativeEditorValue);
32086
32096
  this.walker.destruct();
32087
32097
  }
32088
32098
  constructor(jodit){
@@ -32099,7 +32109,7 @@ class cleanHtml extends jodit_core_plugin_plugin__WEBPACK_IMPORTED_MODULE_7__.Pl
32099
32109
  // markup out of the live tree have to be there from the start, or
32100
32110
  // event handlers in a textarea's content run before anything
32101
32111
  // sanitises them.
32102
- jodit.e.on('safeHTML', this.onSafeHTML).on('beforeSetNativeEditorValue', this.onBeforeSetNativeEditorValue).on('afterSetNativeEditorValue', this.onAfterSetNativeEditorValue);
32112
+ jodit.e.on('safeHTML', this.onSafeHTML).on('cleanHTML', this.onCleanHTML).on('beforeSetNativeEditorValue', this.onBeforeSetNativeEditorValue).on('afterSetNativeEditorValue', this.onAfterSetNativeEditorValue);
32103
32113
  }
32104
32114
  }
32105
32115
  ;(0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__._)([
@@ -32135,6 +32145,9 @@ class cleanHtml extends jodit_core_plugin_plugin__WEBPACK_IMPORTED_MODULE_7__.Pl
32135
32145
  (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__._)([
32136
32146
  jodit_core_decorators__WEBPACK_IMPORTED_MODULE_2__.autobind
32137
32147
  ], cleanHtml.prototype, "onSafeHTML", null);
32148
+ (0,_swc_helpers_ts_decorate__WEBPACK_IMPORTED_MODULE_1__._)([
32149
+ jodit_core_decorators__WEBPACK_IMPORTED_MODULE_2__.autobind
32150
+ ], cleanHtml.prototype, "onCleanHTML", null);
32138
32151
  jodit_core_global__WEBPACK_IMPORTED_MODULE_5__.pluginSystem.add('cleanHtml', cleanHtml);
32139
32152
 
32140
32153
 
@@ -35988,14 +36001,25 @@ jodit_config__WEBPACK_IMPORTED_MODULE_3__.Config.prototype.controls.file = {
35988
36001
  popup: (editor, current, close)=>{
35989
36002
  // The popup's first field takes the focus, so the selection the
35990
36003
  // popup was opened for is kept and put back before the link goes in
35991
- const selected = editor.s.isCollapsed() ? null : editor.s.range;
36004
+ let selected = editor.s.isCollapsed() ? null : editor.s.range;
35992
36005
  const restoreSelection = ()=>{
35993
36006
  if (selected) {
35994
36007
  editor.s.selectRange(selected);
36008
+ selected = null;
35995
36009
  }
35996
36010
  };
35997
36011
  const insert = (url, title = '')=>{
35998
36012
  restoreSelection();
36013
+ if (sourceAnchor && jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_0__.Dom.isOrContains(editor.editor, sourceAnchor)) {
36014
+ (0,jodit_core_helpers_utils_attr__WEBPACK_IMPORTED_MODULE_2__.attr)(sourceAnchor, 'href', url);
36015
+ if (title) {
36016
+ (0,jodit_core_helpers_utils_attr__WEBPACK_IMPORTED_MODULE_2__.attr)(sourceAnchor, 'title', title);
36017
+ }
36018
+ editor.s.setCursorAfter(sourceAnchor);
36019
+ sourceAnchor = null;
36020
+ editor.synchronizeValues();
36021
+ return;
36022
+ }
35999
36023
  if (wrapSelectionInLink(editor, url, title)) {
36000
36024
  return;
36001
36025
  }
@@ -42761,6 +42785,7 @@ jodit_core_global__WEBPACK_IMPORTED_MODULE_4__.pluginSystem.add('lineHeight', li
42761
42785
 
42762
42786
  jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.link = {
42763
42787
  formTemplate: jodit_plugins_link_template__WEBPACK_IMPORTED_MODULE_5__.formTemplate,
42788
+ contentMode: 'text',
42764
42789
  followOnDblClick: false,
42765
42790
  processVideoLink: true,
42766
42791
  processPastedLink: true,
@@ -42943,7 +42968,7 @@ jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.controls.link = {
42943
42968
  __generateForm(current, close) {
42944
42969
  const { jodit } = this;
42945
42970
  const i18n = jodit.i18n.bind(jodit);
42946
- const { openInNewTabCheckbox, openInNewTabCheckboxDefaultChecked, noFollowCheckbox, formTemplate, formClassName, modeClassName } = jodit.o.link;
42971
+ const { openInNewTabCheckbox, openInNewTabCheckboxDefaultChecked, noFollowCheckbox, formTemplate, formClassName, modeClassName, contentMode } = jodit.o.link;
42947
42972
  const html = formTemplate(jodit);
42948
42973
  const form = (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.isString)(html) ? jodit.c.fromHTML(html, {
42949
42974
  target_checkbox_box: openInNewTabCheckbox,
@@ -42954,7 +42979,7 @@ jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.controls.link = {
42954
42979
  const { insert, unlink, content_input_box } = elements;
42955
42980
  const { target_checkbox, nofollow_checkbox, url_input } = elements;
42956
42981
  const currentElement = current;
42957
- const isImageContent = jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isImage(currentElement);
42982
+ const isImageContent = contentMode !== 'html' && jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isImage(currentElement);
42958
42983
  let { content_input } = elements;
42959
42984
  const { className_input } = elements, { className_select } = elements, { aria_label_input } = elements;
42960
42985
  if (!content_input) {
@@ -42970,15 +42995,21 @@ jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.controls.link = {
42970
42995
  jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.hide(content_input_box);
42971
42996
  }
42972
42997
  let link;
42973
- const getSelectionText = ()=>link ? link.innerText : (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.stripTags)(jodit.s.range.cloneContents(), jodit.ed);
42998
+ const getSelectionContent = ()=>{
42999
+ if (contentMode === 'html') {
43000
+ return link ? link.innerHTML : jodit.s.html;
43001
+ }
43002
+ return link ? link.innerText : (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.stripTags)(jodit.s.range.cloneContents(), jodit.ed);
43003
+ };
42974
43004
  if (current && jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.closest(current, 'a', jodit.editor)) {
42975
43005
  link = jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.closest(current, 'a', jodit.editor);
42976
43006
  } else {
42977
43007
  link = false;
42978
43008
  }
42979
43009
  if (!isImageContent && current) {
42980
- content_input.value = getSelectionText();
43010
+ content_input.value = getSelectionContent();
42981
43011
  }
43012
+ const initialContent = content_input.value;
42982
43013
  if (aria_label_input) {
42983
43014
  aria_label_input.value = link ? (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.attr)(link, 'aria-label') || '' : '';
42984
43015
  }
@@ -42997,7 +43028,7 @@ jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.controls.link = {
42997
43028
  } else {
42998
43029
  jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.hide(unlink);
42999
43030
  if (jodit.o.link.deriveUrlFromText && url_input && !isImageContent && !url_input.value.trim()) {
43000
- url_input.value = guessUrlFromText(content_input.value);
43031
+ url_input.value = guessUrlFromText(contentMode === 'html' ? (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.stripTags)(content_input.value, jodit.ed) : content_input.value);
43001
43032
  }
43002
43033
  if (openInNewTabCheckbox && target_checkbox) {
43003
43034
  target_checkbox.checked = openInNewTabCheckboxDefaultChecked;
@@ -43029,7 +43060,7 @@ jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.controls.link = {
43029
43060
  jodit.s.removeMarkers();
43030
43061
  jodit.editor.normalize();
43031
43062
  jodit.history.snapshot.restore(snapshot);
43032
- const textWasChanged = getSelectionText() !== content_input.value.trim();
43063
+ const contentWasChanged = initialContent !== content_input.value;
43033
43064
  const ci = jodit.createInside;
43034
43065
  let caretAfter = null;
43035
43066
  if (!link || !jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isOrContains(jodit.editor, link)) {
@@ -43060,7 +43091,7 @@ jodit_config__WEBPACK_IMPORTED_MODULE_2__.Config.prototype.controls.link = {
43060
43091
  ;(0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.attr)(a, 'href', url_input.value);
43061
43092
  writeClasses(modeClassName, className_input, className_select, a);
43062
43093
  if (!isImageContent) {
43063
- writeImage(a, content_input, textWasChanged, url_input);
43094
+ writeContent(jodit, a, content_input.value, contentWasChanged, url_input.value, contentMode);
43064
43095
  }
43065
43096
  if (openInNewTabCheckbox && target_checkbox) {
43066
43097
  (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.attr)(a, 'target', target_checkbox.checked ? '_blank' : null);
@@ -43336,7 +43367,7 @@ jodit_core_global__WEBPACK_IMPORTED_MODULE_5__.pluginSystem.add('link', link);
43336
43367
  dropdown.close();
43337
43368
  url.value = '#' + name;
43338
43369
  if (!isImage && (!content.value.trim() || content.value === filled)) {
43339
- content.value = filled = text;
43370
+ content.value = filled = jodit.o.link.contentMode === 'html' ? (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.htmlspecialchars)(text) : text;
43340
43371
  }
43341
43372
  url.focus();
43342
43373
  });
@@ -43472,19 +43503,33 @@ function readClassnames(modeClassName, className_input, link, className_select)
43472
43503
  break;
43473
43504
  }
43474
43505
  }
43475
- function writeImage(a, content_input, textWasChanged, url_input) {
43476
- let newContent = a.textContent;
43477
- if (content_input.value.trim().length) {
43478
- if (textWasChanged) {
43479
- newContent = content_input.value;
43480
- }
43481
- } else {
43482
- newContent = url_input.value;
43506
+ function writeContent(editor, anchor, value, changed, url, mode) {
43507
+ if (!changed && anchor.hasChildNodes()) {
43508
+ return;
43483
43509
  }
43484
- const content = a.textContent;
43485
- if (newContent !== content) {
43486
- a.textContent = newContent;
43510
+ if (mode === 'text' || !value.trim()) {
43511
+ anchor.textContent = value.trim() ? value : url;
43512
+ return;
43487
43513
  }
43514
+ const sandboxDocument = editor.od.implementation.createHTMLDocument('');
43515
+ const sandbox = sandboxDocument.createElement('div');
43516
+ sandbox.innerHTML = value;
43517
+ editor.e.fire('safeHTML', sandbox);
43518
+ sanitizeLinkHTML(sandbox);
43519
+ sandboxDocument.body.appendChild(sandbox);
43520
+ editor.e.fire('cleanHTML', sandbox);
43521
+ sanitizeLinkHTML(sandbox);
43522
+ sandbox.querySelectorAll('a').forEach((link)=>jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.unwrap(link));
43523
+ jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.detach(anchor);
43524
+ jodit_core_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.moveContent(sandbox, anchor);
43525
+ }
43526
+ function sanitizeLinkHTML(sandbox) {
43527
+ 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));
43528
+ (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_6__.safeHTML)(sandbox, {
43529
+ removeEventAttributes: true,
43530
+ removeOnError: true,
43531
+ safeJavaScriptLink: true
43532
+ });
43488
43533
  }
43489
43534
 
43490
43535
 
@@ -43505,7 +43550,7 @@ function writeImage(a, content_input, textWasChanged, url_input) {
43505
43550
  */
43506
43551
 
43507
43552
  const formTemplate = (editor)=>{
43508
- const { openInNewTabCheckbox, noFollowCheckbox, ariaLabelInput, modeClassName, selectSizeClassName, selectMultipleClassName, selectOptionsClassName } = editor.o.link;
43553
+ const { openInNewTabCheckbox, noFollowCheckbox, ariaLabelInput, modeClassName, contentMode, selectSizeClassName, selectMultipleClassName, selectOptionsClassName } = editor.o.link;
43509
43554
  return new jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UIForm(editor, [
43510
43555
  new jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UIBlock(editor, [
43511
43556
  new jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UIInput(editor, {
@@ -43527,10 +43572,10 @@ const formTemplate = (editor)=>{
43527
43572
  })
43528
43573
  ]) : null,
43529
43574
  new jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UIBlock(editor, [
43530
- new jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UIInput(editor, {
43575
+ new (contentMode === 'html' ? jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UITextArea : jodit_core_ui_form__WEBPACK_IMPORTED_MODULE_1__.UIInput)(editor, {
43531
43576
  name: 'content',
43532
43577
  ref: 'content_input',
43533
- label: 'Text'
43578
+ label: contentMode === 'html' ? 'HTML' : 'Text'
43534
43579
  })
43535
43580
  ], {
43536
43581
  ref: 'content_input_box'