jodit 4.12.43 → 4.13.3

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 (81) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/es2015/jodit.css +6 -1
  3. package/es2015/jodit.fat.min.css +1 -1
  4. package/es2015/jodit.fat.min.js +14 -14
  5. package/es2015/jodit.js +198 -20
  6. package/es2015/jodit.min.css +1 -1
  7. package/es2015/jodit.min.js +5 -5
  8. package/es2015/plugins/debug/debug.css +1 -1
  9. package/es2015/plugins/debug/debug.js +1 -1
  10. package/es2015/plugins/debug/debug.min.js +1 -1
  11. package/es2015/plugins/speech-recognize/speech-recognize.css +1 -1
  12. package/es2015/plugins/speech-recognize/speech-recognize.js +1 -1
  13. package/es2015/plugins/speech-recognize/speech-recognize.min.js +1 -1
  14. package/es2018/jodit.fat.min.css +1 -1
  15. package/es2018/jodit.fat.min.js +3 -3
  16. package/es2018/jodit.min.css +1 -1
  17. package/es2018/jodit.min.js +5 -5
  18. package/es2018/plugins/debug/debug.min.js +1 -1
  19. package/es2018/plugins/speech-recognize/speech-recognize.min.js +1 -1
  20. package/es2021/jodit.css +6 -1
  21. package/es2021/jodit.fat.min.css +1 -1
  22. package/es2021/jodit.fat.min.js +5 -5
  23. package/es2021/jodit.js +189 -20
  24. package/es2021/jodit.min.css +1 -1
  25. package/es2021/jodit.min.js +7 -7
  26. package/es2021/plugins/debug/debug.css +1 -1
  27. package/es2021/plugins/debug/debug.js +1 -1
  28. package/es2021/plugins/debug/debug.min.js +1 -1
  29. package/es2021/plugins/speech-recognize/speech-recognize.css +1 -1
  30. package/es2021/plugins/speech-recognize/speech-recognize.js +1 -1
  31. package/es2021/plugins/speech-recognize/speech-recognize.min.js +1 -1
  32. package/es2021.en/jodit.css +6 -1
  33. package/es2021.en/jodit.fat.min.css +1 -1
  34. package/es2021.en/jodit.fat.min.js +6 -6
  35. package/es2021.en/jodit.js +189 -20
  36. package/es2021.en/jodit.min.css +1 -1
  37. package/es2021.en/jodit.min.js +6 -6
  38. package/es2021.en/plugins/debug/debug.css +1 -1
  39. package/es2021.en/plugins/debug/debug.js +1 -1
  40. package/es2021.en/plugins/debug/debug.min.js +1 -1
  41. package/es2021.en/plugins/speech-recognize/speech-recognize.css +1 -1
  42. package/es2021.en/plugins/speech-recognize/speech-recognize.js +1 -1
  43. package/es2021.en/plugins/speech-recognize/speech-recognize.min.js +1 -1
  44. package/es5/jodit.css +7 -2
  45. package/es5/jodit.fat.min.css +1 -1
  46. package/es5/jodit.fat.min.js +2 -2
  47. package/es5/jodit.js +234 -20
  48. package/es5/jodit.min.css +3 -3
  49. package/es5/jodit.min.js +2 -2
  50. package/es5/plugins/debug/debug.css +1 -1
  51. package/es5/plugins/debug/debug.js +1 -1
  52. package/es5/plugins/debug/debug.min.js +1 -1
  53. package/es5/plugins/speech-recognize/speech-recognize.css +1 -1
  54. package/es5/plugins/speech-recognize/speech-recognize.js +1 -1
  55. package/es5/plugins/speech-recognize/speech-recognize.min.js +1 -1
  56. package/es5/polyfills.fat.min.js +1 -1
  57. package/es5/polyfills.js +1 -1
  58. package/es5/polyfills.min.js +1 -1
  59. package/esm/config.d.ts +22 -0
  60. package/esm/config.js +21 -0
  61. package/esm/core/constants.js +1 -1
  62. package/esm/core/selection/selection.d.ts +31 -0
  63. package/esm/core/selection/selection.js +143 -14
  64. package/esm/core/storage/async-storage.d.ts +2 -2
  65. package/esm/core/storage/async-storage.js +19 -1
  66. package/esm/core/storage/engines/local-storage-provider.js +6 -1
  67. package/esm/core/view/view-with-toolbar.d.ts +6 -0
  68. package/esm/core/view/view-with-toolbar.js +18 -2
  69. package/esm/core/view/view.js +1 -1
  70. package/esm/jodit.js +7 -0
  71. package/esm/types/jodit.d.ts +2 -0
  72. package/esm/types/storage.d.ts +15 -0
  73. package/esm/types/view.d.ts +8 -1
  74. package/package.json +1 -1
  75. package/types/config.d.ts +22 -0
  76. package/types/core/selection/selection.d.ts +31 -0
  77. package/types/core/storage/async-storage.d.ts +2 -2
  78. package/types/core/view/view-with-toolbar.d.ts +6 -0
  79. package/types/types/jodit.d.ts +2 -0
  80. package/types/types/storage.d.ts +15 -0
  81. package/types/types/view.d.ts +8 -1
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.12.43
4
+ * Version: v4.13.3
5
5
  * Url: https://xdsoft.net/jodit/
