monobill-mintui 0.6.736 → 0.6.738

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 (72) hide show
  1. package/bin/component-dependencies.json +2 -1
  2. package/dist/components/chunks/{date-picker-CTtYAkmM.js → date-picker-R8J7EzuF.js} +1 -1
  3. package/dist/components/chunks/{date-picker-CUf5eJR3.js → date-picker-STjYRdxE.js} +1 -1
  4. package/dist/components/chunks/{popover-DD7uyRXy.js → popover-7-PJT1-5.js} +14 -2
  5. package/dist/components/chunks/popover-CD0v0njp.js +1 -0
  6. package/dist/components/chunks/{select-DOMW7Plx.js → select-hL6gV7mL.js} +1 -1
  7. package/dist/components/chunks/{select-CX9oOwl5.js → select-oEt5Dm4P.js} +1 -1
  8. package/dist/components/chunks/{time-picker-C7pJvGSM.js → time-picker-B7oXBU8q.js} +1 -1
  9. package/dist/components/chunks/{time-picker-BaoT0NtA.js → time-picker-QzH9kywR.js} +1 -1
  10. package/dist/components/date-picker/browser.js +1 -1
  11. package/dist/components/date-picker/index.cjs +1 -1
  12. package/dist/components/date-picker/index.js +1 -1
  13. package/dist/components/datetime-picker/browser.js +2 -2
  14. package/dist/components/datetime-picker/index.cjs +1 -1
  15. package/dist/components/datetime-picker/index.js +2 -2
  16. package/dist/components/editor/Editor.d.ts +31 -2
  17. package/dist/components/editor/Editor.d.ts.map +1 -1
  18. package/dist/components/editor/browser.js +599 -247
  19. package/dist/components/editor/index.cjs +14 -8
  20. package/dist/components/editor/index.d.ts +1 -0
  21. package/dist/components/editor/index.d.ts.map +1 -1
  22. package/dist/components/editor/index.js +599 -247
  23. package/dist/components/link/browser.js +1 -1
  24. package/dist/components/link/index.cjs +1 -1
  25. package/dist/components/link/index.js +1 -1
  26. package/dist/components/navigation/browser.js +2 -2
  27. package/dist/components/navigation/index.cjs +1 -1
  28. package/dist/components/navigation/index.js +2 -2
  29. package/dist/components/page/browser.js +1 -1
  30. package/dist/components/page/index.cjs +1 -1
  31. package/dist/components/page/index.js +1 -1
  32. package/dist/components/popover/Popover.d.ts +4 -0
  33. package/dist/components/popover/Popover.d.ts.map +1 -1
  34. package/dist/components/popover/browser.js +1 -1
  35. package/dist/components/popover/index.cjs +1 -1
  36. package/dist/components/popover/index.js +1 -1
  37. package/dist/components/resource-table/browser.js +4 -4
  38. package/dist/components/resource-table/index.cjs +1 -1
  39. package/dist/components/resource-table/index.js +4 -4
  40. package/dist/components/search/browser.js +1 -1
  41. package/dist/components/search/index.cjs +1 -1
  42. package/dist/components/search/index.js +1 -1
  43. package/dist/components/select/browser.js +1 -1
  44. package/dist/components/select/index.cjs +1 -1
  45. package/dist/components/select/index.js +1 -1
  46. package/dist/components/side-navigation/browser.js +1 -1
  47. package/dist/components/side-navigation/index.cjs +1 -1
  48. package/dist/components/side-navigation/index.js +1 -1
  49. package/dist/components/table/browser.js +1 -1
  50. package/dist/components/table/index.cjs +1 -1
  51. package/dist/components/table/index.js +1 -1
  52. package/dist/components/tags/browser.js +1 -1
  53. package/dist/components/tags/index.cjs +1 -1
  54. package/dist/components/tags/index.js +1 -1
  55. package/dist/components/time-picker/browser.js +1 -1
  56. package/dist/components/time-picker/index.cjs +1 -1
  57. package/dist/components/time-picker/index.js +1 -1
  58. package/dist/components/tree/browser.js +1 -1
  59. package/dist/components/tree/index.cjs +1 -1
  60. package/dist/components/tree/index.js +1 -1
  61. package/dist/editor.css +1 -1
  62. package/dist/index.cjs +15 -9
  63. package/dist/index.css +1 -1
  64. package/dist/index.js +610 -248
  65. package/package.json +1 -1
  66. package/dist/components/chunks/popover-2Cnva3AN.js +0 -1
  67. /package/dist/components/chunks/{link-B_fNmwOk.js → link-B4Hdsb2b.js} +0 -0
  68. /package/dist/components/chunks/{link-BxTQfAW9.js → link-rv2WDJw2.js} +0 -0
  69. /package/dist/components/chunks/{search-BXku4V9r.js → search-C3uTkxhf.js} +0 -0
  70. /package/dist/components/chunks/{search-DKHcIR2F.js → search-qSlGRuMR.js} +0 -0
  71. /package/dist/components/chunks/{table-IU2Vmjwk.js → table-BZ73d2Yb.js} +0 -0
  72. /package/dist/components/chunks/{table-HnSpIfny.js → table-D82Gvcva.js} +0 -0
