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/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.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
  *
@@ -1823,7 +1843,7 @@ __webpack_require__.r(__webpack_exports__);
1823
1843
  * ```
1824
1844
  * @packageDocumentation
1825
1845
  * @module constants
1826
- */ const APP_VERSION = "4.12.43";
1846
+ */ const APP_VERSION = "4.13.3";
1827
1847
  // prettier-ignore
1828
1848
  const ES = "es2021";
1829
1849
  const IS_ES_MODERN = true;
@@ -11286,6 +11306,128 @@ class Selection {
11286
11306
  }
11287
11307
  return '';
11288
11308
  }
11309
+ /**
11310
+ * Splits the boundaries of the current selection and wraps every
11311
+ * contiguous run of selected inline content (grouped by block) into a
11312
+ * `<font>` element, returning those wrappers in document order.
11313
+ *
11314
+ * This is a pure-DOM replacement for the old
11315
+ * `nativeExecCommand('fontsize', false, '7')` trick which relied on the
11316
+ * browser to split the selection into `<font size="7">` fragments.
11317
+ */ __wrapSelectionFragments() {
11318
+ const range = this.range;
11319
+ this.__splitSelectionBoundaries(range);
11320
+ let root = range.commonAncestorContainer;
11321
+ if (jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isText(root)) {
11322
+ root = root.parentNode;
11323
+ }
11324
+ if (!root) {
11325
+ return [];
11326
+ }
11327
+ return this.__wrapSelectionRuns(this.__collectContainedNodes(root, range));
11328
+ }
11329
+ /**
11330
+ * Splits the text nodes at both ends of the range so that its boundaries
11331
+ * always fall between nodes. Afterwards every node inside the range is
11332
+ * fully (not partially) selected.
11333
+ */ __splitSelectionBoundaries(range) {
11334
+ let { startContainer, endContainer } = range;
11335
+ let { startOffset, endOffset } = range;
11336
+ if (jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isText(endContainer) && endOffset > 0 && endOffset < (endContainer.nodeValue?.length ?? 0)) {
11337
+ endContainer.splitText(endOffset);
11338
+ endOffset = endContainer.nodeValue?.length ?? endOffset;
11339
+ }
11340
+ if (jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isText(startContainer) && startOffset > 0 && startOffset < (startContainer.nodeValue?.length ?? 0)) {
11341
+ const middle = startContainer.splitText(startOffset);
11342
+ // Selection located inside a single text node - the tail we just
11343
+ // cut off is the actual selected fragment.
11344
+ if (startContainer === endContainer) {
11345
+ endContainer = middle;
11346
+ endOffset = middle.nodeValue?.length ?? 0;
11347
+ }
11348
+ startContainer = middle;
11349
+ startOffset = 0;
11350
+ }
11351
+ range.setStart(startContainer, startOffset);
11352
+ range.setEnd(endContainer, endOffset);
11353
+ // Normalize text-edge boundaries (e.g. `(text, 0)` or `(text, length)`)
11354
+ // to the element level so that containment checks based on
11355
+ // `selectNode()` treat a fully selected text node as contained.
11356
+ this.__normalizeRangeBoundary(range, true);
11357
+ this.__normalizeRangeBoundary(range, false);
11358
+ }
11359
+ __normalizeRangeBoundary(range, atStart) {
11360
+ const container = atStart ? range.startContainer : range.endContainer;
11361
+ if (!jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isText(container)) {
11362
+ return;
11363
+ }
11364
+ const offset = atStart ? range.startOffset : range.endOffset;
11365
+ const length = container.nodeValue?.length ?? 0;
11366
+ if (offset === 0) {
11367
+ atStart ? range.setStartBefore(container) : range.setEndBefore(container);
11368
+ } else if (offset >= length) {
11369
+ atStart ? range.setStartAfter(container) : range.setEndAfter(container);
11370
+ }
11371
+ }
11372
+ /**
11373
+ * Collects the highest-level nodes that are completely inside the range,
11374
+ * descending into nodes that are only partially selected.
11375
+ */ __collectContainedNodes(root, range) {
11376
+ const result = [];
11377
+ (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.toArray)(root.childNodes).forEach((child)=>{
11378
+ if (this.__isFullyContained(range, child)) {
11379
+ result.push(child);
11380
+ } else if (child.childNodes.length && range.intersectsNode(child)) {
11381
+ result.push(...this.__collectContainedNodes(child, range));
11382
+ }
11383
+ });
11384
+ return result;
11385
+ }
11386
+ __isFullyContained(range, node) {
11387
+ const nodeRange = this.createRange();
11388
+ nodeRange.selectNode(node);
11389
+ return range.compareBoundaryPoints(Range.START_TO_START, nodeRange) <= 0 && range.compareBoundaryPoints(Range.END_TO_END, nodeRange) >= 0;
11390
+ }
11391
+ /**
11392
+ * Wraps every contiguous run of selected inline siblings into a `<font>`
11393
+ * element. Block-level nodes are never wrapped themselves - their inline
11394
+ * content is wrapped instead, keeping every `<font>` inside a single block.
11395
+ */ __wrapSelectionRuns(nodes) {
11396
+ const fonts = [];
11397
+ let run = [];
11398
+ const flush = ()=>{
11399
+ if (run.length) {
11400
+ fonts.push(this.__wrapRunInFont(run));
11401
+ run = [];
11402
+ }
11403
+ };
11404
+ nodes.forEach((node)=>{
11405
+ if (jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isElement(node) && this.__isOrContainsBlock(node)) {
11406
+ flush();
11407
+ fonts.push(...this.__wrapSelectionRuns((0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.toArray)(node.childNodes)));
11408
+ } else {
11409
+ if (run.length && run[run.length - 1].parentNode !== node.parentNode) {
11410
+ flush();
11411
+ }
11412
+ run.push(node);
11413
+ }
11414
+ });
11415
+ flush();
11416
+ return fonts;
11417
+ }
11418
+ __isOrContainsBlock(node) {
11419
+ if (jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.isBlock(node)) {
11420
+ return true;
11421
+ }
11422
+ return (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.toArray)(node.childNodes).some((child)=>this.__isOrContainsBlock(child));
11423
+ }
11424
+ __wrapRunInFont(run) {
11425
+ const font = this.j.createInside.element('font');
11426
+ const [first] = run;
11427
+ first.parentNode?.insertBefore(font, first);
11428
+ run.forEach((node)=>font.appendChild(node));
11429
+ return font;
11430
+ }
11289
11431
  /**
11290
11432
  * Wrap all selected fragments inside Tag or apply some callback
11291
11433
  */ *wrapInTagGen(fakes) {
@@ -11299,20 +11441,7 @@ class Selection {
11299
11441
  jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_4__.Dom.unwrap(font);
11300
11442
  return;
11301
11443
  }
11302
- // fix issue https://github.com/xdan/jodit/issues/65
11303
- (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.$$)('*[style*=font-size]', this.area).forEach((elm)=>{
11304
- (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.attr)(elm, 'data-font-size', elm.style.fontSize.toString());
11305
- elm.style.removeProperty('font-size');
11306
- });
11307
- this.j.nativeExecCommand('fontsize', false, '7');
11308
- (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.$$)('*[data-font-size]', this.area).forEach((elm)=>{
11309
- const fontSize = (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.attr)(elm, 'data-font-size');
11310
- if (fontSize) {
11311
- elm.style.fontSize = fontSize;
11312
- (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.attr)(elm, 'data-font-size', null);
11313
- }
11314
- });
11315
- const elms = (0,jodit_core_helpers__WEBPACK_IMPORTED_MODULE_5__.$$)('font[size="7"]', this.area);
11444
+ const elms = this.__wrapSelectionFragments();
11316
11445
  for (const font of elms){
11317
11446
  const { firstChild, lastChild } = font;
11318
11447
  if (firstChild && firstChild === lastChild && (0,jodit_core_helpers_checker__WEBPACK_IMPORTED_MODULE_6__.isMarker)(firstChild)) {
@@ -13031,9 +13160,23 @@ class AsyncStorage {
13031
13160
  await provider.close();
13032
13161
  }
13033
13162
  }
13034
- static makeStorage(persistentOrStrategy = false, suffix) {
13163
+ static makeStorage(persistentOrStrategy = false, suffix, options) {
13035
13164
  let provider = undefined;
13036
13165
  let storage = null;
13166
+ // An explicit `defaultProvider` overrides the strategy-based selection
13167
+ // below and decides which provider backs the storage.
13168
+ const defaultProvider = options?.defaultProvider;
13169
+ if (defaultProvider != null) {
13170
+ if (defaultProvider === 'local') {
13171
+ provider = (0,_engines_local_storage_provider__WEBPACK_IMPORTED_MODULE_3__.canUsePersistentStorage)('localStorage') ? new _engines_local_storage_provider__WEBPACK_IMPORTED_MODULE_3__.LocalStorageProvider(_storage__WEBPACK_IMPORTED_MODULE_5__.StorageKey + (suffix || '')) : new _engines_memory_storage_provider__WEBPACK_IMPORTED_MODULE_4__.MemoryStorageProvider();
13172
+ } else if (defaultProvider === 'memory') {
13173
+ provider = new _engines_memory_storage_provider__WEBPACK_IMPORTED_MODULE_4__.MemoryStorageProvider();
13174
+ } else {
13175
+ // A custom IAsyncStorage implementation, used as-is.
13176
+ provider = defaultProvider;
13177
+ }
13178
+ return new AsyncStorage(Promise.resolve(provider), suffix);
13179
+ }
13037
13180
  if (persistentOrStrategy === 'localStorage' || persistentOrStrategy === 'sessionStorage') {
13038
13181
  if ((0,_engines_local_storage_provider__WEBPACK_IMPORTED_MODULE_3__.canUsePersistentStorage)(persistentOrStrategy)) {
13039
13182
  provider = new _engines_local_storage_provider__WEBPACK_IMPORTED_MODULE_3__.LocalStorageProvider(_storage__WEBPACK_IMPORTED_MODULE_5__.StorageKey + (suffix || ''), persistentOrStrategy);
@@ -13321,7 +13464,12 @@ function clearUseIndexedDBCache() {
13321
13464
  }
13322
13465
  delete(key) {
13323
13466
  try {
13324
- this.storage.removeItem(this.rootKey);
13467
+ const buffer = this.storage.getItem(this.rootKey);
13468
+ if (buffer) {
13469
+ const json = JSON.parse(buffer);
13470
+ delete json[key];
13471
+ this.storage.setItem(this.rootKey, JSON.stringify(json));
13472
+ }
13325
13473
  } catch {}
13326
13474
  return this;
13327
13475
  }
@@ -16489,9 +16637,23 @@ class ViewWithToolbar extends jodit_core_view_view__WEBPACK_IMPORTED_MODULE_11__
16489
16637
  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))) {
16490
16638
  return (0,jodit_core_helpers_utils_selector__WEBPACK_IMPORTED_MODULE_8__.resolveElement)(this.o.toolbar, this.o.shadowRoot || this.od);
16491
16639
  }
16492
- this.o.toolbar && jodit_core_dom_dom__WEBPACK_IMPORTED_MODULE_5__.Dom.appendChildFirst(this.container, this.__defaultToolbarContainer);
16640
+ this.o.toolbar && this.__appendToolbarBox();
16493
16641
  return this.__defaultToolbarContainer;
16494
16642
  }
16643
+ /**
16644
+ * Keep the toolbar box as the first child of the container, except that
16645
+ * children flagged with `data-jodit-above-toolbar` (e.g. the `above`
16646
+ * workplace slot used for presence bars and banners) stay above it.
16647
+ */ __appendToolbarBox() {
16648
+ const box = this.__defaultToolbarContainer;
16649
+ let anchor = this.container.firstElementChild;
16650
+ while(anchor && anchor !== box && anchor.hasAttribute('data-jodit-above-toolbar')){
16651
+ anchor = anchor.nextElementSibling;
16652
+ }
16653
+ if (anchor !== box) {
16654
+ this.container.insertBefore(box, anchor);
16655
+ }
16656
+ }
16495
16657
  /**
16496
16658
  * Change panel container
16497
16659
  */ setPanel(element) {
@@ -16686,7 +16848,7 @@ class View extends jodit_core_component_component__WEBPACK_IMPORTED_MODULE_3__.C
16686
16848
  /**
16687
16849
  * Container for persistent set/get value
16688
16850
  */ get asyncStorage() {
16689
- return jodit_core_storage_async_storage__WEBPACK_IMPORTED_MODULE_14__.AsyncStorage.makeStorage(true, this.id);
16851
+ return jodit_core_storage_async_storage__WEBPACK_IMPORTED_MODULE_14__.AsyncStorage.makeStorage(true, this.id, this.o.asyncStorage);
16690
16852
  }
16691
16853
  /**
16692
16854
  * Short alias for `create`
@@ -17765,6 +17927,12 @@ class Jodit extends jodit_modules__WEBPACK_IMPORTED_MODULE_9__.ViewWithToolbar {
17765
17927
  element.style.display = 'none';
17766
17928
  }
17767
17929
  const SLOT = 'workplace-slot';
17930
+ // A slot that always stays ABOVE the toolbar (presence bars, banners…).
17931
+ // The `data-jodit-above-toolbar` attribute tells ViewWithToolbar to keep
17932
+ // the toolbar box below it when (re)attaching the toolbar container.
17933
+ const aboveSlot = this.c.div(this.getFullElName(SLOT, 'above'), NOEDIT);
17934
+ aboveSlot.setAttribute('data-jodit-above-toolbar', '');
17935
+ jodit_modules__WEBPACK_IMPORTED_MODULE_9__.Dom.appendChildFirst(container, aboveSlot);
17768
17936
  const topSlot = this.c.div(this.getFullElName(SLOT, 'top'), NOEDIT);
17769
17937
  container.appendChild(topSlot);
17770
17938
  const centerSlot = this.c.div(this.getFullElName(SLOT, 'center'), NOEDIT);
@@ -17797,6 +17965,7 @@ class Jodit extends jodit_modules__WEBPACK_IMPORTED_MODULE_9__.ViewWithToolbar {
17797
17965
  container,
17798
17966
  workplace,
17799
17967
  slots: {
17968
+ above: aboveSlot,
17800
17969
  top: topSlot,
17801
17970
  bottom: bottomPanel,
17802
17971
  center: centerSlot,