6
6
  * License(s): MIT
7
7
  */
@@ -378,6 +378,26 @@ let ConfigPrototype = {};
378
378
  /**
379
379
  * if set true, then the current mode is saved in a cookie, and is restored after a reload of the page
380
380
  */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "saveModeInStorage", false);
381
+ /**
382
+ * Configure the provider that backs {@link IViewBased.asyncStorage}.
383
+ *
384
+ * By default the editor's `asyncStorage` uses persistent `IndexedDB` (with an
385
+ * in-memory fallback when it is unavailable). Set `defaultProvider` to override it:
386
+ * - `'local'` — persist in `localStorage`;
387
+ * - `'memory'` — keep everything in memory (nothing survives a reload);
388
+ * - a custom {@link IAsyncStorage} implementation — plug in your own backend.
389
+ *
390
+ * ```javascript
391
+ * Jodit.make('#editor', {
392
+ * asyncStorage: { defaultProvider: 'local' }
393
+ * });
394
+ *
395
+ * // or a fully custom backend
396
+ * Jodit.make('#editor', {
397
+ * asyncStorage: { defaultProvider: myAsyncStorage }
398
+ * });
399
+ * ```
400
+ */ (0,_swc_helpers_define_property__WEBPACK_IMPORTED_MODULE_0__._)(this, "asyncStorage", {});
381
401
  /**
382
402
  * Class name that can be appended to the editable area
383
403
  *
@@ -1829,7 +1849,7 @@ __webpack_require__.r(__webpack_exports__);
1829
1849
  * ```
1830
1850
  * @packageDocumentation
1831
1851
  * @module constants
1832
- */ const APP_VERSION = "4.12.43";
1852
+ */ const APP_VERSION = "4.13.3";
1833
1853
  // prettier-ignore
1834
1854
  const ES = "es2015";
1835
1855
  const IS_ES_MODERN = true;
@@ -11350,6 +11370,137 @@ class Selection {
11350
11370
  }
11351
11371
  return '';
11352
11372
  }