package/dist/index.js CHANGED
@@ -351,124 +351,124 @@ var D = {
351
351
  s(D);
352
352
  //#endregion
353
353
  //#region src/components/icon/icons/caret-down.js
354
- var ee = {
354
+ var O = {
355
355
  name: "caret-down",
356
356
  viewBox: "0 0 24 24",
357
357
  path: "M19 9l-7 7-7-7",
358
358
  strokeLinecap: "round",
359
359
  strokeLinejoin: "round"
360
360
  };
361
- s(ee);
361
+ s(O);
362
362
  //#endregion
363
363
  //#region src/components/icon/icons/caret-left.js
364
- var O = {
364
+ var k = {
365
365
  name: "caret-left",
366
366
  viewBox: "0 0 24 24",
367
367
  path: "M15 19l-7-7 7-7",
368
368
  strokeLinecap: "round",
369
369
  strokeLinejoin: "round"
370
370
  };
371
- s(O);
371
+ s(k);
372
372
  //#endregion
373
373
  //#region src/components/icon/icons/caret-right.js
374
- var k = {
374
+ var A = {
375
375
  name: "caret-right",
376
376
  viewBox: "0 0 24 24",
377
377
  path: "M9 5l7 7-7 7",
378
378
  strokeLinecap: "round",
379
379
  strokeLinejoin: "round"
380
380
  };
381
- s(k);
381
+ s(A);
382
382
  //#endregion
383
383
  //#region src/components/icon/icons/caret-up.js
384
- var A = {
384
+ var j = {
385
385
  name: "caret-up",
386
386
  viewBox: "0 0 24 24",
387
387
  path: "M5 15l7-7 7 7",
388
388
  strokeLinecap: "round",
389
389
  strokeLinejoin: "round"
390
390
  };
391
- s(A);
391
+ s(j);
392
392
  //#endregion
393
393
  //#region src/components/icon/icons/chart-bar.js
394
- var j = {
394
+ var M = {
395
395
  name: "chart-bar",
396
396
  viewBox: "0 0 24 24",
397
397
  path: "M3 20h18M6 17v-5m4 5V7m4 10v-8m4 8v-3",
398
398
  strokeLinecap: "round",
399
399
  strokeLinejoin: "round"
400
400
  };
401
- s(j);
401
+ s(M);
402
402
  //#endregion
403
403
  //#region src/components/icon/icons/chart-line.js
404
- var M = {
404
+ var ee = {
405
405
  name: "chart-line",
406
406
  viewBox: "0 0 24 24",
407
407
  path: "M3 20h18M4 18V4m2 11l4-4 3 3 5-6m0 0h-4m4 0v4",
408
408
  strokeLinecap: "round",
409
409
  strokeLinejoin: "round"
410
410
  };
411
- s(M);
411
+ s(ee);
412
412
  //#endregion
413
413
  //#region src/components/icon/icons/chat.js
414
- var te = {
414
+ var N = {
415
415
  name: "chat",
416
416
  viewBox: "0 0 24 24",
417
417
  path: "M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z",
418
418
  strokeLinecap: "round",
419
419
  strokeLinejoin: "round"
420
420
  };
421
- s(te);
421
+ s(N);
422
422
  //#endregion
423
423
  //#region src/components/icon/icons/check.js
424
- var N = {
424
+ var P = {
425
425
  name: "check",
426
426
  viewBox: "0 0 24 24",
427
427
  path: "M5 13l4 4L19 7",
428
428
  strokeLinecap: "round",
429
429
  strokeLinejoin: "round"
430
430
  };
431
- s(N);
431
+ s(P);
432
432
  //#endregion
433
433
  //#region src/components/icon/icons/collapse.js
434
- var P = {
434
+ var te = {
435
435
  name: "collapse",
436
436
  viewBox: "0 0 24 24",
437
437
  path: "M8 3v3a2 2 0 01-2 2H3m18 0h-3a2 2 0 01-2-2V3M3 16h3a2 2 0 012 2v3m13-5h-3a2 2 0 00-2 2v3",
438
438
  strokeLinecap: "round",
439
439
  strokeLinejoin: "round"
440
440
  };
441
- s(P);
441
+ s(te);
442
442
  //#endregion
443
443
  //#region src/components/icon/icons/clock.js
444
- var ne = {
444
+ var F = {
445
445
  name: "clock",
446
446
  viewBox: "0 0 24 24",
447
447
  path: "M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z",
448
448
  strokeLinecap: "round",
449
449
  strokeLinejoin: "round"
450
450
  };
451
- s(ne);
451
+ s(F);
452
452
  //#endregion
453
453
  //#region src/components/icon/icons/close.js
454
- var F = {
454
+ var I = {
455
455
  name: "close",
456
456
  viewBox: "0 0 24 24",
457
457
  path: "M6 18L18 6M6 6l12 12",
458
458
  strokeLinecap: "round",
459
459
  strokeLinejoin: "round"
460
460
  };
461
- s(F);
461
+ s(I);
462
462
  //#endregion
463
463
  //#region src/components/icon/icons/code.js
464
- var I = {
464
+ var ne = {
465
465
  name: "code",
466
466
  viewBox: "0 0 24 24",
467
467
  path: "M9 4H7a2 2 0 00-2 2v3a3 3 0 01-3 3 3 3 0 013 3v3a2 2 0 002 2h2M15 4h2a2 2 0 012 2v3a3 3 0 003 3 3 3 0 00-3 3v3a2 2 0 01-2 2h-2",
468
468
  strokeLinecap: "round",
469
469
  strokeLinejoin: "round"
470
470
  };
471
- s(I);
471
+ s(ne);
472
472
  //#endregion
473
473
  //#region src/components/icon/icons/copy.js
474
474
  var re = {
@@ -491,34 +491,34 @@ var ie = {
491
491
  s(ie);
492
492
  //#endregion
493
493
  //#region src/components/icon/icons/delete.js
494
- var ae = {
494
+ var L = {
495
495
  name: "delete",
496
496
  viewBox: "0 0 24 24",
497
497
  path: "M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16",
498
498
  strokeLinecap: "round",
499
499
  strokeLinejoin: "round"
500
500
  };
501
- s(ae);
501
+ s(L);
502
502
  //#endregion
503
503
  //#region src/components/icon/icons/desktop.js
504
- var L = {
504
+ var R = {
505
505
  name: "desktop",
506
506
  viewBox: "0 0 24 24",
507
507
  path: "M4 4h16a1 1 0 0 1 1 1v11a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1ZM12 17v3m-4 0h8",
508
508
  strokeLinecap: "round",
509
509
  strokeLinejoin: "round"
510
510
  };
511
- s(L);
511
+ s(R);
512
512
  //#endregion
513
513
  //#region src/components/icon/icons/desktop-screen.js
514
- var R = {
514
+ var ae = {
515
515
  name: "desktop-screen",
516
516
  viewBox: "0 0 24 24",
517
517
  path: "M3 5a2 2 0 012-2h14a2 2 0 012 2v9a2 2 0 01-2 2h-5m-4 0H5a2 2 0 01-2-2V5m7 11v4m-2 0h8",
518
518
  strokeLinecap: "round",
519
519
  strokeLinejoin: "round"
520
520
  };
521
- s(R);
521
+ s(ae);
522
522
  //#endregion
523
523
  //#region src/components/icon/icons/documentation.js
524
524
  var oe = {
@@ -1764,7 +1764,7 @@ var mn = {
1764
1764
  strokeLinecap: "round",
1765
1765
  strokeLinejoin: "round"
1766
1766
  };
1767
- s(mn), s(u), s(d), s(f), s(p), s(m), s(h), s(g), s(_), s(v), s(y), s(b), s(x), s(S), s(C), s(w), s(T), s(E), s(D), s(ee), s(O), s(k), s(A), s(j), s(M), s(te), s(N), s(P), s(ne), s(F), s(I), s(re), s(ie), s(ae), s(L), s(R), s(oe), s(se), s(ce), s(le), s(ue), s(de), s(fe), s(pe), s(me), s(he), s(ge), s(_e), s(ve), s(ye), s(be), s(xe), s(Se), s(Ce), s(we), s(Te), s(Ee), s(De), s(Oe), s(ke), s(Ae), s(je), s(Me), s(Ne), s(Pe), s(Fe), s(Ie), s(Le), s(Re), s(ze), s(Be), s(Ve), s(He), s(Ue), s(We), s(Ge), s(Ke), s(qe), s(Je), s(Ye), s(Xe), s(Ze), s(Qe), s($e), s(et), s(tt), s(nt), s(rt), s(it), s(at), s(ot), s(st), s(ct), s(lt), s(ut), s(dt), s(ft), s(pt), s(mt), s(ht), s(gt), s(_t), s(vt), s(yt), s(bt), s(xt), s(St), s(Ct), s(wt), s(Tt), s(Et), s(Dt), s(Ot), s(kt), s(At), s(jt), s(Mt), s(Nt), s(Pt), s(Ft), s(It), s(Lt), s(Rt), s(zt), s(Bt), s(Vt), s(Ht), s(Ut), s(Wt), s(Gt), s(Kt), s(qt), s(Jt), s(Yt), s(Xt), s(Zt), s(Qt), s($t), s(en), s(tn), s(nn), s(rn), s(an), s(on), s(sn), s(cn), s(ln), s(un), s(dn), s(fn), s(pn), s(mn);
1767
+ s(mn), s(u), s(d), s(f), s(p), s(m), s(h), s(g), s(_), s(v), s(y), s(b), s(x), s(S), s(C), s(w), s(T), s(E), s(D), s(O), s(k), s(A), s(j), s(M), s(ee), s(N), s(P), s(te), s(F), s(I), s(ne), s(re), s(ie), s(L), s(R), s(ae), s(oe), s(se), s(ce), s(le), s(ue), s(de), s(fe), s(pe), s(me), s(he), s(ge), s(_e), s(ve), s(ye), s(be), s(xe), s(Se), s(Ce), s(we), s(Te), s(Ee), s(De), s(Oe), s(ke), s(Ae), s(je), s(Me), s(Ne), s(Pe), s(Fe), s(Ie), s(Le), s(Re), s(ze), s(Be), s(Ve), s(He), s(Ue), s(We), s(Ge), s(Ke), s(qe), s(Je), s(Ye), s(Xe), s(Ze), s(Qe), s($e), s(et), s(tt), s(nt), s(rt), s(it), s(at), s(ot), s(st), s(ct), s(lt), s(ut), s(dt), s(ft), s(pt), s(mt), s(ht), s(gt), s(_t), s(vt), s(yt), s(bt), s(xt), s(St), s(Ct), s(wt), s(Tt), s(Et), s(Dt), s(Ot), s(kt), s(At), s(jt), s(Mt), s(Nt), s(Pt), s(Ft), s(It), s(Lt), s(Rt), s(zt), s(Bt), s(Vt), s(Ht), s(Ut), s(Wt), s(Gt), s(Kt), s(qt), s(Jt), s(Yt), s(Xt), s(Zt), s(Qt), s($t), s(en), s(tn), s(nn), s(rn), s(an), s(on), s(sn), s(cn), s(ln), s(un), s(dn), s(fn), s(pn), s(mn);
1768
1768
  //#endregion
1769
1769
  //#region src/components/spinner/Spinner.js
1770
1770
  var hn = class extends HTMLElement {
@@ -2978,7 +2978,7 @@ var Dn = class extends HTMLElement {
2978
2978
  ];
2979
2979
  }
2980
2980
  constructor() {
2981
- super(), this._trigger = null, this._triggerLookupTimer = null, this._clickHandler = null, this._hoverEnterHandler = null, this._hoverLeaveHandler = null, this._outsideHandler = null, this._escapeHandler = null, this._positionHandler = null, this._scrollHandler = null, this._resizeObserver = null, this._hoverCloseTimer = null, this._closeAnimationTimer = null, this._blobAnimation = null, this._disposeScrollFade = null;
2981
+ super(), this._trigger = null, this._triggerLookupTimer = null, this._clickHandler = null, this._hoverEnterHandler = null, this._hoverLeaveHandler = null, this._outsideHandler = null, this._escapeHandler = null, this._positionHandler = null, this._scrollHandler = null, this._resizeObserver = null, this._hoverCloseTimer = null, this._closeAnimationTimer = null, this._blobAnimation = null, this._disposeScrollFade = null, this._selectPopoverPlaceholder = null;
2982
2982
  }
2983
2983
  connectedCallback() {
2984
2984
  this.render(), this._disposeScrollFade?.();
@@ -3048,6 +3048,18 @@ var Dn = class extends HTMLElement {
3048
3048
  _syncLayerZIndex() {
3049
3049
  this.style.zIndex = String(this._getLayerZIndex());
3050
3050
  }
3051
+ _portalSelectPopover() {
3052
+ if (!this.classList.contains("mint-select-popover") || this.parentElement === document.body) return;
3053
+ let e = this.parentNode;
3054
+ if (!e) return;
3055
+ let t = document.createComment("mint-select-popover");
3056
+ e.insertBefore(t, this), this._selectPopoverPlaceholder = t, document.body.appendChild(this), this._syncLayerZIndex();
3057
+ }
3058
+ _restoreSelectPopover() {
3059
+ if (!this._selectPopoverPlaceholder) return;
3060
+ let e = this._selectPopoverPlaceholder;
3061
+ this._selectPopoverPlaceholder = null, e.parentNode ? e.parentNode.replaceChild(this, e) : this.parentElement === document.body && this.remove();
3062
+ }
3051
3063
  _scheduleHoverClose() {
3052
3064
  clearTimeout(this._hoverCloseTimer), this._hoverCloseTimer = setTimeout(() => {
3053
3065
  !this._trigger?.matches(":hover") && !this.matches(":hover") && this.close();
@@ -3210,7 +3222,7 @@ var Dn = class extends HTMLElement {
3210
3222
  }
3211
3223
  render() {
3212
3224
  let e = this.isOpen();
3213
- this._syncLayerZIndex();
3225
+ e ? this._portalSelectPopover() : this._restoreSelectPopover(), this._syncLayerZIndex();
3214
3226
  let t = this.hasAttribute("data-open") || this.dataset.state === "closing", n = this.hasAttribute("data-open");
3215
3227
  if (this.toggleAttribute("data-open", e), this.setAttribute("aria-hidden", String(!e)), this._trigger && this._trigger.setAttribute("aria-expanded", String(e)), e) {
3216
3228
  clearTimeout(this._closeAnimationTimer);
@@ -7346,7 +7358,7 @@ var tr = class extends HTMLElement {
7346
7358
  x.className = "mint-date-calendar-grid", x.setAttribute("role", "group"), x.setAttribute("aria-label", `${n[this._currentMonth]} ${this._currentYear}`);
7347
7359
  let S = this.getMin() ? this._parseDateString(this.getMin(), this.getFormat()) : null, C = this.getMax() ? this._parseDateString(this.getMax(), this.getFormat()) : null;
7348
7360
  this.getDisabledDates();
7349
- let w = this._currentMonth === 0 ? 11 : this._currentMonth - 1, T = this._currentMonth === 0 ? this._currentYear - 1 : this._currentYear, E = this._getDaysInMonth(w, T), D = this._currentMonth === 11 ? 0 : this._currentMonth + 1, ee = this._currentMonth === 11 ? this._currentYear + 1 : this._currentYear, O = t + e, k = Math.ceil(O / 7) * 7 - O, A = (e, t, n) => {
7361
+ let w = this._currentMonth === 0 ? 11 : this._currentMonth - 1, T = this._currentMonth === 0 ? this._currentYear - 1 : this._currentYear, E = this._getDaysInMonth(w, T), D = this._currentMonth === 11 ? 0 : this._currentMonth + 1, O = this._currentMonth === 11 ? this._currentYear + 1 : this._currentYear, k = t + e, A = Math.ceil(k / 7) * 7 - k, j = (e, t, n) => {
7350
7362
  let r = this._isToday(e), i = this._isDateSelected(e), a = this._isDateInRange(e), o = S && e < S || C && e > C || this._isDateDisabled(e), s = "is-fully-rounded", c = this._isRange && this._selectedStartDate && !this._selectedEndDate && this._hoveredDate, l = c && this._selectedStartDate && this._hoveredDate && this._selectedStartDate < this._hoveredDate ? this._selectedStartDate : c && this._hoveredDate ? this._hoveredDate : null, u = c && this._selectedStartDate && this._hoveredDate && this._selectedStartDate < this._hoveredDate ? this._hoveredDate : c && this._selectedStartDate ? this._selectedStartDate : null, d = l !== null && this._isSameDate(e, l), f = u !== null && this._isSameDate(e, u), p = this._hoveredDate !== null && this._isSameDate(e, this._hoveredDate), m = c && this._hoveredDate && this._selectedStartDate ? !this._rangeIncludesDisabledDates(this._selectedStartDate < this._hoveredDate ? this._selectedStartDate : this._hoveredDate, this._selectedStartDate < this._hoveredDate ? this._hoveredDate : this._selectedStartDate) : !1;
7351
7363
  if (this._isRange && this._selectedStartDate && this._selectedEndDate) {
7352
7364
  let t = this._isSameDate(e, this._selectedStartDate), n = this._isSameDate(e, this._selectedEndDate);
@@ -7384,15 +7396,15 @@ var tr = class extends HTMLElement {
7384
7396
  }, { passive: !0 }))), h;
7385
7397
  };
7386
7398
  for (let e = t - 1; e >= 0; e--) {
7387
- let t = E - e, n = A(new Date(T, w, t), t, !1);
7399
+ let t = E - e, n = j(new Date(T, w, t), t, !1);
7388
7400
  x.appendChild(n);
7389
7401
  }
7390
7402
  for (let t = 1; t <= e; t++) {
7391
- let e = A(new Date(this._currentYear, this._currentMonth, t), t, !0);
7403
+ let e = j(new Date(this._currentYear, this._currentMonth, t), t, !0);
7392
7404
  x.appendChild(e);
7393
7405
  }
7394
- for (let e = 1; e <= k; e++) {
7395
- let t = A(new Date(ee, D, e), e, !1);
7406
+ for (let e = 1; e <= A; e++) {
7407
+ let t = j(new Date(O, D, e), e, !1);
7396
7408
  x.appendChild(t);
7397
7409
  }
7398
7410
  if (this._isRange && this._selectedStartDate && !this._selectedEndDate && (x.addEventListener("mouseleave", () => {
@@ -15514,6 +15526,50 @@ customElements.get("mint-tree") || a("mint-tree", Yr);
15514
15526
  function Z(e) {
15515
15527
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;");
15516
15528
  }
15529
+ function Xr(e) {
15530
+ return e.replace(/\r\n?/g, "\n").split("\n").map((e) => e.replace(/[\t ]+$/g, "")).join("\n").trim().replace(/\n{3,}/g, "\n\n");
15531
+ }
15532
+ function Zr(e, t) {
15533
+ let n = t.createElement("template");
15534
+ n.innerHTML = e.trim();
15535
+ let r = new Set(/* @__PURE__ */ "address.article.aside.blockquote.body.caption.dd.details.dialog.div.dl.dt.fieldset.figcaption.figure.footer.form.h1.h2.h3.h4.h5.h6.header.hr.li.main.nav.ol.p.pre.section.summary.table.tbody.td.tfoot.th.thead.tr.ul".split(".")), i = new Set([
15536
+ "area",
15537
+ "base",
15538
+ "br",
15539
+ "col",
15540
+ "embed",
15541
+ "hr",
15542
+ "img",
15543
+ "input",
15544
+ "link",
15545
+ "meta",
15546
+ "param",
15547
+ "source",
15548
+ "track",
15549
+ "wbr"
15550
+ ]), a = (e) => " ".repeat(e), o = (e) => Array.from(e.attributes).map((e) => ` ${e.name}="${Z(e.value)}"`).join(""), s = (e) => {
15551
+ if (e.nodeType === Node.TEXT_NODE) return Z(e.textContent || "");
15552
+ if (e.nodeType === Node.COMMENT_NODE) return `<!--${e.nodeValue || ""}-->`;
15553
+ if (e.nodeType !== Node.ELEMENT_NODE) return "";
15554
+ let t = e, n = t.tagName.toLowerCase(), r = `<${n}${o(t)}>`;
15555
+ return i.has(n) ? r : `${r}${Array.from(t.childNodes).map(s).join("")}</${n}>`;
15556
+ }, c = (e, t) => {
15557
+ if (e.nodeType === Node.TEXT_NODE) return Z(e.textContent || "");
15558
+ if (e.nodeType === Node.COMMENT_NODE) return `${a(t)}<!--${e.nodeValue || ""}-->`;
15559
+ if (e.nodeType !== Node.ELEMENT_NODE) return "";
15560
+ let n = e, l = n.tagName.toLowerCase(), u = `<${l}${o(n)}>`;
15561
+ if (i.has(l)) return `${a(t)}${u}`;
15562
+ let d = Array.from(n.childNodes);
15563
+ if (l === "pre" || d.every((e) => e.nodeType === Node.TEXT_NODE || e.nodeType === Node.ELEMENT_NODE && !r.has(e.tagName.toLowerCase()))) return `${a(t)}${u}${d.map(s).join("")}</${l}>`;
15564
+ let f = d.flatMap((e) => {
15565
+ if (e.nodeType === Node.TEXT_NODE && !(e.textContent || "").trim()) return [];
15566
+ let n = c(e, t + 1);
15567
+ return n ? [n] : [];
15568
+ });
15569
+ return f.length ? `${a(t)}${u}\n${f.join("\n")}\n${a(t)}</${l}>` : `${a(t)}${u}</${l}>`;
15570
+ };
15571
+ return Array.from(n.content.childNodes).map((e) => c(e, 0)).filter(Boolean).join("\n");
15572
+ }
15517
15573
  function Q(e) {
15518
15574
  return e.replace(/\r\n?/g, "\n").split(/\n{2,}/).map((e) => {
15519
15575
  let t = e.trim();
@@ -15542,7 +15598,7 @@ function Q(e) {
15542
15598
  function $(e) {
15543
15599
  return Z(e).replace(/`([^`]+)`/g, "<code>$1</code>").replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>").replace(/__(.+?)__/g, "<strong>$1</strong>").replace(/\*(.+?)\*/g, "<em>$1</em>").replace(/_(.+?)_/g, "<em>$1</em>").replace(/~~(.+?)~~/g, "<s>$1</s>").replace(/!\[([^\]]*)\]\(([^)]+)\)/g, "<img alt=\"$1\" src=\"$2\">").replace(/\[([^\]]+)\]\(([^)]+)\)/g, "<a href=\"$2\">$1</a>");
15544
15600
  }
15545
- function Xr(e) {
15601
+ function Qr(e) {
15546
15602
  let t = (e) => {
15547
15603
  if (e.nodeType === Node.TEXT_NODE) return e.textContent || "";
15548
15604
  if (e.nodeType !== Node.ELEMENT_NODE) return "";
@@ -15573,9 +15629,9 @@ function Xr(e) {
15573
15629
  };
15574
15630
  return Array.from(e.childNodes).map(t).join("").trim();
15575
15631
  }
15576
- var Zr = class extends HTMLElement {
15632
+ var $r = class extends HTMLElement {
15577
15633
  constructor(...e) {
15578
- super(...e), this.editor = null, this.editorFrame = null, this.pendingValue = null, this.source = null, this.toolbar = null, this.count = null, this.selectedImage = null, this.sourceMode = !1, this.observer = null, this.frameResizeObserver = null, this.resizeState = null, this.stageResizeState = null, this.editorHeight = null, this.sourceButton = null, this.blockButton = null, this.blockPopover = null, this.tablePopover = null, this.tableTrigger = null, this.selectedTableElement = null, this.inlineTableTools = null, this.tableResizeHandle = null, this.tableResizeState = null, this.gridResizeState = null, this.footerMode = null, this.inlineButtons = /* @__PURE__ */ new Map(), this.inlineOverrides = /* @__PURE__ */ new Map(), this.inlineStyleOverrides = /* @__PURE__ */ new Map(), this.preserveInlineOverridesOnNextEditorClick = !1, this.toolbarResizeObserver = null, this.overflowPopover = null, this.overflowTrigger = null, this.overflowGroups = [], this.tooltipPopup = null, this.fontSizeDisplay = null, this.lastTextColor = "#202833", this.lastBackgroundColor = "#fff2a8", this.colorTriggers = /* @__PURE__ */ new Map(), this.colorRecentSwatches = /* @__PURE__ */ new Map(), this.alignmentTrigger = null, this.onStageResizeStart = (e, t) => {
15634
+ super(...e), this.editor = null, this.editorFrame = null, this.pendingValue = null, this.preservedContent = null, this.history = [], this.historyIndex = -1, this.applyingHistory = !1, this.historyTransactionDepth = 0, this.historyTransactionPending = !1, this.undoButton = null, this.redoButton = null, this.source = null, this.toolbar = null, this.count = null, this.selectedImage = null, this.sourceMode = !1, this.observer = null, this.frameResizeObserver = null, this.resizeState = null, this.stageResizeState = null, this.editorHeight = null, this.sourceButton = null, this.blockButton = null, this.blockPopover = null, this.tablePopover = null, this.tableTrigger = null, this.selectedTableElement = null, this.inlineTableTools = null, this.tableResizeHandle = null, this.tableResizeState = null, this.gridResizeState = null, this.footerMode = null, this.inlineButtons = /* @__PURE__ */ new Map(), this.inlineOverrides = /* @__PURE__ */ new Map(), this.inlineStyleOverrides = /* @__PURE__ */ new Map(), this.preserveInlineOverridesOnNextEditorClick = !1, this.toolbarResizeObserver = null, this.overflowPopover = null, this.overflowTrigger = null, this.overflowGroups = [], this.tooltipPopup = null, this.fontSizeDisplay = null, this.lastTextColor = "#202833", this.lastBackgroundColor = "#fff2a8", this.colorTriggers = /* @__PURE__ */ new Map(), this.colorRecentSwatches = /* @__PURE__ */ new Map(), this.alignmentTrigger = null, this.onStageResizeStart = (e, t) => {
15579
15635
  if (e.button !== 0) return;
15580
15636
  e.preventDefault(), e.stopPropagation(), this.stageResizeState = {
15581
15637
  stage: t,
@@ -15674,17 +15730,21 @@ var Zr = class extends HTMLElement {
15674
15730
  if (this.sourceMode && this.source) return this.source.value;
15675
15731
  if (!this.editor) return "";
15676
15732
  let e = this.cleanEditorCopy();
15677
- return this.format === "markdown" ? Xr(e) : e.innerHTML;
15733
+ return this.format === "markdown" ? Qr(e) : e.innerHTML;
15678
15734
  }
15679
15735
  set value(e) {
15680
15736
  this.setValue(e || "");
15681
15737
  }
15682
15738
  setValue(e) {
15683
15739
  if (!this.editor) {
15684
- this.pendingValue = e, this.getAttribute("value") !== e && this.setAttribute("value", e);
15740
+ this.pendingValue = e, this.preservedContent = e, this.history = [], this.historyIndex = -1, this.updateHistoryButtons(), this.getAttribute("value") !== e && this.setAttribute("value", e);
15685
15741
  return;
15686
15742
  }
15687
- this.editor.innerHTML = this.format === "markdown" ? Q(e) : e, this.clearInlineTypingState(), this.source && (this.source.value = e), this.updateWordCount();
15743
+ if (this.value === e) {
15744
+ this.source && (this.source.value = e), this.updateHistoryButtons();
15745
+ return;
15746
+ }
15747
+ this.editor.innerHTML = this.format === "markdown" ? Q(e) : e, this.preservedContent = e, this.clearInlineTypingState(), this.source && (this.source.value = e), this.updateWordCount(), this.resetHistory();
15688
15748
  }
15689
15749
  insertResource(e) {
15690
15750
  let t = typeof e == "string" ? { url: e } : e, n = t.url || t.src;
@@ -15702,21 +15762,23 @@ var Zr = class extends HTMLElement {
15702
15762
  this.selectImage(i), this.emitChange();
15703
15763
  }
15704
15764
  render() {
15705
- let e = this.editor?.innerHTML ?? this.getAttribute("value") ?? this.innerHTML, t = this.editor ? e : this.format === "markdown" ? Q(e) : e;
15765
+ let e = this.getAttribute("value"), t = this.editor?.innerHTML ?? this.pendingValue ?? e ?? this.preservedContent ?? this.innerHTML;
15766
+ this.editor ? this.preservedContent = this.format === "markdown" && this.source ? this.source.value : this.editor.innerHTML : this.pendingValue === null ? e === null ? this.preservedContent === null && (this.preservedContent = t) : this.preservedContent = e : this.preservedContent = this.pendingValue;
15767
+ let n = this.editor ? t : this.format === "markdown" ? Q(t) : t;
15706
15768
  this.observer?.disconnect(), this.inlineButtons.clear(), this.colorTriggers.clear(), this.colorRecentSwatches.clear(), this.clearInlineTypingState(), this.editor = null, this.selectedImage = null;
15707
- let n = this.hasAttribute("disabled") && this.getAttribute("disabled") !== "false", r = this.editorHeight === null ? this.getAttribute("height") || "300px" : `${this.editorHeight}px`, i = this.getAttribute("label") || "";
15769
+ let r = this.hasAttribute("disabled") && this.getAttribute("disabled") !== "false", i = this.editorHeight === null ? this.getAttribute("height") || "300px" : `${this.editorHeight}px`, a = this.getAttribute("label") || "";
15708
15770
  this.innerHTML = "";
15709
- let a = document.createElement("div");
15710
- if (a.className = "mint-editor-root", this.hasAttribute("error") && a.classList.add("mint-editor-has-error"), this.hasAttribute("compact") && a.classList.add("mint-editor-compact"), i) {
15771
+ let o = document.createElement("div");
15772
+ if (o.className = "mint-editor-root", this.hasAttribute("error") && o.classList.add("mint-editor-has-error"), this.hasAttribute("compact") && o.classList.add("mint-editor-compact"), a) {
15711
15773
  let e = document.createElement("label");
15712
- e.className = "mint-editor-label", e.textContent = i, e.id = `${this.id || "mint-editor"}-label`, a.append(e);
15774
+ e.className = "mint-editor-label", e.textContent = a, e.id = `${this.id || "mint-editor"}-label`, o.append(e);
15713
15775
  }
15714
- let o = document.createElement("div");
15715
- o.className = "mint-editor-shell";
15716
15776
  let s = document.createElement("div");
15717
- s.className = "mint-editor-toolbar", s.setAttribute("role", "toolbar"), s.setAttribute("aria-label", "Text formatting"), this.toolbar = s, this.buildToolbar(s);
15777
+ s.className = "mint-editor-shell";
15718
15778
  let c = document.createElement("div");
15719
- c.className = "mint-editor-inline-table-tools", c.setAttribute("role", "toolbar"), c.setAttribute("aria-label", "Table tools"), c.hidden = !0;
15779
+ c.className = "mint-editor-toolbar", c.setAttribute("role", "toolbar"), c.setAttribute("aria-label", "Text formatting"), this.toolbar = c, this.buildToolbar(c);
15780
+ let l = document.createElement("div");
15781
+ l.className = "mint-editor-inline-table-tools", l.setAttribute("role", "toolbar"), l.setAttribute("aria-label", "Table tools"), l.hidden = !0;
15720
15782
  for (let [e, t] of [
15721
15783
  ["Add row above", "arrow-up"],
15722
15784
  ["Add row below", "arrow-down"],
@@ -15729,12 +15791,12 @@ var Zr = class extends HTMLElement {
15729
15791
  let n = document.createElement("button");
15730
15792
  n.type = "button", n.className = "mint-editor-table-tool-button", this.setTooltip(n, e), n.append(this.icon(t)), n.addEventListener("pointerdown", (e) => {
15731
15793
  e.preventDefault(), this.saveSelection();
15732
- }), n.addEventListener("click", () => this.applyTableAction(e)), c.append(n);
15794
+ }), n.addEventListener("click", () => this.applyTableAction(e)), l.append(n);
15733
15795
  }
15734
- let l = document.createElement("button");
15735
- l.type = "button", l.className = "mint-editor-table-resize-handle", this.setTooltip(l, "Resize table"), l.addEventListener("pointerdown", (e) => this.startTableResize(e)), this.inlineTableTools = c, this.tableResizeHandle = l;
15736
- let u = document.createElement("iframe");
15737
- u.className = "mint-editor-frame", u.title = i ? `${i} editor` : "Rich text editor", u.setAttribute("sandbox", "allow-same-origin"), u.style.height = "100%", u.srcdoc = `<!doctype html><html><head><meta charset="utf-8"><style>
15796
+ let u = document.createElement("button");
15797
+ u.type = "button", u.className = "mint-editor-table-resize-handle", this.setTooltip(u, "Resize table"), u.addEventListener("pointerdown", (e) => this.startTableResize(e)), this.inlineTableTools = l, this.tableResizeHandle = u;
15798
+ let d = document.createElement("iframe");
15799
+ d.className = "mint-editor-frame", d.title = a ? `${a} editor` : "Rich text editor", d.setAttribute("sandbox", "allow-same-origin allow-popups allow-popups-to-escape-sandbox"), d.style.height = "100%", d.srcdoc = `<!doctype html><html><head><meta charset="utf-8"><style>
15738
15800
  html,body{box-sizing:border-box;width:100%;height:100%;min-width:0;margin:0;overflow:hidden}
15739
15801
  .editor{box-sizing:border-box;width:100%;height:100%;min-width:0;min-height:0;overflow:auto;overflow-wrap:anywhere;padding:1rem;outline:0;color:var(--mint-color-text,#202833);background:var(--mint-color-surface,#fff);font:inherit;line-height:1.55}
15740
15802
  .editor:empty:before{content:attr(data-placeholder);color:var(--mint-color-text-muted,#7b8492);pointer-events:none}
@@ -15743,56 +15805,57 @@ var Zr = class extends HTMLElement {
15743
15805
  .editor :where(p,ul,ol,blockquote,table){max-width:100%;overflow-wrap:anywhere;margin:.65em 0}.editor a{color:var(--mint-color-primary,#1e5bff);text-decoration:underline}
15744
15806
  .editor table{width:100%;border-collapse:collapse;table-layout:fixed}.editor table.is-selected{outline:2px solid var(--mint-color-primary,#1e5bff);outline-offset:2px}.editor :where(td,th){box-sizing:border-box;min-width:3rem;max-width:none;overflow-wrap:anywhere;padding:.5rem;border:1px solid var(--mint-color-border,#dfe3e9);text-align:left;vertical-align:top}.editor th{background:var(--mint-color-surface-subtle,#f8f9fb);font-weight:600}
15745
15807
  .editor ul[data-mint-task-list]{padding-left:1.6rem;list-style:none}.editor ul[data-mint-task-list] li{display:flex;align-items:flex-start;gap:.5rem}.editor ul[data-mint-task-list] input[type=checkbox]{flex:0 0 auto;margin:.45em 0 0;accent-color:var(--mint-color-primary,#1e5bff)}
15746
- .editor .mint-editor-comment{border-radius:.15rem;background:rgb(255 224 130 / 45%);box-shadow:0 1px 0 rgb(198 120 0 / 65%);cursor:help}
15747
15808
  .mint-editor-image-frame{position:relative;display:inline-block;max-width:100%;margin:.5rem 0;vertical-align:middle}.mint-editor-image-frame img{display:block;width:100%;height:auto;max-height:none;border-radius:.25rem;object-fit:contain}.mint-editor-image-frame.is-selected{outline:2px solid var(--mint-color-primary,#1e5bff);outline-offset:2px}
15748
15809
  .mint-editor-resize-handle{position:absolute;right:-.45rem;bottom:-.45rem;width:.9rem;height:.9rem;padding:0;border:2px solid var(--mint-color-surface,#fff);border-radius:50%;background:var(--mint-color-primary,#1e5bff);cursor:nwse-resize;touch-action:none}
15749
15810
  @media(max-width:640px){.editor{padding:.75rem}}
15750
- </style></head><body><div class="editor" contenteditable="${!n}" role="textbox" aria-multiline="true" aria-label="${Z(i || "Rich text editor")}" data-placeholder="${Z(this.getAttribute("placeholder") || "Start writing…")}"></div></body></html>`, u.addEventListener("load", () => this.bindEditorFrame(t, n)), this.editorFrame = u;
15751
- let d = document.createElement("textarea");
15752
- d.className = "mint-editor-source", d.style.height = "100%", d.setAttribute("aria-label", `Editor ${this.format.toUpperCase()} source`), d.hidden = !0, d.value = this.format === "markdown" ? e : t, d.addEventListener("input", () => {
15753
- this.editor && (this.editor.innerHTML = this.format === "markdown" ? Q(d.value) : d.value), this.updateWordCount(), this.emitChange();
15754
- }), this.source = d;
15755
- let f = document.createElement("div");
15756
- f.className = "mint-editor-stage", f.style.height = r, f.append(u, d);
15757
- let p = null;
15811
+ </style></head><body><div class="editor" contenteditable="${!r}" role="textbox" aria-multiline="true" aria-label="${Z(a || "Rich text editor")}" data-placeholder="${Z(this.getAttribute("placeholder") || "Start writing…")}"></div></body></html>`, d.addEventListener("load", () => {
15812
+ !this.isConnected || this.editorFrame !== d || this.bindEditorFrame(n, r);
15813
+ }), this.editorFrame = d;
15814
+ let f = document.createElement("textarea");
15815
+ f.className = "mint-editor-source", f.style.height = "100%", f.setAttribute("aria-label", `Editor ${this.format.toUpperCase()} source`), f.hidden = !0, f.value = this.format === "markdown" ? t : n, f.addEventListener("input", (e) => {
15816
+ this.editor && (this.editor.innerHTML = this.format === "markdown" ? Q(f.value) : f.value), this.updateWordCount(), this.emitChange(e.inputType);
15817
+ }), f.addEventListener("keydown", (e) => this.handleHistoryKeydown(e)), f.addEventListener("beforeinput", (e) => this.handleHistoryBeforeInput(e)), this.source = f;
15818
+ let p = document.createElement("div");
15819
+ p.className = "mint-editor-stage", p.style.height = i, p.append(d, f);
15820
+ let m = null;
15758
15821
  [
15759
15822
  "false",
15760
15823
  "0",
15761
15824
  "off",
15762
15825
  "no"
15763
- ].includes((this.getAttribute("resizable") || "").trim().toLowerCase()) || (p = document.createElement("button"), p.type = "button", p.className = "mint-editor-stage-resize-handle", this.setTooltip(p, "Resize editor"), p.addEventListener("pointerdown", (e) => this.onStageResizeStart(e, f))), o.append(s, f, c, l);
15764
- let m = document.createElement("div");
15765
- m.className = "mint-editor-image-tools", m.hidden = !0, m.innerHTML = "<span>Image width</span><mint-input type=\"number\" min=\"10\" max=\"100\" value=\"100\" aria-label=\"Image width percent\"></mint-input><span>%</span><mint-button variant=\"ghost\" data-align=\"left\">Left</mint-button><mint-button variant=\"ghost\" data-align=\"center\">Center</mint-button><mint-button variant=\"ghost\" data-align=\"right\">Right</mint-button><mint-button variant=\"ghost\" data-remove=\"image\">Remove</mint-button>", m.querySelectorAll("[data-align]").forEach((e) => this.setTooltip(e, `Align image ${e.dataset.align}`));
15766
- let h = m.querySelector("[data-remove=\"image\"]");
15767
- h && this.setTooltip(h, "Remove image"), m.querySelector("mint-input")?.addEventListener("input", (e) => {
15826
+ ].includes((this.getAttribute("resizable") || "").trim().toLowerCase()) || (m = document.createElement("button"), m.type = "button", m.className = "mint-editor-stage-resize-handle", this.setTooltip(m, "Resize editor"), m.addEventListener("pointerdown", (e) => this.onStageResizeStart(e, p))), s.append(c, p, l, u);
15827
+ let h = document.createElement("div");
15828
+ h.className = "mint-editor-image-tools", h.hidden = !0, h.innerHTML = "<span>Image width</span><mint-input type=\"number\" min=\"10\" max=\"100\" value=\"100\" aria-label=\"Image width percent\"></mint-input><span>%</span><mint-button variant=\"ghost\" data-align=\"left\">Left</mint-button><mint-button variant=\"ghost\" data-align=\"center\">Center</mint-button><mint-button variant=\"ghost\" data-align=\"right\">Right</mint-button><mint-button variant=\"ghost\" data-remove=\"image\">Remove</mint-button>", h.querySelectorAll("[data-align]").forEach((e) => this.setTooltip(e, `Align image ${e.dataset.align}`));
15829
+ let g = h.querySelector("[data-remove=\"image\"]");
15830
+ g && this.setTooltip(g, "Remove image"), h.querySelector("mint-input")?.addEventListener("input", (e) => {
15768
15831
  if (!this.selectedImage) return;
15769
15832
  let t = Number(e.target.value);
15770
15833
  this.selectedImage.style.width = `${Math.max(10, Math.min(100, t))}%`, this.emitChange();
15771
- }), m.querySelectorAll("[data-align]").forEach((e) => e.addEventListener("click", () => {
15834
+ }), h.querySelectorAll("[data-align]").forEach((e) => e.addEventListener("click", () => {
15772
15835
  this.selectedImage && (this.selectedImage.style.marginLeft = e.dataset.align === "right" || e.dataset.align === "center" ? "auto" : "0", this.selectedImage.style.marginRight = e.dataset.align === "left" || e.dataset.align === "center" ? "auto" : "0", this.emitChange());
15773
- })), m.querySelector("[data-remove=\"image\"]")?.addEventListener("click", () => {
15836
+ })), h.querySelector("[data-remove=\"image\"]")?.addEventListener("click", () => {
15774
15837
  this.selectedImage?.remove(), this.selectImage(null), this.emitChange();
15775
- }), a.append(o, m);
15776
- let g = document.createElement("div");
15777
- g.className = "mint-editor-footer";
15778
- let _ = document.createElement("span");
15779
- _.className = "mint-editor-mode", _.textContent = "p";
15838
+ }), o.append(s, h);
15839
+ let _ = document.createElement("div");
15840
+ _.className = "mint-editor-footer";
15780
15841
  let v = document.createElement("span");
15781
- v.className = "mint-editor-word-count", this.count = v;
15782
- let y = document.createElement("div");
15783
- y.className = "mint-editor-footer-end", y.append(v), p && y.append(p), g.append(_, y), this.footerMode = _, o.append(g);
15784
- let b = this.getAttribute("error");
15785
- if (b) {
15842
+ v.className = "mint-editor-mode", v.textContent = "p";
15843
+ let y = document.createElement("span");
15844
+ y.className = "mint-editor-word-count", this.count = y;
15845
+ let b = document.createElement("div");
15846
+ b.className = "mint-editor-footer-end", b.append(y), m && b.append(m), _.append(v, b), this.footerMode = v, s.append(_);
15847
+ let x = this.getAttribute("error");
15848
+ if (x) {
15786
15849
  let e = document.createElement("div");
15787
- e.className = "mint-editor-error", e.textContent = b, a.append(e);
15850
+ e.className = "mint-editor-error", e.textContent = x, o.append(e);
15788
15851
  }
15789
- this.append(a);
15790
- let x = this.querySelector(".mint-editor-stage");
15791
- if (x && typeof ResizeObserver < "u" && (this.frameResizeObserver?.disconnect(), this.frameResizeObserver = new ResizeObserver(([e]) => {
15852
+ this.append(o);
15853
+ let S = this.querySelector(".mint-editor-stage");
15854
+ if (S && typeof ResizeObserver < "u" && (this.frameResizeObserver?.disconnect(), this.frameResizeObserver = new ResizeObserver(([e]) => {
15792
15855
  if (!e || !this.editorFrame) return;
15793
15856
  let t = Math.max(0, e.contentRect.width), n = Math.max(0, e.contentRect.height);
15794
15857
  this.editorFrame.style.width = `${t}px`, this.editorFrame.style.height = `${n}px`;
15795
- }), this.frameResizeObserver.observe(x)), this.toolbar && typeof ResizeObserver < "u") {
15858
+ }), this.frameResizeObserver.observe(S)), this.toolbar && typeof ResizeObserver < "u") {
15796
15859
  this.toolbarResizeObserver?.disconnect(), this.toolbarResizeObserver = new ResizeObserver(() => this.updateToolbarOverflow()), this.toolbarResizeObserver.observe(this.toolbar);
15797
15860
  let e = this.toolbar.querySelector(".mint-editor-toolbar-actions");
15798
15861
  e && this.toolbarResizeObserver.observe(e), requestAnimationFrame(() => this.updateToolbarOverflow());
@@ -15823,9 +15886,9 @@ var Zr = class extends HTMLElement {
15823
15886
  ].forEach((e) => {
15824
15887
  let t = i.getPropertyValue(`--mint-color-${e}`).trim();
15825
15888
  t && r.style.setProperty(`--mint-color-${e}`, t);
15826
- }), this.editor = r, r.addEventListener("input", () => {
15827
- this.normalizeTaskListItems(), this.syncSource(), this.emitChange(), this.updateSelectionUI();
15828
- }), r.addEventListener("change", (e) => {
15889
+ }), this.editor = r, r.addEventListener("input", (e) => {
15890
+ this.normalizeTaskListItems(), this.emitChange(e.inputType), this.updateSelectionUI();
15891
+ }), r.addEventListener("keydown", (e) => this.handleHistoryKeydown(e)), r.addEventListener("change", (e) => {
15829
15892
  let t = e.target;
15830
15893
  t.matches("ul[data-mint-task-list] input[type=\"checkbox\"]") && (t.toggleAttribute("checked", t.checked), this.emitChange());
15831
15894
  }), r.addEventListener("paste", (e) => {
@@ -15835,6 +15898,7 @@ var Zr = class extends HTMLElement {
15835
15898
  n && (e.preventDefault(), this.clearInlineTypingState(), this.insertPastedHtml(n), this.normalizeTaskListItems(), this.emitChange(), this.updateSelectionUI());
15836
15899
  }), r.addEventListener("beforeinput", (e) => {
15837
15900
  let t = e;
15901
+ if (this.handleHistoryBeforeInput(t)) return;
15838
15902
  t.inputType.startsWith("insert") && (this.preserveInlineOverridesOnNextEditorClick = !1);
15839
15903
  let n = t.shiftKey;
15840
15904
  if ((t.inputType === "insertParagraph" || t.inputType === "insertLineBreak" && !n) && !t.isComposing) {
@@ -15858,12 +15922,23 @@ var Zr = class extends HTMLElement {
15858
15922
  ].includes(e.key) && this.clearInlineTypingState(), this.updateSelectedImage(), this.updateSelectionUI();
15859
15923
  }), r.addEventListener("mouseup", () => {
15860
15924
  this.updateSelectedImage(), this.updateSelectionUI();
15861
- }), n.addEventListener("selectionchange", () => this.updateSelectionUI()), r.addEventListener("scroll", () => this.positionTableTools()), r.addEventListener("pointermove", (e) => this.updateGridResizeCursor(e)), n.addEventListener("pointerdown", (e) => this.startGridResize(e), !0), r.addEventListener("click", (e) => {
15925
+ }), n.addEventListener("selectionchange", () => this.updateSelectionUI()), n.addEventListener("pointerover", (e) => {
15926
+ let t = e.target;
15927
+ if (!t || t.nodeType !== Node.ELEMENT_NODE) return;
15928
+ let n = t.closest("a[href]"), r = e.relatedTarget;
15929
+ !n || r && r.nodeType && n.contains(r) || (this.bindEditorLinkTooltip(n), this.showTooltip(n));
15930
+ }), r.addEventListener("scroll", () => this.positionTableTools()), r.addEventListener("pointermove", (e) => this.updateGridResizeCursor(e)), n.addEventListener("pointerdown", (e) => this.startGridResize(e), !0), r.addEventListener("click", (e) => {
15862
15931
  this.closeEditorPopovers(), this.preserveInlineOverridesOnNextEditorClick ? this.preserveInlineOverridesOnNextEditorClick = !1 : this.clearInlineTypingState();
15863
15932
  let t = e.target, n = t.closest(".mint-editor-image-frame");
15864
15933
  n ? this.selectImage(n) : t.closest(".mint-editor-image-tools") || this.selectImage(null);
15865
15934
  let r = t.closest("table");
15866
- this.selectTable(r), t.closest("a") && e.preventDefault();
15935
+ this.selectTable(r);
15936
+ let i = t.closest("a[href]");
15937
+ if (i) if (e.preventDefault(), this.isOpenLinkModifier(e)) this.openEditorLink(i, "new-tab");
15938
+ else {
15939
+ let e = i.getAttribute("data-mint-editor-open");
15940
+ e && e !== "same-tab" && this.openEditorLink(i, e);
15941
+ }
15867
15942
  }), r.addEventListener("keydown", (e) => {
15868
15943
  if (e.key === "Enter" && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey && !e.isComposing) {
15869
15944
  let t = this.selection, n = t?.anchorNode, r = (n?.nodeType === Node.ELEMENT_NODE ? n : n?.parentElement)?.closest("li"), i = r?.parentElement;
@@ -15877,22 +15952,22 @@ var Zr = class extends HTMLElement {
15877
15952
  childList: !0,
15878
15953
  subtree: !0,
15879
15954
  characterData: !0
15880
- }), this.updateWordCount(), this.updateSelectionUI();
15955
+ }), this.updateWordCount(), this.updateSelectionUI(), this.history.length === 0 ? this.resetHistory() : this.updateHistoryButtons();
15881
15956
  }
15882
15957
  buildToolbar(e) {
15883
15958
  let t = (t, n, r, i = e) => {
15884
15959
  let a = document.createElement("button");
15885
15960
  return a.type = "button", a.className = `mint-editor-tool-button mint-editor-toolbar-${n}`, this.setTooltip(a, t), a.append(this.icon(n)), a.addEventListener("pointerdown", () => this.saveSelection()), a.addEventListener("click", (e) => {
15886
- e.preventDefault(), r();
15961
+ e.preventDefault(), this.runHistoryTransaction(r);
15887
15962
  }), i.append(a), a;
15888
15963
  }, n = (e, t, n) => {
15889
15964
  let r = document.createElement("mint-popover");
15890
15965
  return r.id = `${e.id}-menu`, r.setAttribute("trigger-id", e.id), r.setAttribute("padding", "0.25rem"), r.setAttribute("direction", "down"), r.className = `mint-editor-menu-popover ${t}`, n.append(r), r;
15891
15966
  }, r = (e, t, n, r) => {
15892
15967
  let i = this.createMenuOption(t, n);
15893
- return i.addEventListener("click", r), e.append(i), i;
15968
+ return i.addEventListener("click", () => this.runHistoryTransaction(r)), e.append(i), i;
15894
15969
  };
15895
- t("Undo", "undo", () => this.command("undo")), t("Redo", "redo", () => this.command("redo"));
15970
+ this.undoButton = t("Undo", "undo", () => this.undo()), this.redoButton = t("Redo", "redo", () => this.redo()), this.updateHistoryButtons();
15896
15971
  let i = document.createElement("button");
15897
15972
  i.type = "button", i.className = "mint-editor-tool-button mint-editor-block-trigger", this.setTooltip(i, "Text style"), i.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-block-trigger`;
15898
15973
  let a = document.createElement("span");
@@ -16014,10 +16089,10 @@ var Zr = class extends HTMLElement {
16014
16089
  this.applyFontFamily(t), T.close();
16015
16090
  });
16016
16091
  }), f.push([w, T]), h();
16017
- let E = p("Insert link", "link", () => this.openLinkModal()), D = p("Insert image", "image", () => this.requestResource()), ee = p("Insert table", "table", () => this.openTableModal()), O = document.createElement("button");
16018
- O.type = "button", O.className = "mint-editor-tool-button", this.setTooltip(O, "Table options"), O.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-table-trigger`, O.append(this.icon("caret-down")), O.hidden = !0, u.append(O);
16019
- let k = n(O, "", u);
16020
- this.tablePopover = k, [
16092
+ let E = p("Insert link", "link", () => this.openLinkModal()), D = p("Insert image", "image", () => this.requestResource()), O = p("Insert table", "table", () => this.openTableModal()), k = document.createElement("button");
16093
+ k.type = "button", k.className = "mint-editor-tool-button", this.setTooltip(k, "Table options"), k.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-table-trigger`, k.append(this.icon("caret-down")), k.hidden = !0, u.append(k);
16094
+ let A = n(k, "", u);
16095
+ this.tablePopover = A, [
16021
16096
  ["Add row below", "table-row"],
16022
16097
  ["Add column right", "table-column"],
16023
16098
  ["Delete row", "table-row-delete"],
@@ -16026,15 +16101,13 @@ var Zr = class extends HTMLElement {
16026
16101
  ].forEach(([e, t]) => {
16027
16102
  let n = this.createMenuOption(e, t);
16028
16103
  n.addEventListener("click", () => {
16029
- this.applyTableAction(e), k.close();
16030
- }), k.append(n);
16031
- }), O.addEventListener("pointerdown", () => this.saveSelection()), this.tableTrigger = O, f.push([E], [D], [
16032
- ee,
16104
+ this.applyTableAction(e), A.close();
16105
+ }), A.append(n);
16106
+ }), k.addEventListener("pointerdown", () => this.saveSelection()), this.tableTrigger = k, f.push([E], [D], [
16033
16107
  O,
16034
- k
16035
- ]);
16036
- let A = p("Add comment", "comment-plus", () => this.openCommentModal());
16037
- f.push([A]), h();
16108
+ k,
16109
+ A
16110
+ ]), h();
16038
16111
  let j = p("Text alignment", "align-left", () => {});
16039
16112
  j.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-alignment-trigger`, j.append(this.icon("caret-down")), this.alignmentTrigger = j;
16040
16113
  let M = n(j, "mint-editor-alignment-popover", u);
@@ -16064,7 +16137,7 @@ var Zr = class extends HTMLElement {
16064
16137
  this.command(n), M.close(), this.updateTooltipLabel(j, `Text alignment: ${e}`);
16065
16138
  });
16066
16139
  }), f.push([j, M]), h();
16067
- let te = p("Bulleted list", "list", () => this.command("insertUnorderedList")), N = document.createElement("button");
16140
+ let ee = p("Bulleted list", "list", () => this.command("insertUnorderedList")), N = document.createElement("button");
16068
16141
  N.type = "button", N.className = "mint-editor-tool-button mint-editor-list-options-trigger", N.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-bullet-options-trigger`, this.setTooltip(N, "Bulleted list style"), N.append(this.icon("caret-down")), N.addEventListener("pointerdown", () => this.saveSelection()), u.append(N);
16069
16142
  let P = n(N, "mint-editor-list-popover", u);
16070
16143
  [
@@ -16074,7 +16147,7 @@ var Zr = class extends HTMLElement {
16074
16147
  ].forEach(([e, t]) => r(P, e, "list", () => {
16075
16148
  this.applyListStyle("ul", t), P.close();
16076
16149
  }));
16077
- let ne = p("Numbered list", "numbered-list", () => this.command("insertOrderedList")), F = document.createElement("button");
16150
+ let te = p("Numbered list", "numbered-list", () => this.command("insertOrderedList")), F = document.createElement("button");
16078
16151
  F.type = "button", F.className = "mint-editor-tool-button mint-editor-list-options-trigger", F.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-numbered-options-trigger`, this.setTooltip(F, "Numbered list style"), F.append(this.icon("caret-down")), F.addEventListener("pointerdown", () => this.saveSelection()), u.append(F);
16079
16152
  let I = n(F, "mint-editor-list-popover", u);
16080
16153
  [
@@ -16086,20 +16159,20 @@ var Zr = class extends HTMLElement {
16086
16159
  ].forEach(([e, t]) => r(I, e, "numbered-list", () => {
16087
16160
  this.applyListStyle("ol", t), I.close();
16088
16161
  }));
16089
- let re = p("Checklist", "checklist", () => this.toggleChecklist());
16162
+ let ne = p("Checklist", "checklist", () => this.toggleChecklist());
16090
16163
  f.push([
16091
- te,
16164
+ ee,
16092
16165
  N,
16093
16166
  P
16094
16167
  ], [
16095
- ne,
16168
+ te,
16096
16169
  F,
16097
16170
  I
16098
- ], [re]), h();
16099
- let ie = p("HTML source", "code", () => this.toggleSource());
16100
- f.push([ie]), this.sourceButton = e.querySelector(".mint-editor-toolbar-code");
16101
- let ae = p("Clear formatting", "clear-formatting", () => this.clearFormatting());
16102
- f.push([ae]);
16171
+ ], [ne]), h();
16172
+ let re = p("HTML source", "code", () => this.toggleSource());
16173
+ f.push([re]), this.sourceButton = e.querySelector(".mint-editor-toolbar-code");
16174
+ let ie = p("Clear formatting", "clear-formatting", () => this.clearFormatting());
16175
+ f.push([ie]);
16103
16176
  let L = document.createElement("button");
16104
16177
  L.type = "button", L.className = "mint-editor-tool-button mint-editor-overflow-trigger", this.setTooltip(L, "More formatting options"), L.id = `${this.id || `mint-editor-${Math.random().toString(36).slice(2)}`}-overflow-trigger`, L.append(this.icon("ellipsis"));
16105
16178
  let R = document.createElement("mint-popover");
@@ -16174,7 +16247,9 @@ var Zr = class extends HTMLElement {
16174
16247
  this.inlineStyleOverrides.set(e === "text" ? "color" : "backgroundColor", i), this.preserveInlineOverridesOnNextEditorClick = !0, e === "text" && t && (this.lastTextColor = t), e === "background" && t && (this.lastBackgroundColor = t), this.colorTriggers.get(e)?.style.setProperty("--editor-color", e === "text" ? this.lastTextColor : this.lastBackgroundColor), this.emitChange(), this.updateSelectionUI();
16175
16248
  return;
16176
16249
  }
16177
- this.inlineStyleOverrides.delete(e === "text" ? "color" : "backgroundColor"), e === "text" ? (n.execCommand("foreColor", !1, i), t && (this.lastTextColor = t), this.colorTriggers.get("text")?.style.setProperty("--editor-color", this.lastTextColor)) : (n.execCommand("hiliteColor", !1, i) || n.execCommand("backColor", !1, i), t && (this.lastBackgroundColor = t), this.colorTriggers.get("background")?.style.setProperty("--editor-color", this.lastBackgroundColor)), this.emitChange(), this.updateSelectionUI();
16250
+ this.inlineStyleOverrides.delete(e === "text" ? "color" : "backgroundColor"), this.runHistoryTransaction(() => {
16251
+ e === "text" ? (n.execCommand("foreColor", !1, i), t && (this.lastTextColor = t), this.colorTriggers.get("text")?.style.setProperty("--editor-color", this.lastTextColor)) : (n.execCommand("hiliteColor", !1, i) || n.execCommand("backColor", !1, i), t && (this.lastBackgroundColor = t), this.colorTriggers.get("background")?.style.setProperty("--editor-color", this.lastBackgroundColor)), this.emitChange();
16252
+ }), this.updateSelectionUI();
16178
16253
  }
16179
16254
  readFontSize() {
16180
16255
  let e = this.selection, t = e?.isCollapsed ? Number.parseFloat(this.inlineStyleOverrides.get("fontSize") || "") : NaN;
@@ -16191,58 +16266,63 @@ var Zr = class extends HTMLElement {
16191
16266
  this.inlineStyleOverrides.set("fontSize", `${t}px`), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
16192
16267
  return;
16193
16268
  }
16194
- this.inlineStyleOverrides.delete("fontSize");
16195
- let r = new Set(Array.from(this.editor.querySelectorAll("font[size=\"7\"]")));
16196
- n.execCommand("fontSize", !1, "7"), this.editor.querySelectorAll("font[size=\"7\"]").forEach((e) => {
16197
- if (r.has(e)) return;
16198
- let i = n.createElement("span");
16199
- i.style.fontSize = `${t}px`, e.getAttribute("face") && (i.style.fontFamily = e.getAttribute("face") || ""), e.getAttribute("color") && (i.style.color = e.getAttribute("color") || ""), i.append(...Array.from(e.childNodes)), e.replaceWith(i);
16200
- }), this.emitChange(), this.updateSelectionUI();
16269
+ this.inlineStyleOverrides.delete("fontSize"), this.runHistoryTransaction(() => {
16270
+ let e = new Set(Array.from(this.editor.querySelectorAll("font[size=\"7\"]")));
16271
+ n.execCommand("fontSize", !1, "7"), this.editor.querySelectorAll("font[size=\"7\"]").forEach((r) => {
16272
+ if (e.has(r)) return;
16273
+ let i = n.createElement("span");
16274
+ i.style.fontSize = `${t}px`, r.getAttribute("face") && (i.style.fontFamily = r.getAttribute("face") || ""), r.getAttribute("color") && (i.style.color = r.getAttribute("color") || ""), i.append(...Array.from(r.childNodes)), r.replaceWith(i);
16275
+ }), this.emitChange();
16276
+ }), this.updateSelectionUI();
16201
16277
  }
16202
16278
  applyFontFamily(e) {
16203
- if (!this.editor || this.sourceMode) return;
16204
- if (this.editor.focus(), this.restoreSelection(), this.selection?.isCollapsed) {
16205
- this.inlineStyleOverrides.set("fontFamily", e), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
16206
- return;
16279
+ if (!(!this.editor || this.sourceMode)) {
16280
+ if (this.editor.focus(), this.restoreSelection(), this.selection?.isCollapsed) {
16281
+ this.inlineStyleOverrides.set("fontFamily", e), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
16282
+ return;
16283
+ }
16284
+ this.inlineStyleOverrides.delete("fontFamily"), this.runHistoryTransaction(() => {
16285
+ let t = this.editor.ownerDocument, n = new Set(Array.from(this.editor.querySelectorAll("font[face]")));
16286
+ t.execCommand("fontName", !1, e), this.editor.querySelectorAll("font[face]").forEach((r) => {
16287
+ if (n.has(r)) return;
16288
+ let i = t.createElement("span");
16289
+ i.style.fontFamily = r.getAttribute("face") || e, i.append(...Array.from(r.childNodes)), r.replaceWith(i);
16290
+ }), this.emitChange();
16291
+ }), this.updateSelectionUI();
16207
16292
  }
16208
- this.inlineStyleOverrides.delete("fontFamily");
16209
- let t = this.editor.ownerDocument, n = new Set(Array.from(this.editor.querySelectorAll("font[face]")));
16210
- t.execCommand("fontName", !1, e), this.editor.querySelectorAll("font[face]").forEach((r) => {
16211
- if (n.has(r)) return;
16212
- let i = t.createElement("span");
16213
- i.style.fontFamily = r.getAttribute("face") || e, i.append(...Array.from(r.childNodes)), r.replaceWith(i);
16214
- }), this.emitChange(), this.updateSelectionUI();
16215
16293
  }
16216
16294
  applyListStyle(e, t) {
16217
16295
  if (!this.editor || this.sourceMode) return;
16218
16296
  this.editor.focus(), this.restoreSelection();
16219
16297
  let n = this.selection?.anchorNode, r = (n?.nodeType === Node.ELEMENT_NODE ? n : n?.parentElement)?.closest(e), i = r && this.editor.contains(r) ? r : null;
16220
- if (!i) {
16221
- this.editor.ownerDocument.execCommand(e === "ul" ? "insertUnorderedList" : "insertOrderedList", !1);
16222
- let t = this.selection?.anchorNode, n = (t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement)?.closest(e);
16223
- i = n && this.editor.contains(n) ? n : null;
16224
- }
16225
- i && (i.style.listStyleType = t), this.emitChange(), this.updateSelectionUI();
16298
+ this.runHistoryTransaction(() => {
16299
+ if (!i) {
16300
+ this.editor.ownerDocument.execCommand(e === "ul" ? "insertUnorderedList" : "insertOrderedList", !1);
16301
+ let t = this.selection?.anchorNode, n = (t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement)?.closest(e);
16302
+ i = n && this.editor.contains(n) ? n : null;
16303
+ }
16304
+ i && (i.style.listStyleType = t), this.emitChange();
16305
+ }), this.updateSelectionUI();
16226
16306
  }
16227
16307
  toggleChecklist() {
16228
- if (!this.editor || this.sourceMode) return;
16229
- this.editor.focus(), this.restoreSelection();
16230
- let e = this.editor.ownerDocument, t = this.selection?.anchorNode, n = t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement, r = n?.closest("ul[data-mint-task-list]"), i = n?.closest("ul");
16231
- if (r) r.removeAttribute("data-mint-task-list"), r.querySelectorAll("input[type=\"checkbox\"]").forEach((e) => e.remove());
16232
- else {
16233
- i || (n?.closest("h1,h2,h3,h4,h5,h6") && e.execCommand("formatBlock", !1, "p"), e.execCommand("insertUnorderedList", !1));
16234
- let t = this.selection?.anchorNode, r = t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement, a = i || r?.closest("ul");
16235
- if (a && this.editor.contains(a)) {
16236
- a.setAttribute("data-mint-task-list", "true"), a.querySelectorAll("li").forEach((t, n) => {
16237
- if (t.querySelector("input[type=\"checkbox\"]")) return;
16238
- let r = e.createElement("input");
16239
- r.type = "checkbox", r.setAttribute("contenteditable", "false"), r.setAttribute("aria-label", `Task ${n + 1} complete`), t.insertBefore(r, t.firstChild);
16240
- });
16241
- let t = a.parentElement;
16242
- t && t !== this.editor && /^(P|H[1-6])$/.test(t.tagName) && t.parentElement === this.editor && (Array.from(t.childNodes).filter((e) => e === a ? !1 : e.nodeType === Node.TEXT_NODE ? !!e.textContent?.trim() : e.nodeType === Node.ELEMENT_NODE && !e.matches("br")).length === 0 ? t.replaceWith(a) : t.parentNode?.insertBefore(a, t.nextSibling));
16308
+ !this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.runHistoryTransaction(() => {
16309
+ let e = this.editor.ownerDocument, t = this.selection?.anchorNode, n = t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement, r = n?.closest("ul[data-mint-task-list]"), i = n?.closest("ul");
16310
+ if (r) r.removeAttribute("data-mint-task-list"), r.querySelectorAll("input[type=\"checkbox\"]").forEach((e) => e.remove());
16311
+ else {
16312
+ i || (n?.closest("h1,h2,h3,h4,h5,h6") && e.execCommand("formatBlock", !1, "p"), e.execCommand("insertUnorderedList", !1));
16313
+ let t = this.selection?.anchorNode, r = t?.nodeType === Node.ELEMENT_NODE ? t : t?.parentElement, a = i || r?.closest("ul");
16314
+ if (a && this.editor.contains(a)) {
16315
+ a.setAttribute("data-mint-task-list", "true"), a.querySelectorAll("li").forEach((t, n) => {
16316
+ if (t.querySelector("input[type=\"checkbox\"]")) return;
16317
+ let r = e.createElement("input");
16318
+ r.type = "checkbox", r.setAttribute("contenteditable", "false"), r.setAttribute("aria-label", `Task ${n + 1} complete`), t.insertBefore(r, t.firstChild);
16319
+ });
16320
+ let t = a.parentElement;
16321
+ t && t !== this.editor && /^(P|H[1-6])$/.test(t.tagName) && t.parentElement === this.editor && (Array.from(t.childNodes).filter((e) => e === a ? !1 : e.nodeType === Node.TEXT_NODE ? !!e.textContent?.trim() : e.nodeType === Node.ELEMENT_NODE && !e.matches("br")).length === 0 ? t.replaceWith(a) : t.parentNode?.insertBefore(a, t.nextSibling));
16322
+ }
16243
16323
  }
16244
- }
16245
- this.emitChange(), this.updateSelectionUI();
16324
+ this.emitChange();
16325
+ }), this.updateSelectionUI());
16246
16326
  }
16247
16327
  splitTaskItem(e, t) {
16248
16328
  if (!this.editor) return;
@@ -16295,44 +16375,6 @@ var Zr = class extends HTMLElement {
16295
16375
  let a = this.selection, o = this.editor.ownerDocument.createRange();
16296
16376
  o.setStart(i, 0), o.collapse(!0), a?.removeAllRanges(), a?.addRange(o), this.syncSource(), this.emitChange(), this.updateSelectionUI();
16297
16377
  }
16298
- openCommentModal() {
16299
- this.saveSelection();
16300
- let e = this._savedRange?.toString() || "", t = document.createElement("mint-modal");
16301
- t.setAttribute("heading", "Add comment"), t.setAttribute("size", "small");
16302
- let n = document.createElement("div");
16303
- n.setAttribute("slot", "body"), n.className = "mint-editor-modal-fields";
16304
- let r = document.createElement("p");
16305
- r.className = "mint-editor-comment-hint", r.textContent = e ? `Comment on: “${e.slice(0, 120)}${e.length > 120 ? "…" : ""}”` : "Select some text in the document before adding a comment.";
16306
- let i = document.createElement("textarea");
16307
- i.className = "mint-editor-comment-input", i.setAttribute("aria-label", "Comment"), i.setAttribute("placeholder", "Write a comment…"), i.rows = 4, n.append(r, i);
16308
- let a = document.createElement("div");
16309
- a.setAttribute("slot", "actions"), a.className = "mint-editor-modal-actions";
16310
- let o = document.createElement("mint-button");
16311
- o.textContent = "Cancel", o.setAttribute("variant", "ghost"), this.setTooltip(o, "Cancel"), o.addEventListener("click", () => t.close());
16312
- let s = document.createElement("mint-button");
16313
- s.textContent = "Add comment", s.setAttribute("tone", "action"), s.toggleAttribute("disabled", !e), this.setTooltip(s, "Add comment"), s.addEventListener("click", () => {
16314
- let n = i.value.trim();
16315
- !n || !e || (this.insertComment(n, e), t.close());
16316
- }), a.append(o, s), t.append(n, a), this.append(t), t.open();
16317
- }
16318
- insertComment(e, t) {
16319
- let n = this._savedRange;
16320
- if (this.editor && n && !n.collapsed && this.editor.contains(n.commonAncestorContainer) && this.format === "html") {
16321
- let t = this.editor.ownerDocument.createElement("span");
16322
- t.className = "mint-editor-comment", t.setAttribute("data-mint-comment", e), t.title = `Comment: ${e}`, t.append(n.extractContents()), n.insertNode(t);
16323
- let r = this.selection;
16324
- n.selectNodeContents(t), r?.removeAllRanges(), r?.addRange(n);
16325
- }
16326
- this.dispatchEvent(new CustomEvent("mint-editor-comment-request", {
16327
- bubbles: !0,
16328
- composed: !0,
16329
- detail: {
16330
- selectedText: t,
16331
- comment: e,
16332
- format: this.format
16333
- }
16334
- })), this.emitChange();
16335
- }
16336
16378
  updateToolbarOverflow() {
16337
16379
  let e = this.toolbar, t = this.overflowTrigger, n = this.overflowPopover;
16338
16380
  if (!e || !t || !n) return;
@@ -16348,7 +16390,9 @@ var Zr = class extends HTMLElement {
16348
16390
  t.hidden = n.childElementCount === 0;
16349
16391
  }
16350
16392
  clearFormatting() {
16351
- !this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.editor.ownerDocument.execCommand("removeFormat", !1), this.editor.ownerDocument.execCommand("formatBlock", !1, "p"), this.clearInlineTypingState(), this.emitChange(), this.updateSelectionUI());
16393
+ !this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.runHistoryTransaction(() => {
16394
+ this.editor.ownerDocument.execCommand("removeFormat", !1), this.editor.ownerDocument.execCommand("formatBlock", !1, "p"), this.clearInlineTypingState(), this.emitChange();
16395
+ }), this.updateSelectionUI());
16352
16396
  }
16353
16397
  icon(e) {
16354
16398
  let t = document.createElement("mint-icon");
@@ -16357,6 +16401,48 @@ var Zr = class extends HTMLElement {
16357
16401
  setTooltip(e, t) {
16358
16402
  this.updateTooltipLabel(e, t), e.dataset.editorTooltipBound !== "true" && (e.dataset.editorTooltipBound = "true", e.addEventListener("pointerenter", () => this.showTooltip(e)), e.addEventListener("pointerleave", () => this.hideTooltip()), e.addEventListener("focus", () => this.showTooltip(e)), e.addEventListener("blur", () => this.hideTooltip()));
16359
16403
  }
16404
+ linkOpenModifier() {
16405
+ let e = navigator.userAgentData?.platform || navigator.platform || "";
16406
+ return /mac|iphone|ipad|ipod/i.test(e) ? "⌘" : "Ctrl";
16407
+ }
16408
+ isOpenLinkModifier(e) {
16409
+ return this.linkOpenModifier() === "⌘" ? e.metaKey : e.ctrlKey;
16410
+ }
16411
+ openEditorLink(e, t) {
16412
+ if (t === "same-tab") {
16413
+ this.ownerDocument.defaultView?.location.assign(e.href);
16414
+ return;
16415
+ }
16416
+ if (t === "new-tab") {
16417
+ window.open(e.href, "_blank", "noopener,noreferrer");
16418
+ return;
16419
+ }
16420
+ let n = t === "popup", r = n ? [
16421
+ "popup=yes",
16422
+ `width=${this.normalizePopupNumber(e.dataset.mintPopupWidth || "", 200, 4e3, "800")}`,
16423
+ `height=${this.normalizePopupNumber(e.dataset.mintPopupHeight || "", 150, 4e3, "600")}`,
16424
+ e.dataset.mintPopupLeft ? `left=${this.normalizePopupNumber(e.dataset.mintPopupLeft, 0, 1e4, "")}` : "",
16425
+ e.dataset.mintPopupTop ? `top=${this.normalizePopupNumber(e.dataset.mintPopupTop, 0, 1e4, "")}` : "",
16426
+ `resizable=${e.dataset.mintPopupResizable === "no" ? "no" : "yes"}`,
16427
+ `scrollbars=${e.dataset.mintPopupScrollbars === "no" ? "no" : "yes"}`
16428
+ ].filter(Boolean).join(",") : "popup=no", i = n ? "mint-editor-popup" : "mint-editor-window", a = window.open(e.href, i, r);
16429
+ if (!a) return;
16430
+ try {
16431
+ a.opener = null;
16432
+ } catch {}
16433
+ let o = e.dataset.mintPopupTitle?.trim();
16434
+ if (n && o) {
16435
+ let e = () => {
16436
+ try {
16437
+ a.document.title = o;
16438
+ } catch {}
16439
+ };
16440
+ e(), a.addEventListener("load", e, { once: !0 });
16441
+ }
16442
+ }
16443
+ bindEditorLinkTooltip(e) {
16444
+ e.dataset.editorTooltipBound !== "true" && (e.dataset.editorTooltipBound = "true", e.setAttribute("data-editor-tooltip", `${this.linkOpenModifier()} + click to open`), e.addEventListener("pointerenter", () => this.showTooltip(e)), e.addEventListener("pointerleave", () => this.hideTooltip()), e.addEventListener("focus", () => this.showTooltip(e)), e.addEventListener("blur", () => this.hideTooltip()));
16445
+ }
16360
16446
  updateTooltipLabel(e, t) {
16361
16447
  e.setAttribute("data-editor-tooltip", t);
16362
16448
  let n = t.indexOf(":"), r = n < 0 ? t : `${t.slice(0, n + 1)}\n${t.slice(n + 1).trim()}`;
@@ -16383,8 +16469,23 @@ var Zr = class extends HTMLElement {
16383
16469
  }), document.body.append(n), this.tooltipPopup = n;
16384
16470
  }
16385
16471
  n.textContent = t, n.setAttribute("aria-hidden", "false"), n.style.visibility = "hidden", n.style.display = "block";
16386
- let r = e.getBoundingClientRect(), i = n.getBoundingClientRect(), a = Math.max(8, Math.min(window.innerWidth - i.width - 8, r.left + r.width / 2 - i.width / 2)), o = r.top >= i.height + 6 + 8 ? r.top - i.height - 6 : Math.min(window.innerHeight - i.height - 8, r.bottom + 6);
16387
- n.style.left = `${a}px`, n.style.top = `${o}px`, n.style.visibility = "visible";
16472
+ let r = e.getBoundingClientRect(), i = {
16473
+ left: r.left,
16474
+ top: r.top,
16475
+ width: r.width,
16476
+ bottom: r.bottom
16477
+ }, a = e.ownerDocument.defaultView?.frameElement;
16478
+ if (a) {
16479
+ let e = a.getBoundingClientRect(), t = a.clientWidth ? e.width / a.clientWidth : 1, n = a.clientHeight ? e.height / a.clientHeight : 1;
16480
+ i = {
16481
+ left: e.left + r.left * t,
16482
+ top: e.top + r.top * n,
16483
+ width: r.width * t,
16484
+ bottom: e.top + r.bottom * n
16485
+ };
16486
+ }
16487
+ let o = n.getBoundingClientRect(), s = Math.max(8, Math.min(window.innerWidth - o.width - 8, i.left + i.width / 2 - o.width / 2)), c = i.top >= o.height + 6 + 8 ? i.top - o.height - 6 : Math.min(window.innerHeight - o.height - 8, i.bottom + 6);
16488
+ n.style.left = `${s}px`, n.style.top = `${c}px`, n.style.visibility = "visible";
16388
16489
  }
16389
16490
  hideTooltip() {
16390
16491
  this.tooltipPopup && (this.tooltipPopup.style.display = "none", this.tooltipPopup.setAttribute("aria-hidden", "true"));
@@ -16420,7 +16521,9 @@ var Zr = class extends HTMLElement {
16420
16521
  return e.className = "mint-editor-separator", e.setAttribute("aria-hidden", "true"), e;
16421
16522
  }
16422
16523
  command(e, t) {
16423
- !this.editor || this.sourceMode || (this.editor.focus(), this.restoreSelection(), this.editor.ownerDocument.execCommand(e, !1, t), this.clearInlineTypingState(), this.emitChange(), this.updateSelectionUI());
16524
+ !this.editor || this.sourceMode || (this.runHistoryTransaction(() => {
16525
+ this.editor.focus(), this.restoreSelection(), this.editor.ownerDocument.execCommand(e, !1, t), this.clearInlineTypingState(), this.emitChange();
16526
+ }), this.updateSelectionUI());
16424
16527
  }
16425
16528
  toggleInline(e) {
16426
16529
  if (!this.editor || this.sourceMode) return;
@@ -16432,7 +16535,9 @@ var Zr = class extends HTMLElement {
16432
16535
  this.inlineOverrides.set(e, r), this.preserveInlineOverridesOnNextEditorClick = !0, this.emitChange(), this.updateSelectionUI();
16433
16536
  return;
16434
16537
  }
16435
- this.clearInlineTypingState(), i.execCommand(e, !1), this.emitChange(), this.updateSelectionUI();
16538
+ this.runHistoryTransaction(() => {
16539
+ this.clearInlineTypingState(), i.execCommand(e, !1), this.emitChange();
16540
+ }), this.updateSelectionUI();
16436
16541
  }
16437
16542
  inlineStateAtSelection(e, t) {
16438
16543
  let n = this.selection, r = this.inlineOverrides.get(e);
@@ -16703,24 +16808,7 @@ var Zr = class extends HTMLElement {
16703
16808
  e.replaceWith(...Array.from(e.childNodes));
16704
16809
  };
16705
16810
  for (let e of Array.from(i.querySelectorAll("*"))) e.tagName.includes(":") && l(e);
16706
- let u = new Set([
16707
- "href",
16708
- "src",
16709
- "alt",
16710
- "title",
16711
- "colspan",
16712
- "rowspan",
16713
- "start",
16714
- "value",
16715
- "type",
16716
- "width",
16717
- "height",
16718
- "border",
16719
- "cellpadding",
16720
- "cellspacing",
16721
- "scope",
16722
- "dir"
16723
- ]), d = (e, t = !1) => {
16811
+ let u = new Set(/* @__PURE__ */ "href.src.alt.title.target.rel.data-mint-editor-open.data-mint-popup-title.data-mint-popup-width.data-mint-popup-height.data-mint-popup-left.data-mint-popup-top.data-mint-popup-resizable.data-mint-popup-scrollbars.colspan.rowspan.start.value.type.width.height.border.cellpadding.cellspacing.scope.dir".split(".")), d = (e, t = !1) => {
16724
16812
  let n = e.trim();
16725
16813
  if (/^#[-\w:.]+$/.test(n) || t && /^data:image\/(?:png|gif|jpe?g|webp);base64,/i.test(n)) return !0;
16726
16814
  try {
@@ -16739,7 +16827,17 @@ var Zr = class extends HTMLElement {
16739
16827
  if (n === "style") {
16740
16828
  let n = o(t.value);
16741
16829
  n ? e.setAttribute("style", n) : e.removeAttribute(t.name);
16742
- } else u.has(n) ? ((n === "href" || n === "src") && !d(t.value, n === "src") || [
16830
+ } else if (!u.has(n)) e.removeAttribute(t.name);
16831
+ else if ((n === "href" || n === "src") && !d(t.value, n === "src")) e.removeAttribute(t.name);
16832
+ else if (n === "target" && !/^(_self|_blank|mint-editor-window|mint-editor-popup)$/i.test(t.value.trim())) e.removeAttribute(t.name);
16833
+ else if (n === "rel") {
16834
+ let n = t.value.toLowerCase().split(/\s+/).filter((e) => ["noopener", "noreferrer"].includes(e));
16835
+ n.length ? e.setAttribute("rel", Array.from(new Set(n)).join(" ")) : e.removeAttribute(t.name);
16836
+ } else if (n === "data-mint-editor-open" && !/^(same-tab|new-tab|new-window|popup)$/.test(t.value)) e.removeAttribute(t.name);
16837
+ else if (/^data-mint-popup-(width|height|left|top)$/.test(n)) {
16838
+ let r = Number.parseInt(t.value, 10), i = /width|height/.test(n) ? 150 : 0;
16839
+ !Number.isFinite(r) || r < i || r > 1e4 ? e.removeAttribute(t.name) : e.setAttribute(t.name, String(r));
16840
+ } else /^data-mint-popup-(resizable|scrollbars)$/.test(n) && !/^(yes|no)$/.test(t.value) ? e.removeAttribute(t.name) : n === "data-mint-popup-title" && t.value.length > 120 ? e.setAttribute(n, t.value.slice(0, 120)) : ([
16743
16841
  "colspan",
16744
16842
  "rowspan",
16745
16843
  "start",
@@ -16749,20 +16847,34 @@ var Zr = class extends HTMLElement {
16749
16847
  "border",
16750
16848
  "cellpadding",
16751
16849
  "cellspacing"
16752
- ].includes(n) && !/^\d+(?:%|px)?$/i.test(t.value.trim()) || n === "scope" && !/^(row|col|rowgroup|colgroup)$/i.test(t.value) || n === "dir" && !/^(ltr|rtl|auto)$/i.test(t.value) || n === "type" && !/^(1|a|A|i|I)$/i.test(t.value)) && e.removeAttribute(t.name) : e.removeAttribute(t.name);
16850
+ ].includes(n) && !/^\d+(?:%|px)?$/i.test(t.value.trim()) || n === "scope" && !/^(row|col|rowgroup|colgroup)$/i.test(t.value) || n === "dir" && !/^(ltr|rtl|auto)$/i.test(t.value) || n === "type" && !/^(1|a|A|i|I)$/i.test(t.value)) && e.removeAttribute(t.name);
16753
16851
  }
16754
16852
  for (let e of Array.from(i.querySelectorAll("span"))) e.attributes.length || l(e);
16755
16853
  return i.innerHTML.trim();
16756
16854
  }
16757
16855
  syncSource() {
16758
16856
  if (this.source && this.editor) {
16759
- let e = this.cleanEditorCopy();
16760
- this.source.value = this.format === "markdown" ? Xr(e) : e.innerHTML;
16857
+ let e = this.cleanEditorCopy(), t = this.format === "markdown" ? Qr(e) : e.innerHTML;
16858
+ this.sourceMode || (this.source.value = t), this.preservedContent = this.sourceMode && this.source ? this.source.value : this.format === "markdown" ? t : this.editor.innerHTML;
16761
16859
  }
16762
16860
  this.updateWordCount();
16763
16861
  }
16764
- emitChange() {
16765
- this.syncSource();
16862
+ emitChange(e) {
16863
+ if (this.historyTransactionDepth > 0) {
16864
+ this.historyTransactionPending = !0;
16865
+ return;
16866
+ }
16867
+ this.syncSource(), this.applyingHistory || this.recordHistory(e || null), this.dispatchValueEvents();
16868
+ }
16869
+ runHistoryTransaction(e) {
16870
+ this.historyTransactionDepth += 1;
16871
+ try {
16872
+ e();
16873
+ } finally {
16874
+ --this.historyTransactionDepth, this.historyTransactionDepth === 0 && this.historyTransactionPending && (this.historyTransactionPending = !1, this.syncSource(), this.recordHistory(null), this.dispatchValueEvents());
16875
+ }
16876
+ }
16877
+ dispatchValueEvents() {
16766
16878
  let e = this.value;
16767
16879
  this.dispatchEvent(new CustomEvent("input", {
16768
16880
  bubbles: !0,
@@ -16774,6 +16886,119 @@ var Zr = class extends HTMLElement {
16774
16886
  detail: { value: e }
16775
16887
  }));
16776
16888
  }
16889
+ resetHistory() {
16890
+ this.history = [], this.historyIndex = -1, this.editor && this.recordHistory(null), this.updateHistoryButtons();
16891
+ }
16892
+ refreshCurrentHistorySnapshot() {
16893
+ if (this.historyIndex < 0) return;
16894
+ let e = this.captureHistorySnapshot(null);
16895
+ e && (this.history[this.historyIndex] = e);
16896
+ }
16897
+ captureHistoryPoint(e, t) {
16898
+ let n = this.editor;
16899
+ if (!n || !e || e !== n && !n.contains(e)) return null;
16900
+ let r = [], i = e;
16901
+ for (; i && i !== n;) {
16902
+ let e = i.parentNode;
16903
+ if (!e) return null;
16904
+ r.unshift(Array.prototype.indexOf.call(e.childNodes, i)), i = e;
16905
+ }
16906
+ return i === n ? {
16907
+ path: r,
16908
+ offset: Math.max(0, Math.min(t, e.nodeType === Node.TEXT_NODE ? (e.textContent || "").length : e.childNodes.length))
16909
+ } : null;
16910
+ }
16911
+ resolveHistoryPoint(e) {
16912
+ let t = this.editor;
16913
+ if (!t || !e) return null;
16914
+ let n = t;
16915
+ for (let t of e.path) {
16916
+ let e = n.childNodes[Math.max(0, Math.min(t, n.childNodes.length - 1))];
16917
+ if (!e) break;
16918
+ n = e;
16919
+ }
16920
+ let r = n.nodeType === Node.TEXT_NODE ? (n.textContent || "").length : n.childNodes.length;
16921
+ return {
16922
+ node: n,
16923
+ offset: Math.max(0, Math.min(e.offset, r))
16924
+ };
16925
+ }
16926
+ captureHistorySnapshot(e) {
16927
+ if (!this.editor) return null;
16928
+ let t = this.selection, n = this.sourceMode && this.source ? {
16929
+ start: this.source.selectionStart,
16930
+ end: this.source.selectionEnd,
16931
+ direction: this.source.selectionDirection
16932
+ } : null, r = this.cleanEditorCopy(), i = this.sourceMode && this.source ? this.source.value : this.format === "markdown" ? Qr(r) : r.innerHTML;
16933
+ return {
16934
+ html: r.innerHTML,
16935
+ source: i,
16936
+ anchor: this.captureHistoryPoint(t?.anchorNode || null, t?.anchorOffset || 0),
16937
+ focus: this.captureHistoryPoint(t?.focusNode || null, t?.focusOffset || 0),
16938
+ sourceSelection: n,
16939
+ group: e,
16940
+ time: Date.now()
16941
+ };
16942
+ }
16943
+ recordHistory(e) {
16944
+ if (!this.editor || this.applyingHistory) return;
16945
+ let t = e === "insertText" || e === "insertCompositionText" ? "typing" : e === "deleteContentBackward" || e === "deleteContentForward" || e === "deleteByCut" ? "deleting" : null, n = this.captureHistorySnapshot(t);
16946
+ if (!n) return;
16947
+ if (this.historyIndex < 0) {
16948
+ this.history = [n], this.historyIndex = 0, this.updateHistoryButtons();
16949
+ return;
16950
+ }
16951
+ let r = this.history[this.historyIndex];
16952
+ if (n.html === r.html && n.source === r.source) {
16953
+ n.group = t, this.history[this.historyIndex] = n, this.updateHistoryButtons();
16954
+ return;
16955
+ }
16956
+ t !== null && r.group === t && n.time - r.time <= 900 ? this.history[this.historyIndex] = n : (this.history = this.history.slice(0, this.historyIndex + 1), this.history.push(n), this.historyIndex = this.history.length - 1, this.history.length > 100 && (this.history.shift(), this.historyIndex = this.history.length - 1)), this.updateHistoryButtons();
16957
+ }
16958
+ updateHistoryButtons() {
16959
+ let e = this.historyIndex > 0 && this.historyIndex < this.history.length, t = this.historyIndex >= 0 && this.historyIndex < this.history.length - 1;
16960
+ this.undoButton && (this.undoButton.disabled = !e), this.redoButton && (this.redoButton.disabled = !t);
16961
+ }
16962
+ restoreHistorySelection(e) {
16963
+ if (this.sourceMode && this.source && e.sourceSelection) {
16964
+ let t = Math.min(e.sourceSelection.start, this.source.value.length), n = Math.min(e.sourceSelection.end, this.source.value.length);
16965
+ this.source.setSelectionRange(t, n, e.sourceSelection.direction), this.source.focus();
16966
+ return;
16967
+ }
16968
+ let t = this.selection, n = this.resolveHistoryPoint(e.anchor), r = this.resolveHistoryPoint(e.focus);
16969
+ if (!(!t || !n || !r)) if (t.removeAllRanges(), typeof t.setBaseAndExtent == "function") t.setBaseAndExtent(n.node, n.offset, r.node, r.offset);
16970
+ else {
16971
+ let e = this.editor.ownerDocument.createRange();
16972
+ e.setStart(n.node, n.offset), e.setEnd(r.node, r.offset), t.addRange(e);
16973
+ }
16974
+ }
16975
+ applyHistorySnapshot(e) {
16976
+ if (!(!this.editor || !this.source)) {
16977
+ this.applyingHistory = !0;
16978
+ try {
16979
+ this.editor.innerHTML = e.html, this.source.value = e.source, this.editor.querySelectorAll(".mint-editor-image-frame").forEach((e) => {
16980
+ e.querySelectorAll(".mint-editor-resize-handle").forEach((e) => e.remove()), e.append(this.createResizeHandle());
16981
+ }), this.selectImage(null), this.selectTable(null), this.clearInlineTypingState(), this.preservedContent = this.format === "markdown" ? e.source : e.html, this.updateWordCount(), this.restoreHistorySelection(e), this.updateSelectedImage(), this.updateSelectionUI(), this.updateHistoryButtons();
16982
+ } finally {
16983
+ this.applyingHistory = !1;
16984
+ }
16985
+ this.dispatchValueEvents();
16986
+ }
16987
+ }
16988
+ undo() {
16989
+ this.historyIndex <= 0 || (--this.historyIndex, this.applyHistorySnapshot(this.history[this.historyIndex]));
16990
+ }
16991
+ redo() {
16992
+ this.historyIndex >= this.history.length - 1 || (this.historyIndex += 1, this.applyHistorySnapshot(this.history[this.historyIndex]));
16993
+ }
16994
+ handleHistoryKeydown(e) {
16995
+ if (!(e.metaKey || e.ctrlKey) || e.altKey) return;
16996
+ let t = e.key.toLowerCase();
16997
+ t === "z" ? (e.preventDefault(), e.shiftKey ? this.redo() : this.undo()) : t === "y" && !e.shiftKey && (e.preventDefault(), this.redo());
16998
+ }
16999
+ handleHistoryBeforeInput(e) {
17000
+ return e.inputType === "historyUndo" ? (e.preventDefault(), this.undo(), !0) : e.inputType === "historyRedo" ? (e.preventDefault(), this.redo(), !0) : !1;
17001
+ }
16777
17002
  updateWordCount() {
16778
17003
  if (!this.editor || !this.count) return;
16779
17004
  let e = (this.editor.innerText || "").trim().split(/\s+/).filter(Boolean).length;
@@ -16875,21 +17100,158 @@ var Zr = class extends HTMLElement {
16875
17100
  }
16876
17101
  openLinkModal() {
16877
17102
  this.saveSelection();
16878
- let e = document.createElement("mint-modal");
16879
- e.setAttribute("heading", "Insert link"), e.setAttribute("size", "small");
16880
- let t = document.createElement("div");
16881
- t.setAttribute("slot", "body");
16882
- let n = document.createElement("mint-input");
16883
- n.setAttribute("type", "url"), n.setAttribute("label", "Link URL"), n.setAttribute("placeholder", "https://example.com"), t.append(n);
17103
+ let e = this._savedRange, t = e && !e.collapsed ? e.toString() : "", n = document.createElement("mint-modal");
17104
+ n.setAttribute("heading", "Insert link"), n.setAttribute("size", "small");
16884
17105
  let r = document.createElement("div");
16885
- r.setAttribute("slot", "actions"), r.className = "mint-editor-modal-actions";
16886
- let i = document.createElement("mint-button");
16887
- i.textContent = "Cancel", i.setAttribute("variant", "ghost"), this.setTooltip(i, "Cancel"), i.addEventListener("click", () => e.close());
16888
- let a = document.createElement("mint-button");
16889
- a.textContent = "Insert link", a.setAttribute("tone", "action"), this.setTooltip(a, "Insert link"), a.addEventListener("click", () => {
16890
- let t = String(n.value || "").trim();
16891
- t && (this.command("createLink", t), e.close());
16892
- }), r.append(i, a), e.append(t, r), this.append(e), e.open();
17106
+ r.setAttribute("slot", "body"), r.className = "mint-editor-modal-fields";
17107
+ let i = document.createElement("mint-input");
17108
+ i.setAttribute("type", "text"), i.setAttribute("label", "Link text"), i.setAttribute("placeholder", "Text to display"), t && i.setAttribute("value", t);
17109
+ let a = document.createElement("mint-input");
17110
+ a.setAttribute("type", "url"), a.setAttribute("label", "Link URL"), a.setAttribute("placeholder", "https://example.com"), r.append(i, a);
17111
+ let o = document.createElement("mint-select");
17112
+ o.className = "mint-editor-link-target", o.setAttribute("label", "Open in"), o.setAttribute("value", "same-tab"), [
17113
+ ["same-tab", "Same tab"],
17114
+ ["new-tab", "New tab"],
17115
+ ["new-window", "New window"],
17116
+ ["popup", "Popup"]
17117
+ ].forEach(([e, t]) => {
17118
+ let n = document.createElement("option");
17119
+ n.value = e, n.textContent = t, o.append(n);
17120
+ }), r.append(o);
17121
+ let s = document.createElement("mint-button");
17122
+ s.className = "mint-editor-link-advanced", s.textContent = "Advanced settings", s.setAttribute("variant", "ghost"), s.setAttribute("aria-expanded", "false"), s.hidden = !0;
17123
+ let c = document.createElement("div");
17124
+ c.className = "mint-editor-popup-settings", c.id = `${this.id || "mint-editor"}-popup-settings`, c.hidden = !0, s.setAttribute("aria-controls", c.id);
17125
+ let l = document.createElement("mint-input");
17126
+ l.setAttribute("type", "text"), l.setAttribute("label", "Window title"), l.setAttribute("placeholder", "Link popup");
17127
+ let u = document.createElement("mint-input");
17128
+ u.setAttribute("type", "number"), u.setAttribute("label", "Width"), u.setAttribute("min", "200"), u.setAttribute("max", "4000"), u.setAttribute("value", "800");
17129
+ let d = document.createElement("mint-input");
17130
+ d.setAttribute("type", "number"), d.setAttribute("label", "Height"), d.setAttribute("min", "150"), d.setAttribute("max", "4000"), d.setAttribute("value", "600");
17131
+ let f = document.createElement("mint-input");
17132
+ f.setAttribute("type", "number"), f.setAttribute("label", "Left position"), f.setAttribute("min", "0"), f.setAttribute("max", "10000"), f.setAttribute("placeholder", "Automatic");
17133
+ let p = document.createElement("mint-input");
17134
+ p.setAttribute("type", "number"), p.setAttribute("label", "Top position"), p.setAttribute("min", "0"), p.setAttribute("max", "10000"), p.setAttribute("placeholder", "Automatic");
17135
+ let m = document.createElement("mint-select");
17136
+ m.setAttribute("label", "Resizable"), m.setAttribute("value", "yes");
17137
+ let h = document.createElement("mint-select");
17138
+ h.setAttribute("label", "Scrollbars"), h.setAttribute("value", "yes"), [
17139
+ [
17140
+ m,
17141
+ "yes",
17142
+ "Yes"
17143
+ ],
17144
+ [
17145
+ m,
17146
+ "no",
17147
+ "No"
17148
+ ],
17149
+ [
17150
+ h,
17151
+ "yes",
17152
+ "Yes"
17153
+ ],
17154
+ [
17155
+ h,
17156
+ "no",
17157
+ "No"
17158
+ ]
17159
+ ].forEach(([e, t, n]) => {
17160
+ let r = document.createElement("option");
17161
+ r.value = String(t), r.textContent = String(n), e.append(r);
17162
+ }), c.append(l, u, d, f, p, m, h), s.addEventListener("click", () => {
17163
+ c.hidden = !c.hidden, s.setAttribute("aria-expanded", String(!c.hidden));
17164
+ }), o.addEventListener("change", (e) => {
17165
+ let t = String(e.detail?.value || o.value);
17166
+ s.hidden = t !== "popup", t !== "popup" && (c.hidden = !0, s.setAttribute("aria-expanded", "false"));
17167
+ }), r.append(s, c);
17168
+ let g = document.createElement("div");
17169
+ g.setAttribute("slot", "actions"), g.className = "mint-editor-modal-actions";
17170
+ let _ = document.createElement("mint-button");
17171
+ _.textContent = "Cancel", _.setAttribute("variant", "ghost"), this.setTooltip(_, "Cancel"), _.addEventListener("click", () => n.close());
17172
+ let v = document.createElement("mint-button");
17173
+ v.textContent = "Insert link", v.setAttribute("tone", "action"), this.setTooltip(v, "Insert link"), v.addEventListener("click", () => {
17174
+ let e = String(a.value || "").trim(), t = String(i.value || ""), r = String(o.value || "same-tab"), s = {
17175
+ title: String(l.value || ""),
17176
+ width: String(u.value || "800"),
17177
+ height: String(d.value || "600"),
17178
+ left: String(f.value || ""),
17179
+ top: String(p.value || ""),
17180
+ resizable: String(m.value || "yes"),
17181
+ scrollbars: String(h.value || "yes")
17182
+ };
17183
+ e && t.trim() && (this.insertLink(e, t, r, s), n.close());
17184
+ }), g.append(_, v), n.append(r, g), this.append(n), n.open();
17185
+ }
17186
+ insertLink(e, t, n, r) {
17187
+ let i = this.editor, a = this._savedRange;
17188
+ if (!i || this.sourceMode || !a || !i.contains(a.commonAncestorContainer)) return;
17189
+ let o = a.collapsed ? "" : a.toString();
17190
+ if (o && o === t) {
17191
+ let t = a.cloneRange();
17192
+ this.runHistoryTransaction(() => {
17193
+ this.command("createLink", e);
17194
+ let a = Array.from(i.querySelectorAll("a[href]")).filter((e) => {
17195
+ try {
17196
+ return t.intersectsNode(e);
17197
+ } catch {
17198
+ return !1;
17199
+ }
17200
+ }), o = this.selection?.anchorNode, s = (o?.nodeType === Node.ELEMENT_NODE ? o : o?.parentElement)?.closest("a[href]");
17201
+ (a.length ? a : s ? [s] : []).forEach((e) => this.configureLinkTarget(e, n, r)), this.emitChange();
17202
+ }), this.updateSelectionUI();
17203
+ return;
17204
+ }
17205
+ this.runHistoryTransaction(() => {
17206
+ i.focus(), this.restoreSelection();
17207
+ let a = this.selection;
17208
+ if (!a?.rangeCount) return;
17209
+ let o = a.getRangeAt(0);
17210
+ if (!i.contains(o.commonAncestorContainer)) return;
17211
+ let s = (e) => {
17212
+ let t = (e.nodeType === Node.ELEMENT_NODE ? e : e.parentElement)?.closest("a[href]");
17213
+ return t && i.contains(t) ? t : null;
17214
+ }, c = s(o.startContainer), l = s(o.endContainer), u, d;
17215
+ if (c && c === l) {
17216
+ if (d = c, o.collapsed) d.textContent = t, u = d;
17217
+ else {
17218
+ o.deleteContents();
17219
+ let e = i.ownerDocument.createTextNode(t);
17220
+ o.insertNode(e), u = e;
17221
+ }
17222
+ d.href = e;
17223
+ } else {
17224
+ d = i.ownerDocument.createElement("a"), d.href = e, o.deleteContents();
17225
+ let n = i.ownerDocument.createTextNode(t);
17226
+ d.append(n), o.insertNode(d), u = d;
17227
+ }
17228
+ this.configureLinkTarget(d, n, r), o.setStartAfter(u), o.collapse(!0), a.removeAllRanges(), a.addRange(o), this.emitChange();
17229
+ }), this.updateSelectionUI();
17230
+ }
17231
+ configureLinkTarget(e, t, n) {
17232
+ e.setAttribute("target", {
17233
+ "same-tab": "_self",
17234
+ "new-tab": "_blank",
17235
+ "new-window": "mint-editor-window",
17236
+ popup: "mint-editor-popup"
17237
+ }[t]), e.setAttribute("data-mint-editor-open", t), t === "same-tab" ? e.removeAttribute("rel") : e.setAttribute("rel", "noopener noreferrer");
17238
+ let r = {
17239
+ "data-mint-popup-title": n.title.trim().slice(0, 120),
17240
+ "data-mint-popup-width": this.normalizePopupNumber(n.width, 200, 4e3, "800"),
17241
+ "data-mint-popup-height": this.normalizePopupNumber(n.height, 150, 4e3, "600"),
17242
+ "data-mint-popup-left": this.normalizePopupNumber(n.left, 0, 1e4, ""),
17243
+ "data-mint-popup-top": this.normalizePopupNumber(n.top, 0, 1e4, ""),
17244
+ "data-mint-popup-resizable": n.resizable === "no" ? "no" : "yes",
17245
+ "data-mint-popup-scrollbars": n.scrollbars === "no" ? "no" : "yes"
17246
+ };
17247
+ Object.entries(r).forEach(([n, r]) => {
17248
+ t === "popup" && r ? e.setAttribute(n, r) : e.removeAttribute(n);
17249
+ });
17250
+ }
17251
+ normalizePopupNumber(e, t, n, r) {
17252
+ if (!e.trim()) return r;
17253
+ let i = Number.parseInt(e, 10);
17254
+ return Number.isFinite(i) ? String(Math.max(t, Math.min(n, i))) : r;
16893
17255
  }
16894
17256
  selectedTable() {
16895
17257
  let e = this._savedRange?.startContainer || this.selection?.anchorNode, t = (e?.nodeType === Node.ELEMENT_NODE ? e : e?.parentElement)?.closest("table");
@@ -16992,9 +17354,9 @@ var Zr = class extends HTMLElement {
16992
17354
  toggleSource() {
16993
17355
  if (!(!this.editor || !this.source)) {
16994
17356
  if (this.sourceMode = !this.sourceMode, this.clearInlineTypingState(), this.source.hidden = !this.sourceMode, this.editor.hidden = this.sourceMode, this.sourceMode) {
16995
- let e = this.cleanEditorCopy();
16996
- this.source.value = this.format === "markdown" ? Xr(e) : e.innerHTML;
16997
- } else this.editor.innerHTML = this.format === "markdown" ? Q(this.source.value) : this.source.value;
17357
+ let e = this.cleanEditorCopy(), t = this.format === "markdown" ? Qr(e) : e.innerHTML;
17358
+ this.source.value = this.format === "markdown" ? Xr(t) : Zr(t, this.editor.ownerDocument), this.refreshCurrentHistorySnapshot(), this.preservedContent = this.source.value, this.dispatchValueEvents();
17359
+ } else this.editor.innerHTML = this.format === "markdown" ? Q(this.source.value) : this.source.value, this.syncSource(), this.emitChange();
16998
17360
  this.toolbar?.classList.toggle("mint-editor-source-active", this.sourceMode), this.updateWordCount(), this.sourceMode ? this.selectTable(null) : this.updateSelectionUI();
16999
17361
  }
17000
17362
  }
@@ -17023,6 +17385,6 @@ var Zr = class extends HTMLElement {
17023
17385
  t && this.selectImage(t);
17024
17386
  }
17025
17387
  };
17026
- customElements.get("mint-editor") || a("mint-editor", Zr);
17388
+ customElements.get("mint-editor") || a("mint-editor", $r);
17027
17389
  //#endregion
17028
- export { Rn as Alert, Cn as BackButton, Vn as BottomNavigation, gn as Button, gn as default, bn as Card, Hn as Chart, Nn as Checkbox, Un as Chip, Pn as Choice, Wn as Clickable, Gn as Collapsible, Kn as ConfirmAction, tr as DatePicker, rr as DateTimePicker, ir as Dropzone, Zr as Editor, ar as Form, kn as Grid, l as Icon, er as Input, xn as Link, Bn as MintBottomNavItem, zn as MintBottomNavigation, yr as MintSidenavActionLinks, br as MintSidenavActionMenu, _r as MintSidenavLink, vr as MintSidenavLinks, Yr as MintTree, Yr as Tree, Mn as Modal, lr as NativeSelect, Ln as Navigation, or as OffCanvas, On as Page, Dn as Popover, dr as ResourceTable, wn as ScrollFade, gr as Search, ur as Select, wr as SideNavigation, Er as Sortable, hn as Spinner, yn as Stack, _n as Switch, Dr as Tab, kr as TabContent, Or as TabList, cr as Table, Ar as Tabs, jr as Tags, vn as Text, nr as TimePicker, Mr as Toast, $n as confirm, Vr as mintui, B as observeScrollFade, Br as toast };
17390
+ export { Rn as Alert, Cn as BackButton, Vn as BottomNavigation, gn as Button, gn as default, bn as Card, Hn as Chart, Nn as Checkbox, Un as Chip, Pn as Choice, Wn as Clickable, Gn as Collapsible, Kn as ConfirmAction, tr as DatePicker, rr as DateTimePicker, ir as Dropzone, $r as Editor, ar as Form, kn as Grid, l as Icon, er as Input, xn as Link, Bn as MintBottomNavItem, zn as MintBottomNavigation, yr as MintSidenavActionLinks, br as MintSidenavActionMenu, _r as MintSidenavLink, vr as MintSidenavLinks, Yr as MintTree, Yr as Tree, Mn as Modal, lr as NativeSelect, Ln as Navigation, or as OffCanvas, On as Page, Dn as Popover, dr as ResourceTable, wn as ScrollFade, gr as Search, ur as Select, wr as SideNavigation, Er as Sortable, hn as Spinner, yn as Stack, _n as Switch, Dr as Tab, kr as TabContent, Or as TabList, cr as Table, Ar as Tabs, jr as Tags, vn as Text, nr as TimePicker, Mr as Toast, $n as confirm, Vr as mintui, B as observeScrollFade, Br as toast };