11373
+ /**
11374
+ * Splits the boundaries of the current selection and wraps every
11375
+ * contiguous run of selected inline content (grouped by block) into a
11376
+ * `<font>` element, returning those wrappers in document order.
11377
+ *
11378
+ * This is a pure-DOM replacement for the old
11379
+ * `nativeExecCommand('fontsize', false, '7')` trick which relied on the
11380
+ * browser to split the selection into `<font size="7">` fragments.
11381
+ */ __wrapSelectionFragments() {
11382
+ const range = this.range;
11383
+ this.__splitSelectionBoundaries(range);
11384
+ let root = range.commonAncestorContainer;
11385
+ if (jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isText(root)) {
11386
+ root = root.parentNode;
11387
+ }
11388
+ if (!root) {
11389
+ return [];
11390
+ }
11391
+ return this.__wrapSelectionRuns(this.__collectContainedNodes(root, range));
11392
+ }
11393
+ /**
11394
+ * Splits the text nodes at both ends of the range so that its boundaries
11395
+ * always fall between nodes. Afterwards every node inside the range is
11396
+ * fully (not partially) selected.
11397
+ */ __splitSelectionBoundaries(range) {
11398
+ var _ref, _ref1;
11399
+ var _endContainer_nodeValue, _startContainer_nodeValue;
11400
+ let { startContainer, endContainer } = range;
11401
+ let { startOffset, endOffset } = range;
11402
+ if (jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isText(endContainer) && endOffset > 0 && endOffset < ((_ref = (_endContainer_nodeValue = endContainer.nodeValue) === null || _endContainer_nodeValue === void 0 ? void 0 : _endContainer_nodeValue.length) !== null && _ref !== void 0 ? _ref : 0)) {
11403
+ var _ref2;
11404
+ var _endContainer_nodeValue1;
11405
+ endContainer.splitText(endOffset);
11406
+ endOffset = (_ref2 = (_endContainer_nodeValue1 = endContainer.nodeValue) === null || _endContainer_nodeValue1 === void 0 ? void 0 : _endContainer_nodeValue1.length) !== null && _ref2 !== void 0 ? _ref2 : endOffset;
11407
+ }
11408
+ if (jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isText(startContainer) && startOffset > 0 && startOffset < ((_ref1 = (_startContainer_nodeValue = startContainer.nodeValue) === null || _startContainer_nodeValue === void 0 ? void 0 : _startContainer_nodeValue.length) !== null && _ref1 !== void 0 ? _ref1 : 0)) {
11409
+ const middle = startContainer.splitText(startOffset);
11410
+ // Selection located inside a single text node - the tail we just
11411
+ // cut off is the actual selected fragment.
11412
+ if (startContainer === endContainer) {
11413
+ var _ref3;
11414
+ var _middle_nodeValue;
11415
+ endContainer = middle;
11416
+ endOffset = (_ref3 = (_middle_nodeValue = middle.nodeValue) === null || _middle_nodeValue === void 0 ? void 0 : _middle_nodeValue.length) !== null && _ref3 !== void 0 ? _ref3 : 0;
11417
+ }
11418
+ startContainer = middle;
11419
+ startOffset = 0;
11420
+ }
11421
+ range.setStart(startContainer, startOffset);
11422
+ range.setEnd(endContainer, endOffset);
11423
+ // Normalize text-edge boundaries (e.g. `(text, 0)` or `(text, length)`)
11424
+ // to the element level so that containment checks based on
11425
+ // `selectNode()` treat a fully selected text node as contained.
11426
+ this.__normalizeRangeBoundary(range, true);
11427
+ this.__normalizeRangeBoundary(range, false);
11428
+ }
11429
+ __normalizeRangeBoundary(range, atStart) {
11430
+ var _ref;
11431
+ var _container_nodeValue;
11432
+ const container = atStart ? range.startContainer : range.endContainer;
11433
+ if (!jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isText(container)) {
11434
+ return;
11435
+ }
11436
+ const offset = atStart ? range.startOffset : range.endOffset;
11437
+ const length = (_ref = (_container_nodeValue = container.nodeValue) === null || _container_nodeValue === void 0 ? void 0 : _container_nodeValue.length) !== null && _ref !== void 0 ? _ref : 0;
11438
+ if (offset === 0) {
11439
+ atStart ? range.setStartBefore(container) : range.setEndBefore(container);
11440
+ } else if (offset >= length) {
11441
+ atStart ? range.setStartAfter(container) : range.setEndAfter(container);
11442
+ }
11443
+ }
11444
+ /**
11445
+ * Collects the highest-level nodes that are completely inside the range,
11446
+ * descending into nodes that are only partially selected.
11447
+ */ __collectContainedNodes(root, range) {
11448
+ const result = [];
11449
+ (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.toArray)(root.childNodes).forEach((child)=>{
11450
+ if (this.__isFullyContained(range, child)) {
11451
+ result.push(child);
11452
+ } else if (child.childNodes.length && range.intersectsNode(child)) {
11453
+ result.push(...this.__collectContainedNodes(child, range));
11454
+ }
11455
+ });
11456
+ return result;
11457
+ }
11458
+ __isFullyContained(range, node) {
11459
+ const nodeRange = this.createRange();
11460
+ nodeRange.selectNode(node);
11461
+ return range.compareBoundaryPoints(Range.START_TO_START, nodeRange) <= 0 && range.compareBoundaryPoints(Range.END_TO_END, nodeRange) >= 0;
11462
+ }
11463
+ /**
11464
+ * Wraps every contiguous run of selected inline siblings into a `<font>`
11465
+ * element. Block-level nodes are never wrapped themselves - their inline
11466
+ * content is wrapped instead, keeping every `<font>` inside a single block.
11467
+ */ __wrapSelectionRuns(nodes) {
11468
+ const fonts = [];
11469
+ let run = [];
11470
+ const flush = ()=>{
11471
+ if (run.length) {
11472
+ fonts.push(this.__wrapRunInFont(run));
11473
+ run = [];
11474
+ }
11475
+ };
11476
+ nodes.forEach((node)=>{
11477
+ if (jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isElement(node) && this.__isOrContainsBlock(node)) {
11478
+ flush();
11479
+ fonts.push(...this.__wrapSelectionRuns((0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.toArray)(node.childNodes)));
11480
+ } else {
11481
+ if (run.length && run[run.length - 1].parentNode !== node.parentNode) {
11482
+ flush();
11483
+ }
11484
+ run.push(node);
11485
+ }
11486
+ });
11487
+ flush();
11488
+ return fonts;
11489
+ }
11490
+ __isOrContainsBlock(node) {
11491
+ if (jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isBlock(node)) {
11492
+ return true;
11493
+ }
11494
+ return (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.toArray)(node.childNodes).some((child)=>this.__isOrContainsBlock(child));
11495
+ }
11496
+ __wrapRunInFont(run) {
11497
+ var _first_parentNode;
11498
+ const font = this.j.createInside.element('font');
11499
+ const [first] = run;
11500
+ (_first_parentNode = first.parentNode) === null || _first_parentNode === void 0 ? void 0 : _first_parentNode.insertBefore(font, first);
11501
+ run.forEach((node)=>font.appendChild(node));
11502
+ return font;
11503
+ }
11353
11504
  /**
11354
11505
  * Wrap all selected fragments inside Tag or apply some callback
11355
11506
  */ *wrapInTagGen(fakes) {
@@ -11363,20 +11514,7 @@ class Selection {
11363
11514
  jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.unwrap(font);
11364
11515
  return;
11365
11516
  }
11366
- // fix issue https://github.com/xdan/jodit/issues/65
11367
- (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.$$)('*[style*=font-size]', this.area).forEach((elm)=>{
11368
- (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.attr)(elm, 'data-font-size', elm.style.fontSize.toString());
11369
- elm.style.removeProperty('font-size');
11370
- });
11371
- this.j.nativeExecCommand('fontsize', false, '7');
11372
- (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.$$)('*[data-font-size]', this.area).forEach((elm)=>{
11373
- const fontSize = (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.attr)(elm, 'data-font-size');
11374
- if (fontSize) {
11375
- elm.style.fontSize = fontSize;
11376
- (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.attr)(elm, 'data-font-size', null);
11377
- }
11378
- });
11379
- const elms = (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.$$)('font[size="7"]', this.area);
11517
+ const elms = this.__wrapSelectionFragments();
11380
11518
  for (const font of elms){
11381
11519
  const { firstChild, lastChild } = font;
11382
11520
  if (firstChild && firstChild === lastChild && (0,jodit_core_helpers_checker__WEBPACK_IMPORTED_MODULE_6__.isMarker)(firstChild)) {
@@ -13099,9 +13237,23 @@ class AsyncStorage {
13099
13237
  }
13100
13238
  }).call(this);
13101
13239
  }
13102
- static makeStorage(persistentOrStrategy = false, suffix) {
13240
+ static makeStorage(persistentOrStrategy = false, suffix, options) {
13103
13241
  let provider = undefined;
13104
13242
  let storage = null;
13243
+ // An explicit `defaultProvider` overrides the strategy-based selection
13244
+ // below and decides which provider backs the storage.
13245
+ const defaultProvider = options === null || options === void 0 ? void 0 : options.defaultProvider;
13246
+ if (defaultProvider != null) {
13247
+ if (defaultProvider === 'local') {
13248
+ provider = (0,_engines_local_storage_provider__WEBPACK_IMPORTED_MODULE_4__.canUsePersistentStorage)('localStorage') ? new _engines_local_storage_provider__WEBPACK_IMPORTED_MODULE_4__.LocalStorageProvider(_storage__WEBPACK_IMPORTED_MODULE_6__.StorageKey + (suffix || '')) : new _engines_memory_storage_provider__WEBPACK_IMPORTED_MODULE_5__.MemoryStorageProvider();
13249
+ } else if (defaultProvider === 'memory') {
13250
+ provider = new _engines_memory_storage_provider__WEBPACK_IMPORTED_MODULE_5__.MemoryStorageProvider();
13251
+ } else {
13252
+ // A custom IAsyncStorage implementation, used as-is.
13253
+ provider = defaultProvider;
13254
+ }
13255
+ return new AsyncStorage(Promise.resolve(provider), suffix);
13256
+ }
13105
13257
  if (persistentOrStrategy === 'localStorage' || persistentOrStrategy === 'sessionStorage') {
13106
13258
  if ((0,_engines_local_storage_provider__WEBPACK_IMPORTED_MODULE_4__.canUsePersistentStorage)(persistentOrStrategy)) {
13107
13259
  provider = new _engines_local_storage_provider__WEBPACK_IMPORTED_MODULE_4__.LocalStorageProvider(_storage__WEBPACK_IMPORTED_MODULE_6__.StorageKey + (suffix || ''), persistentOrStrategy);
@@ -13413,7 +13565,12 @@ function clearUseIndexedDBCache() {
13413
13565
  }
13414
13566
  delete(key) {
13415
13567
  try {
13416
- this.storage.removeItem(this.rootKey);
13568
+ const buffer = this.storage.getItem(this.rootKey);
13569
+ if (buffer) {
13570
+ const json = JSON.parse(buffer);
13571
+ delete json[key];
13572
+ this.storage.setItem(this.rootKey, JSON.stringify(json));
13573
+ }
13417
13574
  } catch (unused) {}
13418
13575
  return this;
13419
13576
  }
@@ -16611,9 +16768,23 @@ class ViewWithToolbar extends jodit_core_view_view__WEBPACK_IMPORTED_MODULE_11__
16611
16768
  if (!this.o.fullsize && ((0,jodit_core_helpers_checker_is_string__WEBPACK_IMPORTED_MODULE_7__.isString)(this.o.toolbar) || jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_5__.Dom.isHTMLElement(this.o.toolbar))) {
16612
16769
  return (0,jodit_core_helpers_utils_selector__WEBPACK_IMPORTED_MODULE_8__.resolveElement)(this.o.toolbar, this.o.shadowRoot || this.od);
16613
16770
  }
16614
- this.o.toolbar && jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_5__.Dom.appendChildFirst(this.container, this.__defaultToolbarContainer);
16771
+ this.o.toolbar && this.__appendToolbarBox();
16615
16772
  return this.__defaultToolbarContainer;
16616
16773
  }
16774
+ /**
16775
+ * Keep the toolbar box as the first child of the container, except that
16776
+ * children flagged with `data-jodit-above-toolbar` (e.g. the `above`
16777
+ * workplace slot used for presence bars and banners) stay above it.
16778
+ */ __appendToolbarBox() {
16779
+ const box = this.__defaultToolbarContainer;
16780
+ let anchor = this.container.firstElementChild;
16781
+ while(anchor && anchor !== box && anchor.hasAttribute('data-jodit-above-toolbar')){
16782
+ anchor = anchor.nextElementSibling;
16783
+ }
16784
+ if (anchor !== box) {
16785
+ this.container.insertBefore(box, anchor);
16786
+ }
16787
+ }
16617
16788
  /**
16618
16789
  * Change panel container
16619
16790
  */ setPanel(element) {
@@ -16811,7 +16982,7 @@ class View extends jodit_core_component_component__WEBPACK_IMPORTED_MODULE_3__.C
16811
16982
  /**
16812
16983
  * Container for persistent set/get value
16813
16984
  */ get asyncStorage() {
16814
- return jodit_core_storage_async_storage__WEBPACK_IMPORTED_MODULE_14__.AsyncStorage.makeStorage(true, this.id);
16985
+ return jodit_core_storage_async_storage__WEBPACK_IMPORTED_MODULE_14__.AsyncStorage.makeStorage(true, this.id, this.o.asyncStorage);
16815
16986
  }
16816
16987
  /**
16817
16988
  * Short alias for `create`
@@ -17895,6 +18066,12 @@ class Jodit extends jodit_modules__WEBPACK_IMPORTED_MODULE_10__.ViewWithToolbar
17895
18066
  element.style.display = 'none';
17896
18067
  }
17897
18068
  const SLOT = 'workplace-slot';
18069
+ // A slot that always stays ABOVE the toolbar (presence bars, banners…).
18070
+ // The `data-jodit-above-toolbar` attribute tells ViewWithToolbar to keep
18071
+ // the toolbar box below it when (re)attaching the toolbar container.
18072
+ const aboveSlot = this.c.div(this.getFullElName(SLOT, 'above'), NOEDIT);
18073
+ aboveSlot.setAttribute('data-jodit-above-toolbar', '');
18074
+ jodit_modules__WEBPACK_IMPORTED_MODULE_10__.Dom.appendChildFirst(container, aboveSlot);
17898
18075
  const topSlot = this.c.div(this.getFullElName(SLOT, 'top'), NOEDIT);
17899
18076
  container.appendChild(topSlot);
17900
18077
  const centerSlot = this.c.div(this.getFullElName(SLOT, 'center'), NOEDIT);
@@ -17927,6 +18104,7 @@ class Jodit extends jodit_modules__WEBPACK_IMPORTED_MODULE_10__.ViewWithToolbar
17927
18104
  container,
17928
18105
  workplace,
17929
18106
  slots: {
18107
+ above: aboveSlot,
17930
18108
  top: topSlot,
17931
18109
  bottom: bottomPanel,
17932
18110
  center: centerSlot,