@fab1o978/react-ui 0.1.3 → 0.1.7

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 (39) hide show
  1. package/dist/components/ColorPicker/index.cjs +205 -63
  2. package/dist/components/ColorPicker/index.cjs.map +1 -1
  3. package/dist/components/ColorPicker/index.css +200 -42
  4. package/dist/components/ColorPicker/index.css.map +1 -1
  5. package/dist/components/ColorPicker/index.js +205 -63
  6. package/dist/components/ColorPicker/index.js.map +1 -1
  7. package/dist/components/RichTextEditor/index.cjs +3553 -0
  8. package/dist/components/RichTextEditor/index.cjs.map +1 -0
  9. package/dist/components/RichTextEditor/index.css +356 -0
  10. package/dist/components/RichTextEditor/index.css.map +1 -0
  11. package/dist/components/RichTextEditor/index.d.cts +30 -0
  12. package/dist/components/RichTextEditor/index.d.ts +30 -0
  13. package/dist/components/RichTextEditor/index.js +3538 -0
  14. package/dist/components/RichTextEditor/index.js.map +1 -0
  15. package/dist/components/SliderControl/index.cjs +268 -0
  16. package/dist/components/SliderControl/index.cjs.map +1 -0
  17. package/dist/components/SliderControl/index.css +202 -0
  18. package/dist/components/SliderControl/index.css.map +1 -0
  19. package/dist/components/SliderControl/index.d.cts +21 -0
  20. package/dist/components/SliderControl/index.d.ts +21 -0
  21. package/dist/components/SliderControl/index.js +266 -0
  22. package/dist/components/SliderControl/index.js.map +1 -0
  23. package/dist/components/SlidingCounter/index.cjs +181 -0
  24. package/dist/components/SlidingCounter/index.cjs.map +1 -0
  25. package/dist/components/SlidingCounter/index.css +133 -0
  26. package/dist/components/SlidingCounter/index.css.map +1 -0
  27. package/dist/components/SlidingCounter/index.d.cts +19 -0
  28. package/dist/components/SlidingCounter/index.d.ts +19 -0
  29. package/dist/components/SlidingCounter/index.js +179 -0
  30. package/dist/components/SlidingCounter/index.js.map +1 -0
  31. package/dist/index.cjs +3771 -63
  32. package/dist/index.cjs.map +1 -1
  33. package/dist/index.css +685 -42
  34. package/dist/index.css.map +1 -1
  35. package/dist/index.d.cts +5 -0
  36. package/dist/index.d.ts +5 -0
  37. package/dist/index.js +3760 -65
  38. package/dist/index.js.map +1 -1
  39. package/package.json +8 -1
package/dist/index.js CHANGED
@@ -1,5 +1,17 @@
1
1
  import React, { useRef, useEffect, useState, useCallback } from 'react';
2
- import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { jsxs, jsx, Fragment as Fragment$1 } from 'react/jsx-runtime';
3
+ import { EditorProvider, useCurrentEditor } from '@tiptap/react';
4
+ export { useCurrentEditor } from '@tiptap/react';
5
+ import StarterKit from '@tiptap/starter-kit';
6
+ import Underline from '@tiptap/extension-underline';
7
+ import Placeholder from '@tiptap/extension-placeholder';
8
+ import { RemoveMarkStep, Transform, liftTarget, joinPoint, canSplit, ReplaceStep, ReplaceAroundStep, canJoin } from '@tiptap/pm/transform';
9
+ import { createParagraphNear as createParagraphNear$1, exitCode as exitCode$1, joinUp as joinUp$1, joinDown as joinDown$1, joinBackward as joinBackward$1, joinForward as joinForward$1, joinTextblockBackward as joinTextblockBackward$1, joinTextblockForward as joinTextblockForward$1, lift as lift$1, liftEmptyBlock as liftEmptyBlock$1, newlineInCode as newlineInCode$1, selectNodeBackward as selectNodeBackward$1, selectNodeForward as selectNodeForward$1, selectParentNode as selectParentNode$1, selectTextblockEnd as selectTextblockEnd$1, selectTextblockStart as selectTextblockStart$1, setBlockType, wrapIn as wrapIn$1 } from '@tiptap/pm/commands';
10
+ import { Plugin, PluginKey, Selection, TextSelection, AllSelection, NodeSelection } from '@tiptap/pm/state';
11
+ import { Fragment, Slice, Node, Schema, DOMParser } from '@tiptap/pm/model';
12
+ import { liftListItem as liftListItem$1, sinkListItem as sinkListItem$1, wrapInList as wrapInList$1 } from '@tiptap/pm/schema-list';
13
+ import '@tiptap/pm/view';
14
+ import '@tiptap/pm/keymap';
3
15
 
4
16
  // src/components/Button/Button.tsx
5
17
 
@@ -587,10 +599,6 @@ var ColorPicker_module_default = {
587
599
  discWrapper: "ColorPicker_module_discWrapper",
588
600
  disc: "ColorPicker_module_disc",
589
601
  dot: "ColorPicker_module_dot",
590
- lSlider: "ColorPicker_module_lSlider",
591
- lThumb: "ColorPicker_module_lThumb",
592
- alphaSlider: "ColorPicker_module_alphaSlider",
593
- alphaThumb: "ColorPicker_module_alphaThumb",
594
602
  previewSwatch: "ColorPicker_module_previewSwatch",
595
603
  eyedropperBtn: "ColorPicker_module_eyedropperBtn",
596
604
  inputSection: "ColorPicker_module_inputSection",
@@ -606,6 +614,190 @@ var ColorPicker_module_default = {
606
614
  swatches: "ColorPicker_module_swatches",
607
615
  recentSwatch: "ColorPicker_module_recentSwatch"
608
616
  };
617
+
618
+ // src/components/SliderControl/SliderControl.module.scss
619
+ var SliderControl_module_default = {
620
+ wrapper: "SliderControl_module_wrapper",
621
+ disabled: "SliderControl_module_disabled",
622
+ icon: "SliderControl_module_icon",
623
+ trackArea: "SliderControl_module_trackArea",
624
+ groove: "SliderControl_module_groove",
625
+ rail: "SliderControl_module_rail",
626
+ fill: "SliderControl_module_fill",
627
+ thumb: "SliderControl_module_thumb",
628
+ thumbDragging: "SliderControl_module_thumbDragging",
629
+ tooltip: "SliderControl_module_tooltip",
630
+ tooltipVisible: "SliderControl_module_tooltipVisible"
631
+ };
632
+ function clamp(v, min, max) {
633
+ return Math.min(Math.max(v, min), max);
634
+ }
635
+ function snapToStep(v, min, step) {
636
+ return Math.round((v - min) / step) * step + min;
637
+ }
638
+ var SliderControl = ({
639
+ value: controlledValue,
640
+ defaultValue = 50,
641
+ min = 0,
642
+ max = 100,
643
+ step = 1,
644
+ onChange,
645
+ showTooltip = "drag",
646
+ leftIcon,
647
+ rightIcon,
648
+ railBackground,
649
+ accent,
650
+ className,
651
+ disabled = false
652
+ }) => {
653
+ const isControlled = controlledValue !== void 0;
654
+ const [internalValue, setInternalValue] = useState(defaultValue);
655
+ const [isDragging, setIsDragging] = useState(false);
656
+ const [isFocused, setIsFocused] = useState(false);
657
+ const trackRef = useRef(null);
658
+ const thumbRef = useRef(null);
659
+ const value = isControlled ? controlledValue : internalValue;
660
+ const pct = (clamp(value, min, max) - min) / (max - min);
661
+ const accentVars = accent ? accentToCssVars(deriveAccent(accent), "slider") : {};
662
+ const setValue = useCallback(
663
+ (next) => {
664
+ const snapped = clamp(snapToStep(next, min, step), min, max);
665
+ if (!isControlled) setInternalValue(snapped);
666
+ onChange?.(snapped);
667
+ },
668
+ [isControlled, min, max, step, onChange]
669
+ );
670
+ const valueFromPointer = useCallback(
671
+ (e) => {
672
+ const rect = trackRef.current.getBoundingClientRect();
673
+ const ratio = clamp((e.clientX - rect.left) / rect.width, 0, 1);
674
+ return min + ratio * (max - min);
675
+ },
676
+ [min, max]
677
+ );
678
+ const handlePointerDown = useCallback(
679
+ (e) => {
680
+ if (disabled) return;
681
+ e.currentTarget.setPointerCapture(e.pointerId);
682
+ setIsDragging(true);
683
+ thumbRef.current?.focus();
684
+ setValue(valueFromPointer(e.nativeEvent));
685
+ },
686
+ [disabled, setValue, valueFromPointer]
687
+ );
688
+ const handlePointerMove = useCallback(
689
+ (e) => {
690
+ if (!isDragging || disabled) return;
691
+ setValue(valueFromPointer(e.nativeEvent));
692
+ },
693
+ [isDragging, disabled, setValue, valueFromPointer]
694
+ );
695
+ const handlePointerUp = useCallback(() => {
696
+ setIsDragging(false);
697
+ thumbRef.current?.blur();
698
+ }, []);
699
+ useEffect(() => {
700
+ const el = trackRef.current;
701
+ if (!el) return;
702
+ const onWheel = (e) => {
703
+ if (disabled) return;
704
+ e.preventDefault();
705
+ setValue(value + (e.deltaY < 0 ? step : -step));
706
+ };
707
+ el.addEventListener("wheel", onWheel, { passive: false });
708
+ return () => el.removeEventListener("wheel", onWheel);
709
+ }, [disabled, value, step, setValue]);
710
+ const handleKeyDown = useCallback(
711
+ (e) => {
712
+ if (disabled) return;
713
+ const map = {
714
+ ArrowRight: step,
715
+ ArrowUp: step,
716
+ ArrowLeft: -step,
717
+ ArrowDown: -step,
718
+ PageUp: step * 10,
719
+ PageDown: -step * 10
720
+ };
721
+ if (e.key === "Home") {
722
+ setValue(min);
723
+ e.preventDefault();
724
+ return;
725
+ }
726
+ if (e.key === "End") {
727
+ setValue(max);
728
+ e.preventDefault();
729
+ return;
730
+ }
731
+ if (map[e.key] !== void 0) {
732
+ setValue(value + map[e.key]);
733
+ e.preventDefault();
734
+ }
735
+ },
736
+ [disabled, step, min, max, value, setValue]
737
+ );
738
+ const tooltipVisible = showTooltip === "always" || showTooltip === "drag" && (isDragging || isFocused);
739
+ const displayValue = `${Math.round(value)}%`;
740
+ const tooltipOffset = `calc(${pct * 100}% + ${(0.5 - pct) * 20}px)`;
741
+ return /* @__PURE__ */ jsxs(
742
+ "div",
743
+ {
744
+ className: [SliderControl_module_default.wrapper, disabled ? SliderControl_module_default.disabled : "", className ?? ""].filter(Boolean).join(" "),
745
+ style: accentVars,
746
+ children: [
747
+ leftIcon !== null && leftIcon !== void 0 && /* @__PURE__ */ jsx("span", { className: SliderControl_module_default.icon, children: leftIcon }),
748
+ /* @__PURE__ */ jsxs(
749
+ "div",
750
+ {
751
+ ref: trackRef,
752
+ className: SliderControl_module_default.trackArea,
753
+ onPointerDown: handlePointerDown,
754
+ onPointerMove: handlePointerMove,
755
+ onPointerUp: handlePointerUp,
756
+ onPointerCancel: handlePointerUp,
757
+ children: [
758
+ /* @__PURE__ */ jsx("div", { className: SliderControl_module_default.groove, children: /* @__PURE__ */ jsx(
759
+ "div",
760
+ {
761
+ className: SliderControl_module_default.rail,
762
+ style: railBackground ? { background: railBackground } : void 0,
763
+ children: !railBackground && /* @__PURE__ */ jsx("div", { className: SliderControl_module_default.fill, style: { width: `${pct * 100}%` } })
764
+ }
765
+ ) }),
766
+ /* @__PURE__ */ jsx(
767
+ "div",
768
+ {
769
+ ref: thumbRef,
770
+ role: "slider",
771
+ tabIndex: disabled ? -1 : 0,
772
+ "aria-valuenow": Math.round(value),
773
+ "aria-valuemin": min,
774
+ "aria-valuemax": max,
775
+ "aria-disabled": disabled,
776
+ className: [SliderControl_module_default.thumb, isDragging ? SliderControl_module_default.thumbDragging : ""].filter(Boolean).join(" "),
777
+ style: { left: `calc(${pct * 100}% + ${(0.5 - pct) * 24}px)` },
778
+ onKeyDown: handleKeyDown,
779
+ onFocus: () => setIsFocused(true),
780
+ onBlur: () => setIsFocused(false)
781
+ }
782
+ ),
783
+ /* @__PURE__ */ jsx(
784
+ "div",
785
+ {
786
+ className: [SliderControl_module_default.tooltip, tooltipVisible ? SliderControl_module_default.tooltipVisible : ""].filter(Boolean).join(" "),
787
+ style: { left: tooltipOffset },
788
+ "aria-hidden": "true",
789
+ children: displayValue
790
+ }
791
+ )
792
+ ]
793
+ }
794
+ ),
795
+ rightIcon !== null && rightIcon !== void 0 && /* @__PURE__ */ jsx("span", { className: SliderControl_module_default.icon, children: rightIcon })
796
+ ]
797
+ }
798
+ );
799
+ };
800
+ SliderControl.displayName = "SliderControl";
609
801
  var DISC = 200;
610
802
  var CopyIcon = () => /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", children: [
611
803
  /* @__PURE__ */ jsx("rect", { x: "5", y: "5", width: "7", height: "7", rx: "1.5", stroke: "currentColor", strokeWidth: "1.4" }),
@@ -775,50 +967,21 @@ var ColorPicker = ({
775
967
  },
776
968
  [updateDisc]
777
969
  );
778
- const updateL = useCallback(
779
- (clientX, rect) => {
780
- const nl = Math.max(0, Math.min(100, (clientX - rect.left) / rect.width * 100));
970
+ const handleLChange = useCallback(
971
+ (nl) => {
781
972
  setL(nl);
782
973
  notify(h, s, nl, a);
783
974
  },
784
975
  [h, s, a, notify]
785
976
  );
786
- const handleLPointerDown = useCallback(
787
- (e) => {
788
- e.currentTarget.setPointerCapture(e.pointerId);
789
- updateL(e.clientX, e.currentTarget.getBoundingClientRect());
790
- },
791
- [updateL]
792
- );
793
- const handleLPointerMove = useCallback(
794
- (e) => {
795
- if (e.buttons === 0) return;
796
- updateL(e.clientX, e.currentTarget.getBoundingClientRect());
797
- },
798
- [updateL]
799
- );
800
- const updateA = useCallback(
801
- (clientX, rect) => {
802
- const na = Math.max(0, Math.min(1, (clientX - rect.left) / rect.width));
977
+ const handleAChange = useCallback(
978
+ (val) => {
979
+ const na = val / 100;
803
980
  setA(na);
804
981
  notify(h, s, l, na);
805
982
  },
806
983
  [h, s, l, notify]
807
984
  );
808
- const handleAPointerDown = useCallback(
809
- (e) => {
810
- e.currentTarget.setPointerCapture(e.pointerId);
811
- updateA(e.clientX, e.currentTarget.getBoundingClientRect());
812
- },
813
- [updateA]
814
- );
815
- const handleAPointerMove = useCallback(
816
- (e) => {
817
- if (e.buttons === 0) return;
818
- updateA(e.clientX, e.currentTarget.getBoundingClientRect());
819
- },
820
- [updateA]
821
- );
822
985
  const { r: rr, g: gg, b: bb } = hslToRgb(h, s, l);
823
986
  const luminance = (0.299 * rr + 0.587 * gg + 0.114 * bb) / 255;
824
987
  const swatchFg = luminance > 0.6 ? "rgba(0,0,0,0.5)" : "rgba(255,255,255,0.9)";
@@ -831,7 +994,6 @@ var ColorPicker = ({
831
994
  hsl(${h}, ${s}%, 5%),
832
995
  hsl(${h}, ${s}%, 50%),
833
996
  hsl(${h}, ${s}%, 95%))`;
834
- const alphaGradient = `linear-gradient(to right, transparent, ${rgbStr})`;
835
997
  const handleEyeDropper = async () => {
836
998
  if (!window.EyeDropper) return;
837
999
  try {
@@ -892,35 +1054,27 @@ var ColorPicker = ({
892
1054
  )
893
1055
  ] }) }),
894
1056
  /* @__PURE__ */ jsx(
895
- "div",
1057
+ SliderControl,
896
1058
  {
897
- className: ColorPicker_module_default.lSlider,
898
- style: { backgroundImage: lGradient },
899
- onPointerDown: handleLPointerDown,
900
- onPointerMove: handleLPointerMove,
901
- children: /* @__PURE__ */ jsx(
902
- "div",
903
- {
904
- className: ColorPicker_module_default.lThumb,
905
- style: { left: `${l}%` }
906
- }
907
- )
1059
+ value: l,
1060
+ onChange: handleLChange,
1061
+ min: 0,
1062
+ max: 100,
1063
+ step: 1,
1064
+ showTooltip: "never",
1065
+ railBackground: lGradient
908
1066
  }
909
1067
  ),
910
1068
  showAlpha && /* @__PURE__ */ jsx(
911
- "div",
1069
+ SliderControl,
912
1070
  {
913
- className: ColorPicker_module_default.alphaSlider,
914
- style: { backgroundImage: alphaGradient },
915
- onPointerDown: handleAPointerDown,
916
- onPointerMove: handleAPointerMove,
917
- children: /* @__PURE__ */ jsx(
918
- "div",
919
- {
920
- className: ColorPicker_module_default.alphaThumb,
921
- style: { left: `${a * 100}%` }
922
- }
923
- )
1071
+ value: Math.round(a * 100),
1072
+ onChange: handleAChange,
1073
+ min: 0,
1074
+ max: 100,
1075
+ step: 1,
1076
+ showTooltip: "never",
1077
+ railBackground: `linear-gradient(to right, transparent, ${rgbStr}), repeating-conic-gradient(#ccc 0% 25%, #fff 0% 50%) 0 / 10px 10px`
924
1078
  }
925
1079
  ),
926
1080
  /* @__PURE__ */ jsx(
@@ -990,6 +1144,3547 @@ var ColorPicker = ({
990
1144
  );
991
1145
  };
992
1146
 
993
- export { Badge, Button, ColorPicker, Input, RainCanvas, Timeline };
1147
+ // src/components/SlidingCounter/SlidingCounter.module.scss
1148
+ var SlidingCounter_module_default = {
1149
+ counter: "SlidingCounter_module_counter",
1150
+ sign: "SlidingCounter_module_sign",
1151
+ separator: "SlidingCounter_module_separator",
1152
+ reelWindow: "SlidingCounter_module_reelWindow",
1153
+ sm: "SlidingCounter_module_sm",
1154
+ md: "SlidingCounter_module_md",
1155
+ lg: "SlidingCounter_module_lg",
1156
+ reel: "SlidingCounter_module_reel",
1157
+ digitCell: "SlidingCounter_module_digitCell"
1158
+ };
1159
+ var COPIES = 3;
1160
+ var TOTAL = COPIES * 10;
1161
+ var DigitReel = ({ digit, direction, size }) => {
1162
+ const posRef = useRef(10 + digit);
1163
+ const prevDigitRef = useRef(digit);
1164
+ const [pos, setPos] = useState(10 + digit);
1165
+ const [animate, setAnimate] = useState(true);
1166
+ useEffect(() => {
1167
+ if (prevDigitRef.current === digit) return;
1168
+ const prev = prevDigitRef.current;
1169
+ let next = posRef.current;
1170
+ if (direction === "up") {
1171
+ next += digit > prev ? digit - prev : 10 - prev + digit;
1172
+ } else {
1173
+ next -= digit < prev ? prev - digit : prev + 10 - digit;
1174
+ }
1175
+ posRef.current = next;
1176
+ prevDigitRef.current = digit;
1177
+ setAnimate(true);
1178
+ setPos(next);
1179
+ }, [digit, direction]);
1180
+ const handleTransitionEnd = () => {
1181
+ const normalized = 10 + (posRef.current % 10 + 10) % 10;
1182
+ posRef.current = normalized;
1183
+ setAnimate(false);
1184
+ setPos(normalized);
1185
+ };
1186
+ const translateY = -(pos / TOTAL) * 100;
1187
+ const cells = Array.from(
1188
+ { length: COPIES },
1189
+ () => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
1190
+ ).flat();
1191
+ return /* @__PURE__ */ jsx("div", { className: `${SlidingCounter_module_default.reelWindow} ${SlidingCounter_module_default[size]}`, children: /* @__PURE__ */ jsx(
1192
+ "div",
1193
+ {
1194
+ className: SlidingCounter_module_default.reel,
1195
+ style: {
1196
+ transform: `translateY(${translateY}%)`,
1197
+ transition: animate ? void 0 : "none"
1198
+ },
1199
+ onTransitionEnd: handleTransitionEnd,
1200
+ children: cells.map((d, i) => /* @__PURE__ */ jsx("div", { className: SlidingCounter_module_default.digitCell, children: d }, i))
1201
+ }
1202
+ ) });
1203
+ };
1204
+ function splitDigits(value, minDigits, decimals) {
1205
+ const abs = Math.abs(value);
1206
+ const fixed = abs.toFixed(decimals);
1207
+ const [intPart, decPart = ""] = fixed.split(".");
1208
+ const intDigits = intPart.split("").map(Number);
1209
+ const padded = intDigits.length < minDigits ? [...Array(minDigits - intDigits.length).fill(0), ...intDigits] : intDigits;
1210
+ const decDigits = decPart.split("").map(Number);
1211
+ return { intDigits: padded, decDigits };
1212
+ }
1213
+ var SlidingCounter = ({
1214
+ value,
1215
+ minDigits = 1,
1216
+ decimals = 0,
1217
+ decimalSeparator = ".",
1218
+ size = "md",
1219
+ accent,
1220
+ className
1221
+ }) => {
1222
+ const accentVars = accent ? accentToCssVars(deriveAccent(accent), "sliding-counter") : {};
1223
+ const safeValue = isFinite(value) ? value : 0;
1224
+ const prevValueRef = useRef(safeValue);
1225
+ const direction = safeValue >= prevValueRef.current ? "up" : "down";
1226
+ prevValueRef.current = safeValue;
1227
+ const { intDigits, decDigits } = splitDigits(safeValue, minDigits, decimals);
1228
+ return /* @__PURE__ */ jsxs(
1229
+ "div",
1230
+ {
1231
+ className: [SlidingCounter_module_default.counter, SlidingCounter_module_default[size], className ?? ""].filter(Boolean).join(" "),
1232
+ style: accentVars,
1233
+ "aria-label": safeValue.toFixed(decimals),
1234
+ children: [
1235
+ safeValue < 0 && /* @__PURE__ */ jsx("span", { className: SlidingCounter_module_default.sign, children: "\u2212" }),
1236
+ intDigits.map((digit, i) => /* @__PURE__ */ jsx(DigitReel, { digit, direction, size }, `int-${intDigits.length - i}`)),
1237
+ decimals > 0 && /* @__PURE__ */ jsx("span", { className: SlidingCounter_module_default.separator, children: decimalSeparator }),
1238
+ decDigits.map((digit, i) => /* @__PURE__ */ jsx(DigitReel, { digit, direction, size }, `dec-${i}`))
1239
+ ]
1240
+ }
1241
+ );
1242
+ };
1243
+
1244
+ // src/components/RichTextEditor/RichTextEditor.module.scss
1245
+ var RichTextEditor_module_default = {
1246
+ root: "RichTextEditor_module_root",
1247
+ readOnly: "RichTextEditor_module_readOnly",
1248
+ toolbar: "RichTextEditor_module_toolbar",
1249
+ toolbarGroup: "RichTextEditor_module_toolbarGroup",
1250
+ divider: "RichTextEditor_module_divider",
1251
+ toolbarButton: "RichTextEditor_module_toolbarButton",
1252
+ active: "RichTextEditor_module_active",
1253
+ headingButton: "RichTextEditor_module_headingButton",
1254
+ bubbleMenu: "RichTextEditor_module_bubbleMenu",
1255
+ editorContent: "RichTextEditor_module_editorContent"};
1256
+ var BulletListIcon = () => /* @__PURE__ */ jsxs("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: [
1257
+ /* @__PURE__ */ jsx("circle", { cx: "2.5", cy: "4", r: "1.5", fill: "currentColor" }),
1258
+ /* @__PURE__ */ jsx("line", { x1: "6", y1: "4", x2: "14", y2: "4", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }),
1259
+ /* @__PURE__ */ jsx("circle", { cx: "2.5", cy: "8", r: "1.5", fill: "currentColor" }),
1260
+ /* @__PURE__ */ jsx("line", { x1: "6", y1: "8", x2: "14", y2: "8", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }),
1261
+ /* @__PURE__ */ jsx("circle", { cx: "2.5", cy: "12", r: "1.5", fill: "currentColor" }),
1262
+ /* @__PURE__ */ jsx("line", { x1: "6", y1: "12", x2: "14", y2: "12", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
1263
+ ] });
1264
+ var OrderedListIcon = () => /* @__PURE__ */ jsxs("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: [
1265
+ /* @__PURE__ */ jsx("text", { x: "0.5", y: "5.5", fontSize: "5.5", fill: "currentColor", fontFamily: "system-ui, sans-serif", children: "1." }),
1266
+ /* @__PURE__ */ jsx("line", { x1: "7", y1: "4", x2: "14", y2: "4", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }),
1267
+ /* @__PURE__ */ jsx("text", { x: "0.5", y: "9.5", fontSize: "5.5", fill: "currentColor", fontFamily: "system-ui, sans-serif", children: "2." }),
1268
+ /* @__PURE__ */ jsx("line", { x1: "7", y1: "8", x2: "14", y2: "8", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }),
1269
+ /* @__PURE__ */ jsx("text", { x: "0.5", y: "13.5", fontSize: "5.5", fill: "currentColor", fontFamily: "system-ui, sans-serif", children: "3." }),
1270
+ /* @__PURE__ */ jsx("line", { x1: "7", y1: "12", x2: "14", y2: "12", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
1271
+ ] });
1272
+ var Toolbar = ({ slotBefore }) => {
1273
+ const { editor } = useCurrentEditor();
1274
+ if (!editor) return null;
1275
+ return /* @__PURE__ */ jsxs("div", { className: RichTextEditor_module_default.toolbar, role: "toolbar", "aria-label": "Text formatting", children: [
1276
+ /* @__PURE__ */ jsx("div", { className: RichTextEditor_module_default.toolbarGroup, children: [
1277
+ { render: () => /* @__PURE__ */ jsx("strong", { children: "B" }), title: "Bold", action: () => editor.chain().focus().toggleBold().run(), active: editor.isActive("bold") },
1278
+ { render: () => /* @__PURE__ */ jsx("em", { children: "I" }), title: "Italic", action: () => editor.chain().focus().toggleItalic().run(), active: editor.isActive("italic") },
1279
+ { render: () => /* @__PURE__ */ jsx("u", { children: "U" }), title: "Underline", action: () => editor.chain().focus().toggleUnderline().run(), active: editor.isActive("underline") },
1280
+ { render: () => /* @__PURE__ */ jsx("s", { children: "S" }), title: "Strikethrough", action: () => editor.chain().focus().toggleStrike().run(), active: editor.isActive("strike") }
1281
+ ].map(({ render, title, action, active }) => /* @__PURE__ */ jsx(
1282
+ "button",
1283
+ {
1284
+ type: "button",
1285
+ title,
1286
+ "aria-label": title,
1287
+ "aria-pressed": active,
1288
+ className: [RichTextEditor_module_default.toolbarButton, active ? RichTextEditor_module_default.active : ""].filter(Boolean).join(" "),
1289
+ onMouseDown: (e) => {
1290
+ e.preventDefault();
1291
+ action();
1292
+ },
1293
+ children: render()
1294
+ },
1295
+ title
1296
+ )) }),
1297
+ /* @__PURE__ */ jsx("div", { className: RichTextEditor_module_default.divider, "aria-hidden": "true" }),
1298
+ /* @__PURE__ */ jsx("div", { className: RichTextEditor_module_default.toolbarGroup, children: [1, 2, 3].map((level) => /* @__PURE__ */ jsxs(
1299
+ "button",
1300
+ {
1301
+ type: "button",
1302
+ title: `Heading ${level}`,
1303
+ "aria-label": `Heading ${level}`,
1304
+ "aria-pressed": editor.isActive("heading", { level }),
1305
+ className: [
1306
+ RichTextEditor_module_default.toolbarButton,
1307
+ RichTextEditor_module_default.headingButton,
1308
+ editor.isActive("heading", { level }) ? RichTextEditor_module_default.active : ""
1309
+ ].filter(Boolean).join(" "),
1310
+ onMouseDown: (e) => {
1311
+ e.preventDefault();
1312
+ editor.chain().focus().toggleHeading({ level }).run();
1313
+ },
1314
+ children: [
1315
+ "H",
1316
+ level
1317
+ ]
1318
+ },
1319
+ `h${level}`
1320
+ )) }),
1321
+ /* @__PURE__ */ jsx("div", { className: RichTextEditor_module_default.divider, "aria-hidden": "true" }),
1322
+ /* @__PURE__ */ jsx("div", { className: RichTextEditor_module_default.toolbarGroup, children: [
1323
+ { icon: /* @__PURE__ */ jsx(BulletListIcon, {}), title: "Bullet list", action: () => editor.chain().focus().toggleBulletList().run(), active: editor.isActive("bulletList") },
1324
+ { icon: /* @__PURE__ */ jsx(OrderedListIcon, {}), title: "Ordered list", action: () => editor.chain().focus().toggleOrderedList().run(), active: editor.isActive("orderedList") }
1325
+ ].map(({ icon, title, action, active }) => /* @__PURE__ */ jsx(
1326
+ "button",
1327
+ {
1328
+ type: "button",
1329
+ title,
1330
+ "aria-label": title,
1331
+ "aria-pressed": active,
1332
+ className: [RichTextEditor_module_default.toolbarButton, active ? RichTextEditor_module_default.active : ""].filter(Boolean).join(" "),
1333
+ onMouseDown: (e) => {
1334
+ e.preventDefault();
1335
+ action();
1336
+ },
1337
+ children: icon
1338
+ },
1339
+ title
1340
+ )) }),
1341
+ slotBefore && /* @__PURE__ */ jsxs(Fragment$1, { children: [
1342
+ /* @__PURE__ */ jsx("div", { className: RichTextEditor_module_default.divider, "aria-hidden": "true" }),
1343
+ /* @__PURE__ */ jsx("div", { className: RichTextEditor_module_default.toolbarGroup, children: slotBefore })
1344
+ ] })
1345
+ ] });
1346
+ };
1347
+ var BubbleMenu = () => {
1348
+ const { editor } = useCurrentEditor();
1349
+ const menuRef = useRef(null);
1350
+ const [pos, setPos] = useState(null);
1351
+ useEffect(() => {
1352
+ if (!editor) return;
1353
+ const update = () => {
1354
+ const { selection } = editor.state;
1355
+ if (selection.empty) {
1356
+ setPos(null);
1357
+ return;
1358
+ }
1359
+ const { from, to } = selection;
1360
+ const start = editor.view.coordsAtPos(from);
1361
+ const end = editor.view.coordsAtPos(to);
1362
+ const halfW = (menuRef.current?.offsetWidth ?? 0) / 2;
1363
+ const menuH = menuRef.current?.offsetHeight ?? 0;
1364
+ const rawX = (start.left + end.left) / 2;
1365
+ const clampedX = Math.max(halfW + 8, Math.min(rawX, window.innerWidth - halfW - 8));
1366
+ const toolbarBottom = document.querySelector("[role='toolbar']")?.getBoundingClientRect().bottom ?? 0;
1367
+ const flip = start.top - menuH - 8 < toolbarBottom + 8;
1368
+ setPos({ x: clampedX, y: flip ? start.bottom : start.top, flip });
1369
+ };
1370
+ editor.on("selectionUpdate", update);
1371
+ editor.on("blur", () => setPos(null));
1372
+ return () => {
1373
+ editor.off("selectionUpdate", update);
1374
+ editor.off("blur", () => setPos(null));
1375
+ };
1376
+ }, [editor]);
1377
+ if (!editor) return null;
1378
+ const visible = pos !== null;
1379
+ return /* @__PURE__ */ jsx(
1380
+ "div",
1381
+ {
1382
+ ref: menuRef,
1383
+ className: RichTextEditor_module_default.bubbleMenu,
1384
+ "aria-hidden": !visible,
1385
+ style: {
1386
+ position: "fixed",
1387
+ left: pos?.x ?? 0,
1388
+ top: pos?.y ?? 0,
1389
+ transform: pos?.flip ? "translate(-50%, 8px)" : "translate(-50%, calc(-100% - 8px))",
1390
+ zIndex: 50,
1391
+ visibility: visible ? "visible" : "hidden",
1392
+ pointerEvents: visible ? "auto" : "none"
1393
+ },
1394
+ children: [
1395
+ { render: () => /* @__PURE__ */ jsx("strong", { children: "B" }), title: "Bold", action: () => editor.chain().focus().toggleBold().run(), active: editor.isActive("bold") },
1396
+ { render: () => /* @__PURE__ */ jsx("em", { children: "I" }), title: "Italic", action: () => editor.chain().focus().toggleItalic().run(), active: editor.isActive("italic") },
1397
+ { render: () => /* @__PURE__ */ jsx("u", { children: "U" }), title: "Underline", action: () => editor.chain().focus().toggleUnderline().run(), active: editor.isActive("underline") },
1398
+ { render: () => /* @__PURE__ */ jsx("s", { children: "S" }), title: "Strikethrough", action: () => editor.chain().focus().toggleStrike().run(), active: editor.isActive("strike") }
1399
+ ].map(({ render, title, action, active }) => /* @__PURE__ */ jsx(
1400
+ "button",
1401
+ {
1402
+ type: "button",
1403
+ title,
1404
+ "aria-label": title,
1405
+ "aria-pressed": active,
1406
+ className: [RichTextEditor_module_default.toolbarButton, active ? RichTextEditor_module_default.active : ""].filter(Boolean).join(" "),
1407
+ onMouseDown: (e) => {
1408
+ e.preventDefault();
1409
+ action();
1410
+ },
1411
+ children: render()
1412
+ },
1413
+ title
1414
+ ))
1415
+ }
1416
+ );
1417
+ };
1418
+ var RichTextEditor = ({
1419
+ value,
1420
+ placeholder = "Start writing...",
1421
+ readOnly = false,
1422
+ minHeight = 200,
1423
+ maxHeight,
1424
+ accent,
1425
+ extensions = [],
1426
+ slotBefore,
1427
+ slotAfter,
1428
+ onChangeHTML,
1429
+ onChangeJSON
1430
+ }) => {
1431
+ const accentVars = accent ? accentToCssVars(deriveAccent(accent), "rich-text-editor") : {};
1432
+ const minHeightValue = typeof minHeight === "number" ? `${minHeight}px` : minHeight;
1433
+ const maxHeightValue = maxHeight !== void 0 ? typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight : void 0;
1434
+ return /* @__PURE__ */ jsx(
1435
+ "div",
1436
+ {
1437
+ className: [RichTextEditor_module_default.root, readOnly ? RichTextEditor_module_default.readOnly : ""].filter(Boolean).join(" "),
1438
+ style: { ...accentVars, "--rte-min-height": minHeightValue, "--rte-max-height": maxHeightValue },
1439
+ children: /* @__PURE__ */ jsx(
1440
+ EditorProvider,
1441
+ {
1442
+ extensions: [
1443
+ StarterKit.configure({ heading: { levels: [1, 2, 3] } }),
1444
+ Underline,
1445
+ Placeholder.configure({ placeholder }),
1446
+ ...extensions
1447
+ ],
1448
+ content: value,
1449
+ editable: !readOnly,
1450
+ onUpdate: ({ editor }) => {
1451
+ onChangeHTML?.(editor.getHTML());
1452
+ onChangeJSON?.(editor.getJSON());
1453
+ },
1454
+ slotBefore: !readOnly ? /* @__PURE__ */ jsx(Toolbar, { slotBefore }) : void 0,
1455
+ slotAfter,
1456
+ editorContainerProps: { className: RichTextEditor_module_default.editorContent },
1457
+ children: !readOnly && /* @__PURE__ */ jsx(BubbleMenu, {})
1458
+ }
1459
+ )
1460
+ }
1461
+ );
1462
+ };
1463
+ var __defProp = Object.defineProperty;
1464
+ var __export = (target, all) => {
1465
+ for (var name in all)
1466
+ __defProp(target, name, { get: all[name], enumerable: true });
1467
+ };
1468
+ function createChainableState(config) {
1469
+ const { state, transaction } = config;
1470
+ let { selection } = transaction;
1471
+ let { doc } = transaction;
1472
+ let { storedMarks } = transaction;
1473
+ return {
1474
+ ...state,
1475
+ apply: state.apply.bind(state),
1476
+ applyTransaction: state.applyTransaction.bind(state),
1477
+ plugins: state.plugins,
1478
+ schema: state.schema,
1479
+ reconfigure: state.reconfigure.bind(state),
1480
+ toJSON: state.toJSON.bind(state),
1481
+ get storedMarks() {
1482
+ return storedMarks;
1483
+ },
1484
+ get selection() {
1485
+ return selection;
1486
+ },
1487
+ get doc() {
1488
+ return doc;
1489
+ },
1490
+ get tr() {
1491
+ selection = transaction.selection;
1492
+ doc = transaction.doc;
1493
+ storedMarks = transaction.storedMarks;
1494
+ return transaction;
1495
+ }
1496
+ };
1497
+ }
1498
+ var CommandManager = class {
1499
+ constructor(props) {
1500
+ this.editor = props.editor;
1501
+ this.rawCommands = this.editor.extensionManager.commands;
1502
+ this.customState = props.state;
1503
+ }
1504
+ get hasCustomState() {
1505
+ return !!this.customState;
1506
+ }
1507
+ get state() {
1508
+ return this.customState || this.editor.state;
1509
+ }
1510
+ get commands() {
1511
+ const { rawCommands, editor, state } = this;
1512
+ const { view } = editor;
1513
+ const { tr } = state;
1514
+ const props = this.buildProps(tr);
1515
+ return Object.fromEntries(
1516
+ Object.entries(rawCommands).map(([name, command2]) => {
1517
+ const method = (...args) => {
1518
+ const callback = command2(...args)(props);
1519
+ if (!tr.getMeta("preventDispatch") && !this.hasCustomState) {
1520
+ view.dispatch(tr);
1521
+ }
1522
+ return callback;
1523
+ };
1524
+ return [name, method];
1525
+ })
1526
+ );
1527
+ }
1528
+ get chain() {
1529
+ return () => this.createChain();
1530
+ }
1531
+ get can() {
1532
+ return () => this.createCan();
1533
+ }
1534
+ createChain(startTr, shouldDispatch = true) {
1535
+ const { rawCommands, editor, state } = this;
1536
+ const { view } = editor;
1537
+ const callbacks = [];
1538
+ const hasStartTransaction = !!startTr;
1539
+ const tr = startTr || state.tr;
1540
+ const run3 = () => {
1541
+ if (!hasStartTransaction && shouldDispatch && !tr.getMeta("preventDispatch") && !this.hasCustomState) {
1542
+ view.dispatch(tr);
1543
+ }
1544
+ return callbacks.every((callback) => callback === true);
1545
+ };
1546
+ const chain = {
1547
+ ...Object.fromEntries(
1548
+ Object.entries(rawCommands).map(([name, command2]) => {
1549
+ const chainedCommand = (...args) => {
1550
+ const props = this.buildProps(tr, shouldDispatch);
1551
+ const callback = command2(...args)(props);
1552
+ callbacks.push(callback);
1553
+ return chain;
1554
+ };
1555
+ return [name, chainedCommand];
1556
+ })
1557
+ ),
1558
+ run: run3
1559
+ };
1560
+ return chain;
1561
+ }
1562
+ createCan(startTr) {
1563
+ const { rawCommands, state } = this;
1564
+ const dispatch = false;
1565
+ const tr = startTr || state.tr;
1566
+ const props = this.buildProps(tr, dispatch);
1567
+ const formattedCommands = Object.fromEntries(
1568
+ Object.entries(rawCommands).map(([name, command2]) => {
1569
+ return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
1570
+ })
1571
+ );
1572
+ return {
1573
+ ...formattedCommands,
1574
+ chain: () => this.createChain(tr, dispatch)
1575
+ };
1576
+ }
1577
+ buildProps(tr, shouldDispatch = true) {
1578
+ const { rawCommands, editor, state } = this;
1579
+ const { view } = editor;
1580
+ const props = {
1581
+ tr,
1582
+ editor,
1583
+ view,
1584
+ state: createChainableState({
1585
+ state,
1586
+ transaction: tr
1587
+ }),
1588
+ dispatch: shouldDispatch ? () => void 0 : void 0,
1589
+ chain: () => this.createChain(tr, shouldDispatch),
1590
+ can: () => this.createCan(tr),
1591
+ get commands() {
1592
+ return Object.fromEntries(
1593
+ Object.entries(rawCommands).map(([name, command2]) => {
1594
+ return [name, (...args) => command2(...args)(props)];
1595
+ })
1596
+ );
1597
+ }
1598
+ };
1599
+ return props;
1600
+ }
1601
+ };
1602
+ var commands_exports = {};
1603
+ __export(commands_exports, {
1604
+ blur: () => blur,
1605
+ clearContent: () => clearContent,
1606
+ clearNodes: () => clearNodes,
1607
+ command: () => command,
1608
+ createParagraphNear: () => createParagraphNear,
1609
+ cut: () => cut,
1610
+ deleteCurrentNode: () => deleteCurrentNode,
1611
+ deleteNode: () => deleteNode,
1612
+ deleteRange: () => deleteRange,
1613
+ deleteSelection: () => deleteSelection,
1614
+ enter: () => enter,
1615
+ exitCode: () => exitCode,
1616
+ extendMarkRange: () => extendMarkRange,
1617
+ first: () => first,
1618
+ focus: () => focus,
1619
+ forEach: () => forEach,
1620
+ insertContent: () => insertContent,
1621
+ insertContentAt: () => insertContentAt,
1622
+ joinBackward: () => joinBackward,
1623
+ joinDown: () => joinDown,
1624
+ joinForward: () => joinForward,
1625
+ joinItemBackward: () => joinItemBackward,
1626
+ joinItemForward: () => joinItemForward,
1627
+ joinTextblockBackward: () => joinTextblockBackward,
1628
+ joinTextblockForward: () => joinTextblockForward,
1629
+ joinUp: () => joinUp,
1630
+ keyboardShortcut: () => keyboardShortcut,
1631
+ lift: () => lift,
1632
+ liftEmptyBlock: () => liftEmptyBlock,
1633
+ liftListItem: () => liftListItem,
1634
+ newlineInCode: () => newlineInCode,
1635
+ resetAttributes: () => resetAttributes,
1636
+ scrollIntoView: () => scrollIntoView,
1637
+ selectAll: () => selectAll,
1638
+ selectNodeBackward: () => selectNodeBackward,
1639
+ selectNodeForward: () => selectNodeForward,
1640
+ selectParentNode: () => selectParentNode,
1641
+ selectTextblockEnd: () => selectTextblockEnd,
1642
+ selectTextblockStart: () => selectTextblockStart,
1643
+ setContent: () => setContent,
1644
+ setMark: () => setMark,
1645
+ setMeta: () => setMeta,
1646
+ setNode: () => setNode,
1647
+ setNodeSelection: () => setNodeSelection,
1648
+ setTextDirection: () => setTextDirection,
1649
+ setTextSelection: () => setTextSelection,
1650
+ sinkListItem: () => sinkListItem,
1651
+ splitBlock: () => splitBlock,
1652
+ splitListItem: () => splitListItem,
1653
+ toggleList: () => toggleList,
1654
+ toggleMark: () => toggleMark,
1655
+ toggleNode: () => toggleNode,
1656
+ toggleWrap: () => toggleWrap,
1657
+ undoInputRule: () => undoInputRule,
1658
+ unsetAllMarks: () => unsetAllMarks,
1659
+ unsetMark: () => unsetMark,
1660
+ unsetTextDirection: () => unsetTextDirection,
1661
+ updateAttributes: () => updateAttributes,
1662
+ wrapIn: () => wrapIn,
1663
+ wrapInList: () => wrapInList
1664
+ });
1665
+ var blur = () => ({ editor, view }) => {
1666
+ requestAnimationFrame(() => {
1667
+ var _a;
1668
+ if (!editor.isDestroyed) {
1669
+ view.dom.blur();
1670
+ (_a = window == null ? void 0 : window.getSelection()) == null ? void 0 : _a.removeAllRanges();
1671
+ }
1672
+ });
1673
+ return true;
1674
+ };
1675
+ var clearContent = (emitUpdate = true) => ({ commands }) => {
1676
+ return commands.setContent("", { emitUpdate });
1677
+ };
1678
+ var clearNodes = () => ({ state, tr, dispatch }) => {
1679
+ const { selection } = tr;
1680
+ const { ranges } = selection;
1681
+ if (!dispatch) {
1682
+ return true;
1683
+ }
1684
+ ranges.forEach(({ $from, $to }) => {
1685
+ state.doc.nodesBetween($from.pos, $to.pos, (node, pos) => {
1686
+ if (node.type.isText) {
1687
+ return;
1688
+ }
1689
+ const { doc, mapping } = tr;
1690
+ const $mappedFrom = doc.resolve(mapping.map(pos));
1691
+ const $mappedTo = doc.resolve(mapping.map(pos + node.nodeSize));
1692
+ const nodeRange = $mappedFrom.blockRange($mappedTo);
1693
+ if (!nodeRange) {
1694
+ return;
1695
+ }
1696
+ const targetLiftDepth = liftTarget(nodeRange);
1697
+ if (node.type.isTextblock) {
1698
+ const { defaultType } = $mappedFrom.parent.contentMatchAt($mappedFrom.index());
1699
+ tr.setNodeMarkup(nodeRange.start, defaultType);
1700
+ }
1701
+ if (targetLiftDepth || targetLiftDepth === 0) {
1702
+ tr.lift(nodeRange, targetLiftDepth);
1703
+ }
1704
+ });
1705
+ });
1706
+ return true;
1707
+ };
1708
+ var command = (fn) => (props) => {
1709
+ return fn(props);
1710
+ };
1711
+ var createParagraphNear = () => ({ state, dispatch }) => {
1712
+ return createParagraphNear$1(state, dispatch);
1713
+ };
1714
+ var cut = (originRange, targetPos) => ({ editor, tr }) => {
1715
+ const { state } = editor;
1716
+ const contentSlice = state.doc.slice(originRange.from, originRange.to);
1717
+ tr.deleteRange(originRange.from, originRange.to);
1718
+ const newPos = tr.mapping.map(targetPos);
1719
+ tr.insert(newPos, contentSlice.content);
1720
+ tr.setSelection(new TextSelection(tr.doc.resolve(Math.max(newPos - 1, 0))));
1721
+ return true;
1722
+ };
1723
+ var deleteCurrentNode = () => ({ tr, dispatch }) => {
1724
+ const { selection } = tr;
1725
+ const currentNode = selection.$anchor.node();
1726
+ if (currentNode.content.size > 0) {
1727
+ return false;
1728
+ }
1729
+ const $pos = tr.selection.$anchor;
1730
+ for (let depth = $pos.depth; depth > 0; depth -= 1) {
1731
+ const node = $pos.node(depth);
1732
+ if (node.type === currentNode.type) {
1733
+ if (dispatch) {
1734
+ const from = $pos.before(depth);
1735
+ const to = $pos.after(depth);
1736
+ tr.delete(from, to).scrollIntoView();
1737
+ }
1738
+ return true;
1739
+ }
1740
+ }
1741
+ return false;
1742
+ };
1743
+ function getNodeType(nameOrType, schema) {
1744
+ if (typeof nameOrType === "string") {
1745
+ if (!schema.nodes[nameOrType]) {
1746
+ throw Error(
1747
+ `There is no node type named '${nameOrType}'. Maybe you forgot to add the extension?`
1748
+ );
1749
+ }
1750
+ return schema.nodes[nameOrType];
1751
+ }
1752
+ return nameOrType;
1753
+ }
1754
+ var deleteNode = (typeOrName) => ({ tr, state, dispatch }) => {
1755
+ const type = getNodeType(typeOrName, state.schema);
1756
+ const $pos = tr.selection.$anchor;
1757
+ for (let depth = $pos.depth; depth > 0; depth -= 1) {
1758
+ const node = $pos.node(depth);
1759
+ if (node.type === type) {
1760
+ if (dispatch) {
1761
+ const from = $pos.before(depth);
1762
+ const to = $pos.after(depth);
1763
+ tr.delete(from, to).scrollIntoView();
1764
+ }
1765
+ return true;
1766
+ }
1767
+ }
1768
+ return false;
1769
+ };
1770
+ var deleteRange = (range) => ({ tr, dispatch }) => {
1771
+ const { from, to } = range;
1772
+ if (dispatch) {
1773
+ tr.delete(from, to);
1774
+ }
1775
+ return true;
1776
+ };
1777
+ var hasTextContent = (nodeSpec) => {
1778
+ if (!nodeSpec.content) {
1779
+ return false;
1780
+ }
1781
+ const textRegex = /^text(\*|\+)/;
1782
+ return textRegex.test(nodeSpec.content);
1783
+ };
1784
+ var expandSelectionForSide = ($pos, schema, side) => {
1785
+ if (!$pos.parent.isInline) {
1786
+ return $pos.pos;
1787
+ }
1788
+ if (side === "left" && $pos.pos > $pos.start() || side === "right" && $pos.pos < $pos.end()) {
1789
+ return $pos.pos;
1790
+ }
1791
+ const parentContent = schema.nodes[$pos.parent.type.name].spec;
1792
+ if (!hasTextContent(parentContent)) {
1793
+ return $pos.pos;
1794
+ }
1795
+ return side === "left" ? $pos.start() - 1 : $pos.end() + 1;
1796
+ };
1797
+ var expandSelectionForInlineText = ($from, $to, schema) => {
1798
+ const from = expandSelectionForSide($from, schema, "left");
1799
+ const to = expandSelectionForSide($to, schema, "right");
1800
+ return { from, to };
1801
+ };
1802
+ var deleteSelection = () => ({ state, dispatch }) => {
1803
+ const { $from, $to } = state.selection;
1804
+ if (state.selection.empty) {
1805
+ return false;
1806
+ }
1807
+ const { from, to } = expandSelectionForInlineText($from, $to, state.schema);
1808
+ if (dispatch) {
1809
+ state.tr.deleteRange(from, to).scrollIntoView();
1810
+ dispatch(state.tr);
1811
+ }
1812
+ return true;
1813
+ };
1814
+ var enter = () => ({ commands }) => {
1815
+ return commands.keyboardShortcut("Enter");
1816
+ };
1817
+ var exitCode = () => ({ state, dispatch }) => {
1818
+ return exitCode$1(state, dispatch);
1819
+ };
1820
+ function isRegExp(value) {
1821
+ return Object.prototype.toString.call(value) === "[object RegExp]";
1822
+ }
1823
+ function objectIncludes(object1, object2, options = { strict: true }) {
1824
+ const keys = Object.keys(object2);
1825
+ if (!keys.length) {
1826
+ return true;
1827
+ }
1828
+ return keys.every((key) => {
1829
+ if (options.strict) {
1830
+ return object2[key] === object1[key];
1831
+ }
1832
+ if (isRegExp(object2[key])) {
1833
+ return object2[key].test(object1[key]);
1834
+ }
1835
+ return object2[key] === object1[key];
1836
+ });
1837
+ }
1838
+ function findMarkInSet(marks, type, attributes = {}) {
1839
+ return marks.find((item) => {
1840
+ return item.type === type && objectIncludes(
1841
+ // Only check equality for the attributes that are provided
1842
+ Object.fromEntries(Object.keys(attributes).map((k) => [k, item.attrs[k]])),
1843
+ attributes
1844
+ );
1845
+ });
1846
+ }
1847
+ function isMarkInSet(marks, type, attributes = {}) {
1848
+ return !!findMarkInSet(marks, type, attributes);
1849
+ }
1850
+ function getMarkRange($pos, type, attributes) {
1851
+ if (!$pos || !type) {
1852
+ return;
1853
+ }
1854
+ let start = $pos.parent.childAfter($pos.parentOffset);
1855
+ if (!start.node || !start.node.marks.some((mark2) => mark2.type === type)) {
1856
+ start = $pos.parent.childBefore($pos.parentOffset);
1857
+ }
1858
+ if (!start.node || !start.node.marks.some((mark2) => mark2.type === type)) {
1859
+ return;
1860
+ }
1861
+ if (!attributes) {
1862
+ const firstMark = start.node.marks.find((mark2) => mark2.type === type);
1863
+ if (firstMark) {
1864
+ attributes = firstMark.attrs;
1865
+ }
1866
+ }
1867
+ const mark = findMarkInSet([...start.node.marks], type, attributes);
1868
+ if (!mark) {
1869
+ return;
1870
+ }
1871
+ let startIndex = start.index;
1872
+ let startPos = $pos.start() + start.offset;
1873
+ let endIndex = startIndex + 1;
1874
+ let endPos = startPos + start.node.nodeSize;
1875
+ while (startIndex > 0 && isMarkInSet([...$pos.parent.child(startIndex - 1).marks], type, attributes)) {
1876
+ startIndex -= 1;
1877
+ startPos -= $pos.parent.child(startIndex).nodeSize;
1878
+ }
1879
+ while (endIndex < $pos.parent.childCount && isMarkInSet([...$pos.parent.child(endIndex).marks], type, attributes)) {
1880
+ endPos += $pos.parent.child(endIndex).nodeSize;
1881
+ endIndex += 1;
1882
+ }
1883
+ return {
1884
+ from: startPos,
1885
+ to: endPos
1886
+ };
1887
+ }
1888
+ function getMarkType(nameOrType, schema) {
1889
+ if (typeof nameOrType === "string") {
1890
+ if (!schema.marks[nameOrType]) {
1891
+ throw Error(
1892
+ `There is no mark type named '${nameOrType}'. Maybe you forgot to add the extension?`
1893
+ );
1894
+ }
1895
+ return schema.marks[nameOrType];
1896
+ }
1897
+ return nameOrType;
1898
+ }
1899
+ var extendMarkRange = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
1900
+ const type = getMarkType(typeOrName, state.schema);
1901
+ const { doc, selection } = tr;
1902
+ const { $from, from, to } = selection;
1903
+ if (dispatch) {
1904
+ const range = getMarkRange($from, type, attributes);
1905
+ if (range && range.from <= from && range.to >= to) {
1906
+ const newSelection = TextSelection.create(doc, range.from, range.to);
1907
+ tr.setSelection(newSelection);
1908
+ }
1909
+ }
1910
+ return true;
1911
+ };
1912
+ var first = (commands) => (props) => {
1913
+ const items = typeof commands === "function" ? commands(props) : commands;
1914
+ for (let i = 0; i < items.length; i += 1) {
1915
+ if (items[i](props)) {
1916
+ return true;
1917
+ }
1918
+ }
1919
+ return false;
1920
+ };
1921
+ function isTextSelection(value) {
1922
+ return value instanceof TextSelection;
1923
+ }
1924
+ function minMax(value = 0, min = 0, max = 0) {
1925
+ return Math.min(Math.max(value, min), max);
1926
+ }
1927
+ function resolveFocusPosition(doc, position = null) {
1928
+ if (!position) {
1929
+ return null;
1930
+ }
1931
+ const selectionAtStart = Selection.atStart(doc);
1932
+ const selectionAtEnd = Selection.atEnd(doc);
1933
+ if (position === "start" || position === true) {
1934
+ return selectionAtStart;
1935
+ }
1936
+ if (position === "end") {
1937
+ return selectionAtEnd;
1938
+ }
1939
+ const minPos = selectionAtStart.from;
1940
+ const maxPos = selectionAtEnd.to;
1941
+ if (position === "all") {
1942
+ return TextSelection.create(
1943
+ doc,
1944
+ minMax(0, minPos, maxPos),
1945
+ minMax(doc.content.size, minPos, maxPos)
1946
+ );
1947
+ }
1948
+ return TextSelection.create(
1949
+ doc,
1950
+ minMax(position, minPos, maxPos),
1951
+ minMax(position, minPos, maxPos)
1952
+ );
1953
+ }
1954
+ function isAndroid() {
1955
+ return navigator.platform === "Android" || /android/i.test(navigator.userAgent);
1956
+ }
1957
+ function isiOS() {
1958
+ return ["iPad Simulator", "iPhone Simulator", "iPod Simulator", "iPad", "iPhone", "iPod"].includes(
1959
+ navigator.platform
1960
+ ) || // iPad on iOS 13 detection
1961
+ navigator.userAgent.includes("Mac") && "ontouchend" in document;
1962
+ }
1963
+ function isSafari() {
1964
+ return typeof navigator !== "undefined" ? /^((?!chrome|android).)*safari/i.test(navigator.userAgent) : false;
1965
+ }
1966
+ var focus = (position = null, options = {}) => ({ editor, view, tr, dispatch }) => {
1967
+ options = {
1968
+ scrollIntoView: true,
1969
+ ...options
1970
+ };
1971
+ const delayedFocus = () => {
1972
+ if (isiOS() || isAndroid()) {
1973
+ view.dom.focus();
1974
+ }
1975
+ if (isSafari() && !isiOS() && !isAndroid()) {
1976
+ view.dom.focus({ preventScroll: true });
1977
+ }
1978
+ requestAnimationFrame(() => {
1979
+ if (!editor.isDestroyed) {
1980
+ view.focus();
1981
+ if (options == null ? void 0 : options.scrollIntoView) {
1982
+ editor.commands.scrollIntoView();
1983
+ }
1984
+ }
1985
+ });
1986
+ };
1987
+ try {
1988
+ if (view.hasFocus() && position === null || position === false) {
1989
+ return true;
1990
+ }
1991
+ } catch {
1992
+ return false;
1993
+ }
1994
+ if (dispatch && position === null && !isTextSelection(editor.state.selection)) {
1995
+ delayedFocus();
1996
+ return true;
1997
+ }
1998
+ const selection = resolveFocusPosition(tr.doc, position) || editor.state.selection;
1999
+ const isSameSelection = editor.state.selection.eq(selection);
2000
+ if (dispatch) {
2001
+ if (!isSameSelection) {
2002
+ tr.setSelection(selection);
2003
+ }
2004
+ if (isSameSelection && tr.storedMarks) {
2005
+ tr.setStoredMarks(tr.storedMarks);
2006
+ }
2007
+ delayedFocus();
2008
+ }
2009
+ return true;
2010
+ };
2011
+ var forEach = (items, fn) => (props) => {
2012
+ return items.every((item, index) => fn(item, { ...props, index }));
2013
+ };
2014
+ var insertContent = (value, options) => ({ tr, commands }) => {
2015
+ return commands.insertContentAt(
2016
+ { from: tr.selection.from, to: tr.selection.to },
2017
+ value,
2018
+ options
2019
+ );
2020
+ };
2021
+ var removeWhitespaces = (node) => {
2022
+ const children = node.childNodes;
2023
+ for (let i = children.length - 1; i >= 0; i -= 1) {
2024
+ const child = children[i];
2025
+ if (child.nodeType === 3 && child.nodeValue && /^(\n\s\s|\n)$/.test(child.nodeValue)) {
2026
+ node.removeChild(child);
2027
+ } else if (child.nodeType === 1) {
2028
+ removeWhitespaces(child);
2029
+ }
2030
+ }
2031
+ return node;
2032
+ };
2033
+ function elementFromString(value) {
2034
+ if (typeof window === "undefined") {
2035
+ throw new Error(
2036
+ "[tiptap error]: there is no window object available, so this function cannot be used"
2037
+ );
2038
+ }
2039
+ const wrappedValue = `<body>${value}</body>`;
2040
+ const html = new window.DOMParser().parseFromString(wrappedValue, "text/html").body;
2041
+ return removeWhitespaces(html);
2042
+ }
2043
+ function createNodeFromContent(content, schema, options) {
2044
+ if (content instanceof Node || content instanceof Fragment) {
2045
+ return content;
2046
+ }
2047
+ options = {
2048
+ slice: true,
2049
+ parseOptions: {},
2050
+ ...options
2051
+ };
2052
+ const isJSONContent = typeof content === "object" && content !== null;
2053
+ const isTextContent = typeof content === "string";
2054
+ if (isJSONContent) {
2055
+ try {
2056
+ const isArrayContent = Array.isArray(content) && content.length > 0;
2057
+ if (isArrayContent) {
2058
+ return Fragment.fromArray(content.map((item) => schema.nodeFromJSON(item)));
2059
+ }
2060
+ const node = schema.nodeFromJSON(content);
2061
+ if (options.errorOnInvalidContent) {
2062
+ node.check();
2063
+ }
2064
+ return node;
2065
+ } catch (error) {
2066
+ if (options.errorOnInvalidContent) {
2067
+ throw new Error("[tiptap error]: Invalid JSON content", { cause: error });
2068
+ }
2069
+ console.warn("[tiptap warn]: Invalid content.", "Passed value:", content, "Error:", error);
2070
+ return createNodeFromContent("", schema, options);
2071
+ }
2072
+ }
2073
+ if (isTextContent) {
2074
+ if (options.errorOnInvalidContent) {
2075
+ let hasInvalidContent = false;
2076
+ let invalidContent = "";
2077
+ const contentCheckSchema = new Schema({
2078
+ topNode: schema.spec.topNode,
2079
+ marks: schema.spec.marks,
2080
+ // Prosemirror's schemas are executed such that: the last to execute, matches last
2081
+ // This means that we can add a catch-all node at the end of the schema to catch any content that we don't know how to handle
2082
+ nodes: schema.spec.nodes.append({
2083
+ __tiptap__private__unknown__catch__all__node: {
2084
+ content: "inline*",
2085
+ group: "block",
2086
+ parseDOM: [
2087
+ {
2088
+ tag: "*",
2089
+ getAttrs: (e) => {
2090
+ hasInvalidContent = true;
2091
+ invalidContent = typeof e === "string" ? e : e.outerHTML;
2092
+ return null;
2093
+ }
2094
+ }
2095
+ ]
2096
+ }
2097
+ })
2098
+ });
2099
+ if (options.slice) {
2100
+ DOMParser.fromSchema(contentCheckSchema).parseSlice(
2101
+ elementFromString(content),
2102
+ options.parseOptions
2103
+ );
2104
+ } else {
2105
+ DOMParser.fromSchema(contentCheckSchema).parse(
2106
+ elementFromString(content),
2107
+ options.parseOptions
2108
+ );
2109
+ }
2110
+ if (options.errorOnInvalidContent && hasInvalidContent) {
2111
+ throw new Error("[tiptap error]: Invalid HTML content", {
2112
+ cause: new Error(`Invalid element found: ${invalidContent}`)
2113
+ });
2114
+ }
2115
+ }
2116
+ const parser = DOMParser.fromSchema(schema);
2117
+ if (options.slice) {
2118
+ return parser.parseSlice(elementFromString(content), options.parseOptions).content;
2119
+ }
2120
+ return parser.parse(elementFromString(content), options.parseOptions);
2121
+ }
2122
+ return createNodeFromContent("", schema, options);
2123
+ }
2124
+ function selectionToInsertionEnd(tr, startLen, bias) {
2125
+ const last = tr.steps.length - 1;
2126
+ if (last < startLen) {
2127
+ return;
2128
+ }
2129
+ const step = tr.steps[last];
2130
+ if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {
2131
+ return;
2132
+ }
2133
+ const map = tr.mapping.maps[last];
2134
+ let end = 0;
2135
+ map.forEach((_from, _to, _newFrom, newTo) => {
2136
+ if (end === 0) {
2137
+ end = newTo;
2138
+ }
2139
+ });
2140
+ tr.setSelection(Selection.near(tr.doc.resolve(end), bias));
2141
+ }
2142
+ var isFragment = (nodeOrFragment) => {
2143
+ return !("type" in nodeOrFragment);
2144
+ };
2145
+ var insertContentAt = (position, value, options) => ({ tr, dispatch, editor }) => {
2146
+ var _a;
2147
+ if (dispatch) {
2148
+ options = {
2149
+ parseOptions: editor.options.parseOptions,
2150
+ updateSelection: true,
2151
+ applyInputRules: false,
2152
+ applyPasteRules: false,
2153
+ ...options
2154
+ };
2155
+ let content;
2156
+ const emitContentError = (error) => {
2157
+ editor.emit("contentError", {
2158
+ editor,
2159
+ error,
2160
+ disableCollaboration: () => {
2161
+ if ("collaboration" in editor.storage && typeof editor.storage.collaboration === "object" && editor.storage.collaboration) {
2162
+ editor.storage.collaboration.isDisabled = true;
2163
+ }
2164
+ }
2165
+ });
2166
+ };
2167
+ const parseOptions = {
2168
+ preserveWhitespace: "full",
2169
+ ...options.parseOptions
2170
+ };
2171
+ if (!options.errorOnInvalidContent && !editor.options.enableContentCheck && editor.options.emitContentError) {
2172
+ try {
2173
+ createNodeFromContent(value, editor.schema, {
2174
+ parseOptions,
2175
+ errorOnInvalidContent: true
2176
+ });
2177
+ } catch (e) {
2178
+ emitContentError(e);
2179
+ }
2180
+ }
2181
+ try {
2182
+ content = createNodeFromContent(value, editor.schema, {
2183
+ parseOptions,
2184
+ errorOnInvalidContent: (_a = options.errorOnInvalidContent) != null ? _a : editor.options.enableContentCheck
2185
+ });
2186
+ } catch (e) {
2187
+ emitContentError(e);
2188
+ return false;
2189
+ }
2190
+ let { from, to } = typeof position === "number" ? { from: position, to: position } : { from: position.from, to: position.to };
2191
+ let isOnlyTextContent = true;
2192
+ let isOnlyBlockContent = true;
2193
+ const nodes = isFragment(content) ? content : [content];
2194
+ nodes.forEach((node) => {
2195
+ node.check();
2196
+ isOnlyTextContent = isOnlyTextContent ? node.isText && node.marks.length === 0 : false;
2197
+ isOnlyBlockContent = isOnlyBlockContent ? node.isBlock : false;
2198
+ });
2199
+ if (from === to && isOnlyBlockContent) {
2200
+ const { parent } = tr.doc.resolve(from);
2201
+ const isEmptyTextBlock = parent.isTextblock && !parent.type.spec.code && !parent.childCount;
2202
+ if (isEmptyTextBlock) {
2203
+ from -= 1;
2204
+ to += 1;
2205
+ }
2206
+ }
2207
+ let newContent;
2208
+ if (isOnlyTextContent) {
2209
+ if (Array.isArray(value)) {
2210
+ newContent = value.map((v) => v.text || "").join("");
2211
+ } else if (value instanceof Fragment) {
2212
+ let text = "";
2213
+ value.forEach((node) => {
2214
+ if (node.text) {
2215
+ text += node.text;
2216
+ }
2217
+ });
2218
+ newContent = text;
2219
+ } else if (typeof value === "object" && !!value && !!value.text) {
2220
+ newContent = value.text;
2221
+ } else {
2222
+ newContent = value;
2223
+ }
2224
+ tr.insertText(newContent, from, to);
2225
+ } else {
2226
+ newContent = content;
2227
+ const $from = tr.doc.resolve(from);
2228
+ const $fromNode = $from.node();
2229
+ const fromSelectionAtStart = $from.parentOffset === 0;
2230
+ const isTextSelection2 = $fromNode.isText || $fromNode.isTextblock;
2231
+ const hasContent = $fromNode.content.size > 0;
2232
+ if (fromSelectionAtStart && isTextSelection2 && hasContent && isOnlyBlockContent) {
2233
+ from = Math.max(0, from - 1);
2234
+ }
2235
+ tr.replaceWith(from, to, newContent);
2236
+ }
2237
+ if (options.updateSelection) {
2238
+ selectionToInsertionEnd(tr, tr.steps.length - 1, -1);
2239
+ }
2240
+ if (options.applyInputRules) {
2241
+ tr.setMeta("applyInputRules", { from, text: newContent });
2242
+ }
2243
+ if (options.applyPasteRules) {
2244
+ tr.setMeta("applyPasteRules", { from, text: newContent });
2245
+ }
2246
+ }
2247
+ return true;
2248
+ };
2249
+ var joinUp = () => ({ state, dispatch }) => {
2250
+ return joinUp$1(state, dispatch);
2251
+ };
2252
+ var joinDown = () => ({ state, dispatch }) => {
2253
+ return joinDown$1(state, dispatch);
2254
+ };
2255
+ var joinBackward = () => ({ state, dispatch }) => {
2256
+ return joinBackward$1(state, dispatch);
2257
+ };
2258
+ var joinForward = () => ({ state, dispatch }) => {
2259
+ return joinForward$1(state, dispatch);
2260
+ };
2261
+ var joinItemBackward = () => ({ state, dispatch, tr }) => {
2262
+ try {
2263
+ const point = joinPoint(state.doc, state.selection.$from.pos, -1);
2264
+ if (point === null || point === void 0) {
2265
+ return false;
2266
+ }
2267
+ tr.join(point, 2);
2268
+ if (dispatch) {
2269
+ dispatch(tr);
2270
+ }
2271
+ return true;
2272
+ } catch {
2273
+ return false;
2274
+ }
2275
+ };
2276
+ var joinItemForward = () => ({ state, dispatch, tr }) => {
2277
+ try {
2278
+ const point = joinPoint(state.doc, state.selection.$from.pos, 1);
2279
+ if (point === null || point === void 0) {
2280
+ return false;
2281
+ }
2282
+ tr.join(point, 2);
2283
+ if (dispatch) {
2284
+ dispatch(tr);
2285
+ }
2286
+ return true;
2287
+ } catch {
2288
+ return false;
2289
+ }
2290
+ };
2291
+ var joinTextblockBackward = () => ({ state, dispatch }) => {
2292
+ return joinTextblockBackward$1(state, dispatch);
2293
+ };
2294
+ var joinTextblockForward = () => ({ state, dispatch }) => {
2295
+ return joinTextblockForward$1(state, dispatch);
2296
+ };
2297
+ function isMacOS() {
2298
+ return typeof navigator !== "undefined" ? /Mac/.test(navigator.platform) : false;
2299
+ }
2300
+ function normalizeKeyName(name) {
2301
+ const parts = name.split(/-(?!$)/);
2302
+ let result = parts[parts.length - 1];
2303
+ if (result === "Space") {
2304
+ result = " ";
2305
+ }
2306
+ let alt;
2307
+ let ctrl;
2308
+ let shift;
2309
+ let meta;
2310
+ for (let i = 0; i < parts.length - 1; i += 1) {
2311
+ const mod = parts[i];
2312
+ if (/^(cmd|meta|m)$/i.test(mod)) {
2313
+ meta = true;
2314
+ } else if (/^a(lt)?$/i.test(mod)) {
2315
+ alt = true;
2316
+ } else if (/^(c|ctrl|control)$/i.test(mod)) {
2317
+ ctrl = true;
2318
+ } else if (/^s(hift)?$/i.test(mod)) {
2319
+ shift = true;
2320
+ } else if (/^mod$/i.test(mod)) {
2321
+ if (isiOS() || isMacOS()) {
2322
+ meta = true;
2323
+ } else {
2324
+ ctrl = true;
2325
+ }
2326
+ } else {
2327
+ throw new Error(`Unrecognized modifier name: ${mod}`);
2328
+ }
2329
+ }
2330
+ if (alt) {
2331
+ result = `Alt-${result}`;
2332
+ }
2333
+ if (ctrl) {
2334
+ result = `Ctrl-${result}`;
2335
+ }
2336
+ if (meta) {
2337
+ result = `Meta-${result}`;
2338
+ }
2339
+ if (shift) {
2340
+ result = `Shift-${result}`;
2341
+ }
2342
+ return result;
2343
+ }
2344
+ var keyboardShortcut = (name) => ({ editor, view, tr, dispatch }) => {
2345
+ const keys = normalizeKeyName(name).split(/-(?!$)/);
2346
+ const key = keys.find((item) => !["Alt", "Ctrl", "Meta", "Shift"].includes(item));
2347
+ const event = new KeyboardEvent("keydown", {
2348
+ key: key === "Space" ? " " : key,
2349
+ altKey: keys.includes("Alt"),
2350
+ ctrlKey: keys.includes("Ctrl"),
2351
+ metaKey: keys.includes("Meta"),
2352
+ shiftKey: keys.includes("Shift"),
2353
+ bubbles: true,
2354
+ cancelable: true
2355
+ });
2356
+ const capturedTransaction = editor.captureTransaction(() => {
2357
+ view.someProp("handleKeyDown", (f) => f(view, event));
2358
+ });
2359
+ capturedTransaction == null ? void 0 : capturedTransaction.steps.forEach((step) => {
2360
+ const newStep = step.map(tr.mapping);
2361
+ if (newStep && dispatch) {
2362
+ tr.maybeStep(newStep);
2363
+ }
2364
+ });
2365
+ return true;
2366
+ };
2367
+ function isNodeActive(state, typeOrName, attributes = {}) {
2368
+ const { from, to, empty } = state.selection;
2369
+ const type = typeOrName ? getNodeType(typeOrName, state.schema) : null;
2370
+ const nodeRanges = [];
2371
+ state.doc.nodesBetween(from, to, (node, pos) => {
2372
+ if (node.isText) {
2373
+ return;
2374
+ }
2375
+ const relativeFrom = Math.max(from, pos);
2376
+ const relativeTo = Math.min(to, pos + node.nodeSize);
2377
+ nodeRanges.push({
2378
+ node,
2379
+ from: relativeFrom,
2380
+ to: relativeTo
2381
+ });
2382
+ });
2383
+ const selectionRange = to - from;
2384
+ const matchedNodeRanges = nodeRanges.filter((nodeRange) => {
2385
+ if (!type) {
2386
+ return true;
2387
+ }
2388
+ return type.name === nodeRange.node.type.name;
2389
+ }).filter((nodeRange) => objectIncludes(nodeRange.node.attrs, attributes, { strict: false }));
2390
+ if (empty) {
2391
+ return !!matchedNodeRanges.length;
2392
+ }
2393
+ const range = matchedNodeRanges.reduce((sum, nodeRange) => sum + nodeRange.to - nodeRange.from, 0);
2394
+ return range >= selectionRange;
2395
+ }
2396
+ var lift = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
2397
+ const type = getNodeType(typeOrName, state.schema);
2398
+ const isActive2 = isNodeActive(state, type, attributes);
2399
+ if (!isActive2) {
2400
+ return false;
2401
+ }
2402
+ return lift$1(state, dispatch);
2403
+ };
2404
+ var liftEmptyBlock = () => ({ state, dispatch }) => {
2405
+ return liftEmptyBlock$1(state, dispatch);
2406
+ };
2407
+ var liftListItem = (typeOrName) => ({ state, dispatch }) => {
2408
+ const type = getNodeType(typeOrName, state.schema);
2409
+ return liftListItem$1(type)(state, dispatch);
2410
+ };
2411
+ var newlineInCode = () => ({ state, dispatch }) => {
2412
+ return newlineInCode$1(state, dispatch);
2413
+ };
2414
+ function getSchemaTypeNameByName(name, schema) {
2415
+ if (schema.nodes[name]) {
2416
+ return "node";
2417
+ }
2418
+ if (schema.marks[name]) {
2419
+ return "mark";
2420
+ }
2421
+ return null;
2422
+ }
2423
+ function deleteProps(obj, propOrProps) {
2424
+ const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
2425
+ return Object.keys(obj).reduce((newObj, prop) => {
2426
+ if (!props.includes(prop)) {
2427
+ newObj[prop] = obj[prop];
2428
+ }
2429
+ return newObj;
2430
+ }, {});
2431
+ }
2432
+ var resetAttributes = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
2433
+ let nodeType = null;
2434
+ let markType = null;
2435
+ const schemaType = getSchemaTypeNameByName(
2436
+ typeof typeOrName === "string" ? typeOrName : typeOrName.name,
2437
+ state.schema
2438
+ );
2439
+ if (!schemaType) {
2440
+ return false;
2441
+ }
2442
+ if (schemaType === "node") {
2443
+ nodeType = getNodeType(typeOrName, state.schema);
2444
+ }
2445
+ if (schemaType === "mark") {
2446
+ markType = getMarkType(typeOrName, state.schema);
2447
+ }
2448
+ let canReset = false;
2449
+ tr.selection.ranges.forEach((range) => {
2450
+ state.doc.nodesBetween(range.$from.pos, range.$to.pos, (node, pos) => {
2451
+ if (nodeType && nodeType === node.type) {
2452
+ canReset = true;
2453
+ if (dispatch) {
2454
+ tr.setNodeMarkup(pos, void 0, deleteProps(node.attrs, attributes));
2455
+ }
2456
+ }
2457
+ if (markType && node.marks.length) {
2458
+ node.marks.forEach((mark) => {
2459
+ if (markType === mark.type) {
2460
+ canReset = true;
2461
+ if (dispatch) {
2462
+ tr.addMark(
2463
+ pos,
2464
+ pos + node.nodeSize,
2465
+ markType.create(deleteProps(mark.attrs, attributes))
2466
+ );
2467
+ }
2468
+ }
2469
+ });
2470
+ }
2471
+ });
2472
+ });
2473
+ return canReset;
2474
+ };
2475
+ var scrollIntoView = () => ({ tr, dispatch }) => {
2476
+ if (dispatch) {
2477
+ tr.scrollIntoView();
2478
+ }
2479
+ return true;
2480
+ };
2481
+ var selectAll = () => ({ tr, dispatch }) => {
2482
+ if (dispatch) {
2483
+ const selection = new AllSelection(tr.doc);
2484
+ tr.setSelection(selection);
2485
+ }
2486
+ return true;
2487
+ };
2488
+ var selectNodeBackward = () => ({ state, dispatch }) => {
2489
+ return selectNodeBackward$1(state, dispatch);
2490
+ };
2491
+ var selectNodeForward = () => ({ state, dispatch }) => {
2492
+ return selectNodeForward$1(state, dispatch);
2493
+ };
2494
+ var selectParentNode = () => ({ state, dispatch }) => {
2495
+ return selectParentNode$1(state, dispatch);
2496
+ };
2497
+ var selectTextblockEnd = () => ({ state, dispatch }) => {
2498
+ return selectTextblockEnd$1(state, dispatch);
2499
+ };
2500
+ var selectTextblockStart = () => ({ state, dispatch }) => {
2501
+ return selectTextblockStart$1(state, dispatch);
2502
+ };
2503
+ function createDocument(content, schema, parseOptions = {}, options = {}) {
2504
+ return createNodeFromContent(content, schema, {
2505
+ slice: false,
2506
+ parseOptions,
2507
+ errorOnInvalidContent: options.errorOnInvalidContent
2508
+ });
2509
+ }
2510
+ var setContent = (content, { errorOnInvalidContent, emitUpdate = true, parseOptions = {} } = {}) => ({ editor, tr, dispatch, commands }) => {
2511
+ const { doc } = tr;
2512
+ if (parseOptions.preserveWhitespace !== "full") {
2513
+ const document2 = createDocument(content, editor.schema, parseOptions, {
2514
+ errorOnInvalidContent: errorOnInvalidContent != null ? errorOnInvalidContent : editor.options.enableContentCheck
2515
+ });
2516
+ if (dispatch) {
2517
+ tr.replaceWith(0, doc.content.size, document2).setMeta("preventUpdate", !emitUpdate);
2518
+ }
2519
+ return true;
2520
+ }
2521
+ if (dispatch) {
2522
+ tr.setMeta("preventUpdate", !emitUpdate);
2523
+ }
2524
+ return commands.insertContentAt({ from: 0, to: doc.content.size }, content, {
2525
+ parseOptions,
2526
+ errorOnInvalidContent: errorOnInvalidContent != null ? errorOnInvalidContent : editor.options.enableContentCheck
2527
+ });
2528
+ };
2529
+ function getMarkAttributes(state, typeOrName) {
2530
+ const type = getMarkType(typeOrName, state.schema);
2531
+ const { from, to, empty } = state.selection;
2532
+ const marks = [];
2533
+ if (empty) {
2534
+ if (state.storedMarks) {
2535
+ marks.push(...state.storedMarks);
2536
+ }
2537
+ marks.push(...state.selection.$head.marks());
2538
+ } else {
2539
+ state.doc.nodesBetween(from, to, (node) => {
2540
+ marks.push(...node.marks);
2541
+ });
2542
+ }
2543
+ const mark = marks.find((markItem) => markItem.type.name === type.name);
2544
+ if (!mark) {
2545
+ return {};
2546
+ }
2547
+ return { ...mark.attrs };
2548
+ }
2549
+ function combineTransactionSteps(oldDoc, transactions) {
2550
+ const transform = new Transform(oldDoc);
2551
+ transactions.forEach((transaction) => {
2552
+ transaction.steps.forEach((step) => {
2553
+ transform.step(step);
2554
+ });
2555
+ });
2556
+ return transform;
2557
+ }
2558
+ function defaultBlockAt(match) {
2559
+ for (let i = 0; i < match.edgeCount; i += 1) {
2560
+ const { type } = match.edge(i);
2561
+ if (type.isTextblock && !type.hasRequiredAttrs()) {
2562
+ return type;
2563
+ }
2564
+ }
2565
+ return null;
2566
+ }
2567
+ function findParentNodeClosestToPos($pos, predicate) {
2568
+ for (let i = $pos.depth; i > 0; i -= 1) {
2569
+ const node = $pos.node(i);
2570
+ if (predicate(node)) {
2571
+ return {
2572
+ pos: i > 0 ? $pos.before(i) : 0,
2573
+ start: $pos.start(i),
2574
+ depth: i,
2575
+ node
2576
+ };
2577
+ }
2578
+ }
2579
+ }
2580
+ function findParentNode(predicate) {
2581
+ return (selection) => findParentNodeClosestToPos(selection.$from, predicate);
2582
+ }
2583
+ function getExtensionField(extension, field, context) {
2584
+ if (extension.config[field] === void 0 && extension.parent) {
2585
+ return getExtensionField(extension.parent, field, context);
2586
+ }
2587
+ if (typeof extension.config[field] === "function") {
2588
+ const value = extension.config[field].bind({
2589
+ ...context,
2590
+ parent: extension.parent ? getExtensionField(extension.parent, field, context) : null
2591
+ });
2592
+ return value;
2593
+ }
2594
+ return extension.config[field];
2595
+ }
2596
+ function isFunction(value) {
2597
+ return typeof value === "function";
2598
+ }
2599
+ function callOrReturn(value, context = void 0, ...props) {
2600
+ if (isFunction(value)) {
2601
+ if (context) {
2602
+ return value.bind(context)(...props);
2603
+ }
2604
+ return value(...props);
2605
+ }
2606
+ return value;
2607
+ }
2608
+ function splitExtensions(extensions) {
2609
+ const baseExtensions = extensions.filter(
2610
+ (extension) => extension.type === "extension"
2611
+ );
2612
+ const nodeExtensions = extensions.filter((extension) => extension.type === "node");
2613
+ const markExtensions = extensions.filter((extension) => extension.type === "mark");
2614
+ return {
2615
+ baseExtensions,
2616
+ nodeExtensions,
2617
+ markExtensions
2618
+ };
2619
+ }
2620
+ function splitStyleDeclarations(styles) {
2621
+ const result = [];
2622
+ let current = "";
2623
+ let inSingleQuote = false;
2624
+ let inDoubleQuote = false;
2625
+ let parenDepth = 0;
2626
+ const length = styles.length;
2627
+ for (let i = 0; i < length; i += 1) {
2628
+ const char = styles[i];
2629
+ if (char === "'" && !inDoubleQuote) {
2630
+ inSingleQuote = !inSingleQuote;
2631
+ current += char;
2632
+ continue;
2633
+ }
2634
+ if (char === '"' && !inSingleQuote) {
2635
+ inDoubleQuote = !inDoubleQuote;
2636
+ current += char;
2637
+ continue;
2638
+ }
2639
+ if (!inSingleQuote && !inDoubleQuote) {
2640
+ if (char === "(") {
2641
+ parenDepth += 1;
2642
+ current += char;
2643
+ continue;
2644
+ }
2645
+ if (char === ")" && parenDepth > 0) {
2646
+ parenDepth -= 1;
2647
+ current += char;
2648
+ continue;
2649
+ }
2650
+ if (char === ";" && parenDepth === 0) {
2651
+ result.push(current);
2652
+ current = "";
2653
+ continue;
2654
+ }
2655
+ }
2656
+ current += char;
2657
+ }
2658
+ if (current) {
2659
+ result.push(current);
2660
+ }
2661
+ return result;
2662
+ }
2663
+ function parseStyleEntries(styles) {
2664
+ const pairs = [];
2665
+ const declarations = splitStyleDeclarations(styles || "");
2666
+ const numDeclarations = declarations.length;
2667
+ for (let i = 0; i < numDeclarations; i += 1) {
2668
+ const declaration = declarations[i];
2669
+ const firstColonIndex = declaration.indexOf(":");
2670
+ if (firstColonIndex === -1) {
2671
+ continue;
2672
+ }
2673
+ const property = declaration.slice(0, firstColonIndex).trim();
2674
+ const value = declaration.slice(firstColonIndex + 1).trim();
2675
+ if (property && value) {
2676
+ pairs.push([property, value]);
2677
+ }
2678
+ }
2679
+ return pairs;
2680
+ }
2681
+ function mergeAttributes(...objects) {
2682
+ return objects.filter((item) => !!item).reduce((items, item) => {
2683
+ const mergedAttributes = { ...items };
2684
+ Object.entries(item).forEach(([key, value]) => {
2685
+ const exists = mergedAttributes[key];
2686
+ if (!exists) {
2687
+ mergedAttributes[key] = value;
2688
+ return;
2689
+ }
2690
+ if (key === "class") {
2691
+ const valueClasses = value ? String(value).split(" ") : [];
2692
+ const existingClasses = mergedAttributes[key] ? mergedAttributes[key].split(" ") : [];
2693
+ const insertClasses = valueClasses.filter(
2694
+ (valueClass) => !existingClasses.includes(valueClass)
2695
+ );
2696
+ mergedAttributes[key] = [...existingClasses, ...insertClasses].join(" ");
2697
+ } else if (key === "style") {
2698
+ const styleMap = new Map([
2699
+ ...parseStyleEntries(mergedAttributes[key]),
2700
+ ...parseStyleEntries(value)
2701
+ ]);
2702
+ mergedAttributes[key] = Array.from(styleMap.entries()).map(([property, val]) => `${property}: ${val}`).join("; ");
2703
+ } else {
2704
+ mergedAttributes[key] = value;
2705
+ }
2706
+ });
2707
+ return mergedAttributes;
2708
+ }, {});
2709
+ }
2710
+ function getTextBetween(startNode, range, options) {
2711
+ const { from, to } = range;
2712
+ const { blockSeparator = "\n\n", textSerializers = {} } = options || {};
2713
+ let text = "";
2714
+ startNode.nodesBetween(from, to, (node, pos, parent, index) => {
2715
+ var _a;
2716
+ if (node.isBlock && pos > from) {
2717
+ text += blockSeparator;
2718
+ }
2719
+ const textSerializer = textSerializers == null ? void 0 : textSerializers[node.type.name];
2720
+ if (textSerializer) {
2721
+ if (parent) {
2722
+ text += textSerializer({
2723
+ node,
2724
+ pos,
2725
+ parent,
2726
+ index,
2727
+ range
2728
+ });
2729
+ }
2730
+ return false;
2731
+ }
2732
+ if (node.isText) {
2733
+ text += (_a = node == null ? void 0 : node.text) == null ? void 0 : _a.slice(Math.max(from, pos) - pos, to - pos);
2734
+ }
2735
+ });
2736
+ return text;
2737
+ }
2738
+ function getTextSerializersFromSchema(schema) {
2739
+ return Object.fromEntries(
2740
+ Object.entries(schema.nodes).filter(([, node]) => node.spec.toText).map(([name, node]) => [name, node.spec.toText])
2741
+ );
2742
+ }
2743
+ function removeDuplicates(array, by = JSON.stringify) {
2744
+ const seen = {};
2745
+ return array.filter((item) => {
2746
+ const key = by(item);
2747
+ return Object.prototype.hasOwnProperty.call(seen, key) ? false : seen[key] = true;
2748
+ });
2749
+ }
2750
+ function simplifyChangedRanges(changes) {
2751
+ const uniqueChanges = removeDuplicates(changes);
2752
+ return uniqueChanges.length === 1 ? uniqueChanges : uniqueChanges.filter((change, index) => {
2753
+ const rest = uniqueChanges.filter((_, i) => i !== index);
2754
+ return !rest.some((otherChange) => {
2755
+ return change.oldRange.from >= otherChange.oldRange.from && change.oldRange.to <= otherChange.oldRange.to && change.newRange.from >= otherChange.newRange.from && change.newRange.to <= otherChange.newRange.to;
2756
+ });
2757
+ });
2758
+ }
2759
+ function getChangedRanges(transform) {
2760
+ const { mapping, steps } = transform;
2761
+ const changes = [];
2762
+ mapping.maps.forEach((stepMap, index) => {
2763
+ const ranges = [];
2764
+ if (!stepMap.ranges.length) {
2765
+ const { from, to } = steps[index];
2766
+ if (from === void 0 || to === void 0) {
2767
+ return;
2768
+ }
2769
+ ranges.push({ from, to });
2770
+ } else {
2771
+ stepMap.forEach((from, to) => {
2772
+ ranges.push({ from, to });
2773
+ });
2774
+ }
2775
+ ranges.forEach(({ from, to }) => {
2776
+ const newStart = mapping.slice(index).map(from, -1);
2777
+ const newEnd = mapping.slice(index).map(to);
2778
+ const oldStart = mapping.invert().map(newStart, -1);
2779
+ const oldEnd = mapping.invert().map(newEnd);
2780
+ changes.push({
2781
+ oldRange: {
2782
+ from: oldStart,
2783
+ to: oldEnd
2784
+ },
2785
+ newRange: {
2786
+ from: newStart,
2787
+ to: newEnd
2788
+ }
2789
+ });
2790
+ });
2791
+ });
2792
+ return simplifyChangedRanges(changes);
2793
+ }
2794
+ function getSplittedAttributes(extensionAttributes, typeName, attributes) {
2795
+ return Object.fromEntries(
2796
+ Object.entries(attributes).filter(([name]) => {
2797
+ const extensionAttribute = extensionAttributes.find((item) => {
2798
+ return item.type === typeName && item.name === name;
2799
+ });
2800
+ if (!extensionAttribute) {
2801
+ return false;
2802
+ }
2803
+ return extensionAttribute.attribute.keepOnSplit;
2804
+ })
2805
+ );
2806
+ }
2807
+ function isMarkActive(state, typeOrName, attributes = {}) {
2808
+ const { empty, ranges } = state.selection;
2809
+ const type = typeOrName ? getMarkType(typeOrName, state.schema) : null;
2810
+ if (empty) {
2811
+ return !!(state.storedMarks || state.selection.$from.marks()).filter((mark) => {
2812
+ if (!type) {
2813
+ return true;
2814
+ }
2815
+ return type.name === mark.type.name;
2816
+ }).find((mark) => objectIncludes(mark.attrs, attributes, { strict: false }));
2817
+ }
2818
+ let selectionRange = 0;
2819
+ const markRanges = [];
2820
+ ranges.forEach(({ $from, $to }) => {
2821
+ const from = $from.pos;
2822
+ const to = $to.pos;
2823
+ state.doc.nodesBetween(from, to, (node, pos) => {
2824
+ if (type && node.inlineContent && !node.type.allowsMarkType(type)) {
2825
+ return false;
2826
+ }
2827
+ if (!node.isText && !node.marks.length) {
2828
+ return;
2829
+ }
2830
+ const relativeFrom = Math.max(from, pos);
2831
+ const relativeTo = Math.min(to, pos + node.nodeSize);
2832
+ const range2 = relativeTo - relativeFrom;
2833
+ selectionRange += range2;
2834
+ markRanges.push(
2835
+ ...node.marks.map((mark) => ({
2836
+ mark,
2837
+ from: relativeFrom,
2838
+ to: relativeTo
2839
+ }))
2840
+ );
2841
+ });
2842
+ });
2843
+ if (selectionRange === 0) {
2844
+ return false;
2845
+ }
2846
+ const matchedRange = markRanges.filter((markRange) => {
2847
+ if (!type) {
2848
+ return true;
2849
+ }
2850
+ return type.name === markRange.mark.type.name;
2851
+ }).filter((markRange) => objectIncludes(markRange.mark.attrs, attributes, { strict: false })).reduce((sum, markRange) => sum + markRange.to - markRange.from, 0);
2852
+ const excludedRange = markRanges.filter((markRange) => {
2853
+ if (!type) {
2854
+ return true;
2855
+ }
2856
+ return markRange.mark.type !== type && markRange.mark.type.excludes(type);
2857
+ }).reduce((sum, markRange) => sum + markRange.to - markRange.from, 0);
2858
+ const range = matchedRange > 0 ? matchedRange + excludedRange : matchedRange;
2859
+ return range >= selectionRange;
2860
+ }
2861
+ function isList(name, extensions) {
2862
+ const { nodeExtensions } = splitExtensions(extensions);
2863
+ const extension = nodeExtensions.find((item) => item.name === name);
2864
+ if (!extension) {
2865
+ return false;
2866
+ }
2867
+ const context = {
2868
+ name: extension.name,
2869
+ options: extension.options,
2870
+ storage: extension.storage
2871
+ };
2872
+ const group = callOrReturn(getExtensionField(extension, "group", context));
2873
+ if (typeof group !== "string") {
2874
+ return false;
2875
+ }
2876
+ return group.split(" ").includes("list");
2877
+ }
2878
+ function isNodeEmpty(node, {
2879
+ checkChildren = true,
2880
+ ignoreWhitespace = false
2881
+ } = {}) {
2882
+ var _a;
2883
+ if (ignoreWhitespace) {
2884
+ if (node.type.name === "hardBreak") {
2885
+ return true;
2886
+ }
2887
+ if (node.isText) {
2888
+ return !/\S/.test((_a = node.text) != null ? _a : "");
2889
+ }
2890
+ }
2891
+ if (node.isText) {
2892
+ return !node.text;
2893
+ }
2894
+ if (node.isAtom || node.isLeaf) {
2895
+ return false;
2896
+ }
2897
+ if (node.content.childCount === 0) {
2898
+ return true;
2899
+ }
2900
+ if (checkChildren) {
2901
+ let isContentEmpty = true;
2902
+ node.content.forEach((childNode) => {
2903
+ if (isContentEmpty === false) {
2904
+ return;
2905
+ }
2906
+ if (!isNodeEmpty(childNode, { ignoreWhitespace, checkChildren })) {
2907
+ isContentEmpty = false;
2908
+ }
2909
+ });
2910
+ return isContentEmpty;
2911
+ }
2912
+ return false;
2913
+ }
2914
+ function canSetMark(state, tr, newMarkType) {
2915
+ var _a;
2916
+ const { selection } = tr;
2917
+ let cursor = null;
2918
+ if (isTextSelection(selection)) {
2919
+ cursor = selection.$cursor;
2920
+ }
2921
+ if (cursor) {
2922
+ const currentMarks = (_a = state.storedMarks) != null ? _a : cursor.marks();
2923
+ const parentAllowsMarkType = cursor.parent.type.allowsMarkType(newMarkType);
2924
+ return parentAllowsMarkType && (!!newMarkType.isInSet(currentMarks) || !currentMarks.some((mark) => mark.type.excludes(newMarkType)));
2925
+ }
2926
+ const { ranges } = selection;
2927
+ return ranges.some(({ $from, $to }) => {
2928
+ let someNodeSupportsMark = $from.depth === 0 ? state.doc.inlineContent && state.doc.type.allowsMarkType(newMarkType) : false;
2929
+ state.doc.nodesBetween($from.pos, $to.pos, (node, _pos, parent) => {
2930
+ if (someNodeSupportsMark) {
2931
+ return false;
2932
+ }
2933
+ if (node.isInline) {
2934
+ const parentAllowsMarkType = !parent || parent.type.allowsMarkType(newMarkType);
2935
+ const currentMarksAllowMarkType = !!newMarkType.isInSet(node.marks) || !node.marks.some((otherMark) => otherMark.type.excludes(newMarkType));
2936
+ someNodeSupportsMark = parentAllowsMarkType && currentMarksAllowMarkType;
2937
+ }
2938
+ return !someNodeSupportsMark;
2939
+ });
2940
+ return someNodeSupportsMark;
2941
+ });
2942
+ }
2943
+ var setMark = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
2944
+ const { selection } = tr;
2945
+ const { empty, ranges } = selection;
2946
+ const type = getMarkType(typeOrName, state.schema);
2947
+ if (dispatch) {
2948
+ if (empty) {
2949
+ const oldAttributes = getMarkAttributes(state, type);
2950
+ tr.addStoredMark(
2951
+ type.create({
2952
+ ...oldAttributes,
2953
+ ...attributes
2954
+ })
2955
+ );
2956
+ } else {
2957
+ ranges.forEach((range) => {
2958
+ const from = range.$from.pos;
2959
+ const to = range.$to.pos;
2960
+ state.doc.nodesBetween(from, to, (node, pos) => {
2961
+ const trimmedFrom = Math.max(pos, from);
2962
+ const trimmedTo = Math.min(pos + node.nodeSize, to);
2963
+ const someHasMark = node.marks.find((mark) => mark.type === type);
2964
+ if (someHasMark) {
2965
+ node.marks.forEach((mark) => {
2966
+ if (type === mark.type) {
2967
+ tr.addMark(
2968
+ trimmedFrom,
2969
+ trimmedTo,
2970
+ type.create({
2971
+ ...mark.attrs,
2972
+ ...attributes
2973
+ })
2974
+ );
2975
+ }
2976
+ });
2977
+ } else {
2978
+ tr.addMark(trimmedFrom, trimmedTo, type.create(attributes));
2979
+ }
2980
+ });
2981
+ });
2982
+ }
2983
+ }
2984
+ return canSetMark(state, tr, type);
2985
+ };
2986
+ var setMeta = (key, value) => ({ tr }) => {
2987
+ tr.setMeta(key, value);
2988
+ return true;
2989
+ };
2990
+ var setNode = (typeOrName, attributes = {}) => ({ state, dispatch, chain }) => {
2991
+ const type = getNodeType(typeOrName, state.schema);
2992
+ let attributesToCopy;
2993
+ if (state.selection.$anchor.sameParent(state.selection.$head)) {
2994
+ attributesToCopy = state.selection.$anchor.parent.attrs;
2995
+ }
2996
+ if (!type.isTextblock) {
2997
+ console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.');
2998
+ return false;
2999
+ }
3000
+ return chain().command(({ commands }) => {
3001
+ const canSetBlock = setBlockType(type, { ...attributesToCopy, ...attributes })(state);
3002
+ if (canSetBlock) {
3003
+ return true;
3004
+ }
3005
+ return commands.clearNodes();
3006
+ }).command(({ state: updatedState }) => {
3007
+ return setBlockType(type, { ...attributesToCopy, ...attributes })(updatedState, dispatch);
3008
+ }).run();
3009
+ };
3010
+ var setNodeSelection = (position) => ({ tr, dispatch }) => {
3011
+ if (dispatch) {
3012
+ const { doc } = tr;
3013
+ const from = minMax(position, 0, doc.content.size);
3014
+ const selection = NodeSelection.create(doc, from);
3015
+ tr.setSelection(selection);
3016
+ }
3017
+ return true;
3018
+ };
3019
+ var setTextDirection = (direction, position) => ({ tr, state, dispatch }) => {
3020
+ const { selection } = state;
3021
+ let from;
3022
+ let to;
3023
+ if (typeof position === "number") {
3024
+ from = position;
3025
+ to = position;
3026
+ } else if (position && "from" in position && "to" in position) {
3027
+ from = position.from;
3028
+ to = position.to;
3029
+ } else {
3030
+ from = selection.from;
3031
+ to = selection.to;
3032
+ }
3033
+ if (dispatch) {
3034
+ tr.doc.nodesBetween(from, to, (node, pos) => {
3035
+ if (node.isText) {
3036
+ return;
3037
+ }
3038
+ tr.setNodeMarkup(pos, void 0, {
3039
+ ...node.attrs,
3040
+ dir: direction
3041
+ });
3042
+ });
3043
+ }
3044
+ return true;
3045
+ };
3046
+ var setTextSelection = (position) => ({ tr, dispatch }) => {
3047
+ if (dispatch) {
3048
+ const { doc } = tr;
3049
+ const { from, to } = typeof position === "number" ? { from: position, to: position } : position;
3050
+ const minPos = TextSelection.atStart(doc).from;
3051
+ const maxPos = TextSelection.atEnd(doc).to;
3052
+ const resolvedFrom = minMax(from, minPos, maxPos);
3053
+ const resolvedEnd = minMax(to, minPos, maxPos);
3054
+ const selection = TextSelection.create(doc, resolvedFrom, resolvedEnd);
3055
+ tr.setSelection(selection);
3056
+ }
3057
+ return true;
3058
+ };
3059
+ var sinkListItem = (typeOrName) => ({ state, dispatch }) => {
3060
+ const type = getNodeType(typeOrName, state.schema);
3061
+ return sinkListItem$1(type)(state, dispatch);
3062
+ };
3063
+ function ensureMarks(state, splittableMarks) {
3064
+ const marks = state.storedMarks || state.selection.$to.parentOffset && state.selection.$from.marks();
3065
+ if (marks) {
3066
+ const filteredMarks = marks.filter((mark) => splittableMarks == null ? void 0 : splittableMarks.includes(mark.type.name));
3067
+ state.tr.ensureMarks(filteredMarks);
3068
+ }
3069
+ }
3070
+ var splitBlock = ({ keepMarks = true } = {}) => ({ tr, state, dispatch, editor }) => {
3071
+ const { selection, doc } = tr;
3072
+ const { $from, $to } = selection;
3073
+ const extensionAttributes = editor.extensionManager.attributes;
3074
+ const newAttributes = getSplittedAttributes(
3075
+ extensionAttributes,
3076
+ $from.node().type.name,
3077
+ $from.node().attrs
3078
+ );
3079
+ if (selection instanceof NodeSelection && selection.node.isBlock) {
3080
+ if (!$from.parentOffset || !canSplit(doc, $from.pos)) {
3081
+ return false;
3082
+ }
3083
+ if (dispatch) {
3084
+ if (keepMarks) {
3085
+ ensureMarks(state, editor.extensionManager.splittableMarks);
3086
+ }
3087
+ tr.split($from.pos).scrollIntoView();
3088
+ }
3089
+ return true;
3090
+ }
3091
+ if (!$from.parent.isBlock) {
3092
+ return false;
3093
+ }
3094
+ const atEnd = $to.parentOffset === $to.parent.content.size;
3095
+ const deflt = $from.depth === 0 ? void 0 : defaultBlockAt($from.node(-1).contentMatchAt($from.indexAfter(-1)));
3096
+ let types = atEnd && deflt ? [
3097
+ {
3098
+ type: deflt,
3099
+ attrs: newAttributes
3100
+ }
3101
+ ] : void 0;
3102
+ let can = canSplit(tr.doc, tr.mapping.map($from.pos), 1, types);
3103
+ if (!types && !can && canSplit(tr.doc, tr.mapping.map($from.pos), 1, deflt ? [{ type: deflt }] : void 0)) {
3104
+ can = true;
3105
+ types = deflt ? [
3106
+ {
3107
+ type: deflt,
3108
+ attrs: newAttributes
3109
+ }
3110
+ ] : void 0;
3111
+ }
3112
+ if (dispatch) {
3113
+ if (can) {
3114
+ if (selection instanceof TextSelection) {
3115
+ tr.deleteSelection();
3116
+ }
3117
+ tr.split(tr.mapping.map($from.pos), 1, types);
3118
+ if (deflt && !atEnd && !$from.parentOffset && $from.parent.type !== deflt) {
3119
+ const first2 = tr.mapping.map($from.before());
3120
+ const $first = tr.doc.resolve(first2);
3121
+ if ($from.node(-1).canReplaceWith($first.index(), $first.index() + 1, deflt)) {
3122
+ tr.setNodeMarkup(tr.mapping.map($from.before()), deflt);
3123
+ }
3124
+ }
3125
+ }
3126
+ if (keepMarks) {
3127
+ ensureMarks(state, editor.extensionManager.splittableMarks);
3128
+ }
3129
+ tr.scrollIntoView();
3130
+ }
3131
+ return can;
3132
+ };
3133
+ var splitListItem = (typeOrName, overrideAttrs = {}) => ({ tr, state, dispatch, editor }) => {
3134
+ var _a;
3135
+ const type = getNodeType(typeOrName, state.schema);
3136
+ const { $from, $to } = state.selection;
3137
+ const node = state.selection.node;
3138
+ if (node && node.isBlock || $from.depth < 2 || !$from.sameParent($to)) {
3139
+ return false;
3140
+ }
3141
+ const grandParent = $from.node(-1);
3142
+ if (grandParent.type !== type) {
3143
+ return false;
3144
+ }
3145
+ const extensionAttributes = editor.extensionManager.attributes;
3146
+ if ($from.parent.content.size === 0 && $from.node(-1).childCount === $from.indexAfter(-1)) {
3147
+ if ($from.depth === 2 || $from.node(-3).type !== type || $from.index(-2) !== $from.node(-2).childCount - 1) {
3148
+ return false;
3149
+ }
3150
+ if (dispatch) {
3151
+ let wrap = Fragment.empty;
3152
+ const depthBefore = $from.index(-1) ? 1 : $from.index(-2) ? 2 : 3;
3153
+ for (let d = $from.depth - depthBefore; d >= $from.depth - 3; d -= 1) {
3154
+ wrap = Fragment.from($from.node(d).copy(wrap));
3155
+ }
3156
+ const depthAfter = (
3157
+ // oxlint-disable-next-line no-nested-ternary
3158
+ $from.indexAfter(-1) < $from.node(-2).childCount ? 1 : $from.indexAfter(-2) < $from.node(-3).childCount ? 2 : 3
3159
+ );
3160
+ const newNextTypeAttributes2 = {
3161
+ ...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),
3162
+ ...overrideAttrs
3163
+ };
3164
+ const nextType2 = ((_a = type.contentMatch.defaultType) == null ? void 0 : _a.createAndFill(newNextTypeAttributes2)) || void 0;
3165
+ wrap = wrap.append(Fragment.from(type.createAndFill(null, nextType2) || void 0));
3166
+ const start = $from.before($from.depth - (depthBefore - 1));
3167
+ tr.replace(start, $from.after(-depthAfter), new Slice(wrap, 4 - depthBefore, 0));
3168
+ let sel = -1;
3169
+ tr.doc.nodesBetween(start, tr.doc.content.size, (n, pos) => {
3170
+ if (sel > -1) {
3171
+ return false;
3172
+ }
3173
+ if (n.isTextblock && n.content.size === 0) {
3174
+ sel = pos + 1;
3175
+ }
3176
+ });
3177
+ if (sel > -1) {
3178
+ tr.setSelection(TextSelection.near(tr.doc.resolve(sel)));
3179
+ }
3180
+ tr.scrollIntoView();
3181
+ }
3182
+ return true;
3183
+ }
3184
+ const nextType = $to.pos === $from.end() ? grandParent.contentMatchAt(0).defaultType : null;
3185
+ const newTypeAttributes = {
3186
+ ...getSplittedAttributes(extensionAttributes, grandParent.type.name, grandParent.attrs),
3187
+ ...overrideAttrs
3188
+ };
3189
+ const newNextTypeAttributes = {
3190
+ ...getSplittedAttributes(extensionAttributes, $from.node().type.name, $from.node().attrs),
3191
+ ...overrideAttrs
3192
+ };
3193
+ tr.delete($from.pos, $to.pos);
3194
+ const types = nextType ? [
3195
+ { type, attrs: newTypeAttributes },
3196
+ { type: nextType, attrs: newNextTypeAttributes }
3197
+ ] : [{ type, attrs: newTypeAttributes }];
3198
+ if (!canSplit(tr.doc, $from.pos, 2)) {
3199
+ return false;
3200
+ }
3201
+ if (dispatch) {
3202
+ const { selection, storedMarks } = state;
3203
+ const { splittableMarks } = editor.extensionManager;
3204
+ const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks();
3205
+ tr.split($from.pos, 2, types).scrollIntoView();
3206
+ if (!marks || !dispatch) {
3207
+ return true;
3208
+ }
3209
+ const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name));
3210
+ tr.ensureMarks(filteredMarks);
3211
+ }
3212
+ return true;
3213
+ };
3214
+ var joinListBackwards = (tr, listType) => {
3215
+ const list = findParentNode((node) => node.type === listType)(tr.selection);
3216
+ if (!list) {
3217
+ return true;
3218
+ }
3219
+ const before = tr.doc.resolve(Math.max(0, list.pos - 1)).before(list.depth);
3220
+ if (before === void 0) {
3221
+ return true;
3222
+ }
3223
+ const nodeBefore = tr.doc.nodeAt(before);
3224
+ const canJoinBackwards = list.node.type === (nodeBefore == null ? void 0 : nodeBefore.type) && canJoin(tr.doc, list.pos);
3225
+ if (!canJoinBackwards) {
3226
+ return true;
3227
+ }
3228
+ tr.join(list.pos);
3229
+ return true;
3230
+ };
3231
+ var joinListForwards = (tr, listType) => {
3232
+ const list = findParentNode((node) => node.type === listType)(tr.selection);
3233
+ if (!list) {
3234
+ return true;
3235
+ }
3236
+ const after = tr.doc.resolve(list.start).after(list.depth);
3237
+ if (after === void 0) {
3238
+ return true;
3239
+ }
3240
+ const nodeAfter = tr.doc.nodeAt(after);
3241
+ const canJoinForwards = list.node.type === (nodeAfter == null ? void 0 : nodeAfter.type) && canJoin(tr.doc, after);
3242
+ if (!canJoinForwards) {
3243
+ return true;
3244
+ }
3245
+ tr.join(after);
3246
+ return true;
3247
+ };
3248
+ function createInnerSelectionForWholeDocList(tr) {
3249
+ const doc = tr.doc;
3250
+ const list = doc.firstChild;
3251
+ if (!list) {
3252
+ return null;
3253
+ }
3254
+ const $start = doc.resolve(1);
3255
+ const $end = doc.resolve(list.nodeSize - 1);
3256
+ return TextSelection.between($start, $end);
3257
+ }
3258
+ var toggleList = (listTypeOrName, itemTypeOrName, keepMarks, attributes = {}) => ({ editor, tr, state, dispatch, chain, commands, can }) => {
3259
+ const { extensions, splittableMarks } = editor.extensionManager;
3260
+ const listType = getNodeType(listTypeOrName, state.schema);
3261
+ const itemType = getNodeType(itemTypeOrName, state.schema);
3262
+ const { selection, storedMarks } = state;
3263
+ const { $from, $to } = selection;
3264
+ const range = $from.blockRange($to);
3265
+ const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks();
3266
+ if (!range) {
3267
+ return false;
3268
+ }
3269
+ const parentList = findParentNode((node) => isList(node.type.name, extensions))(selection);
3270
+ const isAllSelection = selection.from === 0 && selection.to === state.doc.content.size;
3271
+ const topLevelNodes = state.doc.content.content;
3272
+ const soleTopLevelNode = topLevelNodes.length === 1 ? topLevelNodes[0] : null;
3273
+ const allSelectionList = isAllSelection && soleTopLevelNode && isList(soleTopLevelNode.type.name, extensions) ? {
3274
+ node: soleTopLevelNode,
3275
+ pos: 0} : null;
3276
+ const currentList = parentList != null ? parentList : allSelectionList;
3277
+ const isInsideExistingList = !!parentList && range.depth >= 1 && range.depth - parentList.depth <= 1;
3278
+ const hasWholeDocSelectedList = !!allSelectionList;
3279
+ if ((isInsideExistingList || hasWholeDocSelectedList) && currentList) {
3280
+ if (currentList.node.type === listType) {
3281
+ if (isAllSelection && hasWholeDocSelectedList) {
3282
+ return chain().command(({ tr: trx, dispatch: disp }) => {
3283
+ const nextSelection = createInnerSelectionForWholeDocList(trx);
3284
+ if (!nextSelection) {
3285
+ return false;
3286
+ }
3287
+ trx.setSelection(nextSelection);
3288
+ if (disp) {
3289
+ disp(trx);
3290
+ }
3291
+ return true;
3292
+ }).liftListItem(itemType).run();
3293
+ }
3294
+ return commands.liftListItem(itemType);
3295
+ }
3296
+ if (isList(currentList.node.type.name, extensions) && listType.validContent(currentList.node.content)) {
3297
+ return chain().command(() => {
3298
+ tr.setNodeMarkup(currentList.pos, listType);
3299
+ return true;
3300
+ }).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
3301
+ }
3302
+ }
3303
+ if (!keepMarks || !marks || !dispatch) {
3304
+ return chain().command(() => {
3305
+ const canWrapInList = can().wrapInList(listType, attributes);
3306
+ if (canWrapInList) {
3307
+ return true;
3308
+ }
3309
+ return commands.clearNodes();
3310
+ }).wrapInList(listType, attributes).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
3311
+ }
3312
+ return chain().command(() => {
3313
+ const canWrapInList = can().wrapInList(listType, attributes);
3314
+ const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name));
3315
+ tr.ensureMarks(filteredMarks);
3316
+ if (canWrapInList) {
3317
+ return true;
3318
+ }
3319
+ return commands.clearNodes();
3320
+ }).wrapInList(listType, attributes).command(() => joinListBackwards(tr, listType)).command(() => joinListForwards(tr, listType)).run();
3321
+ };
3322
+ var toggleMark = (typeOrName, attributes = {}, options = {}) => ({ state, commands }) => {
3323
+ const { extendEmptyMarkRange = false } = options;
3324
+ const type = getMarkType(typeOrName, state.schema);
3325
+ const isActive2 = isMarkActive(state, type, attributes);
3326
+ if (isActive2) {
3327
+ return commands.unsetMark(type, { extendEmptyMarkRange });
3328
+ }
3329
+ return commands.setMark(type, attributes);
3330
+ };
3331
+ var toggleNode = (typeOrName, toggleTypeOrName, attributes = {}) => ({ state, commands }) => {
3332
+ const type = getNodeType(typeOrName, state.schema);
3333
+ const toggleType = getNodeType(toggleTypeOrName, state.schema);
3334
+ const isActive2 = isNodeActive(state, type, attributes);
3335
+ let attributesToCopy;
3336
+ if (state.selection.$anchor.sameParent(state.selection.$head)) {
3337
+ attributesToCopy = state.selection.$anchor.parent.attrs;
3338
+ }
3339
+ if (isActive2) {
3340
+ return commands.setNode(toggleType, attributesToCopy);
3341
+ }
3342
+ return commands.setNode(type, { ...attributesToCopy, ...attributes });
3343
+ };
3344
+ var toggleWrap = (typeOrName, attributes = {}) => ({ state, commands }) => {
3345
+ const type = getNodeType(typeOrName, state.schema);
3346
+ const isActive2 = isNodeActive(state, type, attributes);
3347
+ if (isActive2) {
3348
+ return commands.lift(type);
3349
+ }
3350
+ return commands.wrapIn(type, attributes);
3351
+ };
3352
+ var undoInputRule = () => ({ state, dispatch }) => {
3353
+ const plugins = state.plugins;
3354
+ for (let i = 0; i < plugins.length; i += 1) {
3355
+ const plugin = plugins[i];
3356
+ let undoable;
3357
+ if (plugin.spec.isInputRules && (undoable = plugin.getState(state))) {
3358
+ if (dispatch) {
3359
+ const tr = state.tr;
3360
+ const toUndo = undoable.transform;
3361
+ for (let j = toUndo.steps.length - 1; j >= 0; j -= 1) {
3362
+ tr.step(toUndo.steps[j].invert(toUndo.docs[j]));
3363
+ }
3364
+ if (undoable.text) {
3365
+ const marks = tr.doc.resolve(undoable.from).marks();
3366
+ tr.replaceWith(undoable.from, undoable.to, state.schema.text(undoable.text, marks));
3367
+ } else {
3368
+ tr.delete(undoable.from, undoable.to);
3369
+ }
3370
+ }
3371
+ return true;
3372
+ }
3373
+ }
3374
+ return false;
3375
+ };
3376
+ var unsetAllMarks = (options = {}) => ({ tr, dispatch, editor }) => {
3377
+ const { ignoreClearable = false } = options;
3378
+ const { selection } = tr;
3379
+ const { empty, ranges } = selection;
3380
+ if (empty) {
3381
+ return true;
3382
+ }
3383
+ const { nonClearableMarks } = editor.extensionManager;
3384
+ if (dispatch) {
3385
+ const clearableMarkTypes = Object.values(editor.schema.marks).filter(
3386
+ (markType) => ignoreClearable || !nonClearableMarks.includes(markType.name)
3387
+ );
3388
+ ranges.forEach((range) => {
3389
+ for (const markType of clearableMarkTypes) {
3390
+ tr.removeMark(range.$from.pos, range.$to.pos, markType);
3391
+ }
3392
+ });
3393
+ }
3394
+ return true;
3395
+ };
3396
+ var unsetMark = (typeOrName, options = {}) => ({ tr, state, dispatch }) => {
3397
+ var _a;
3398
+ const { extendEmptyMarkRange = false } = options;
3399
+ const { selection } = tr;
3400
+ const type = getMarkType(typeOrName, state.schema);
3401
+ const { $from, empty, ranges } = selection;
3402
+ if (!dispatch) {
3403
+ return true;
3404
+ }
3405
+ if (empty && extendEmptyMarkRange) {
3406
+ let { from, to } = selection;
3407
+ const attrs = (_a = $from.marks().find((mark) => mark.type === type)) == null ? void 0 : _a.attrs;
3408
+ const range = getMarkRange($from, type, attrs);
3409
+ if (range) {
3410
+ from = range.from;
3411
+ to = range.to;
3412
+ }
3413
+ tr.removeMark(from, to, type);
3414
+ } else {
3415
+ ranges.forEach((range) => {
3416
+ tr.removeMark(range.$from.pos, range.$to.pos, type);
3417
+ });
3418
+ }
3419
+ tr.removeStoredMark(type);
3420
+ return true;
3421
+ };
3422
+ var unsetTextDirection = (position) => ({ tr, state, dispatch }) => {
3423
+ const { selection } = state;
3424
+ let from;
3425
+ let to;
3426
+ if (typeof position === "number") {
3427
+ from = position;
3428
+ to = position;
3429
+ } else if (position && "from" in position && "to" in position) {
3430
+ from = position.from;
3431
+ to = position.to;
3432
+ } else {
3433
+ from = selection.from;
3434
+ to = selection.to;
3435
+ }
3436
+ if (dispatch) {
3437
+ tr.doc.nodesBetween(from, to, (node, pos) => {
3438
+ if (node.isText) {
3439
+ return;
3440
+ }
3441
+ const newAttrs = { ...node.attrs };
3442
+ delete newAttrs.dir;
3443
+ tr.setNodeMarkup(pos, void 0, newAttrs);
3444
+ });
3445
+ }
3446
+ return true;
3447
+ };
3448
+ var updateAttributes = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
3449
+ let nodeType = null;
3450
+ let markType = null;
3451
+ const schemaType = getSchemaTypeNameByName(
3452
+ typeof typeOrName === "string" ? typeOrName : typeOrName.name,
3453
+ state.schema
3454
+ );
3455
+ if (!schemaType) {
3456
+ return false;
3457
+ }
3458
+ if (schemaType === "node") {
3459
+ nodeType = getNodeType(typeOrName, state.schema);
3460
+ }
3461
+ if (schemaType === "mark") {
3462
+ markType = getMarkType(typeOrName, state.schema);
3463
+ }
3464
+ let canUpdate = false;
3465
+ tr.selection.ranges.forEach((range) => {
3466
+ const from = range.$from.pos;
3467
+ const to = range.$to.pos;
3468
+ let lastPos;
3469
+ let lastNode;
3470
+ let trimmedFrom;
3471
+ let trimmedTo;
3472
+ if (tr.selection.empty) {
3473
+ state.doc.nodesBetween(from, to, (node, pos) => {
3474
+ if (nodeType && nodeType === node.type) {
3475
+ canUpdate = true;
3476
+ trimmedFrom = Math.max(pos, from);
3477
+ trimmedTo = Math.min(pos + node.nodeSize, to);
3478
+ lastPos = pos;
3479
+ lastNode = node;
3480
+ }
3481
+ });
3482
+ } else {
3483
+ state.doc.nodesBetween(from, to, (node, pos) => {
3484
+ if (pos < from && nodeType && nodeType === node.type) {
3485
+ canUpdate = true;
3486
+ trimmedFrom = Math.max(pos, from);
3487
+ trimmedTo = Math.min(pos + node.nodeSize, to);
3488
+ lastPos = pos;
3489
+ lastNode = node;
3490
+ }
3491
+ if (pos >= from && pos <= to) {
3492
+ if (nodeType && nodeType === node.type) {
3493
+ canUpdate = true;
3494
+ if (dispatch) {
3495
+ tr.setNodeMarkup(pos, void 0, {
3496
+ ...node.attrs,
3497
+ ...attributes
3498
+ });
3499
+ }
3500
+ }
3501
+ if (markType && node.marks.length) {
3502
+ node.marks.forEach((mark) => {
3503
+ if (markType === mark.type) {
3504
+ canUpdate = true;
3505
+ if (dispatch) {
3506
+ const trimmedFrom2 = Math.max(pos, from);
3507
+ const trimmedTo2 = Math.min(pos + node.nodeSize, to);
3508
+ tr.addMark(
3509
+ trimmedFrom2,
3510
+ trimmedTo2,
3511
+ markType.create({
3512
+ ...mark.attrs,
3513
+ ...attributes
3514
+ })
3515
+ );
3516
+ }
3517
+ }
3518
+ });
3519
+ }
3520
+ }
3521
+ });
3522
+ }
3523
+ if (lastNode) {
3524
+ if (lastPos !== void 0 && dispatch) {
3525
+ tr.setNodeMarkup(lastPos, void 0, {
3526
+ ...lastNode.attrs,
3527
+ ...attributes
3528
+ });
3529
+ }
3530
+ if (markType && lastNode.marks.length) {
3531
+ lastNode.marks.forEach((mark) => {
3532
+ if (markType === mark.type && dispatch) {
3533
+ tr.addMark(
3534
+ trimmedFrom,
3535
+ trimmedTo,
3536
+ markType.create({
3537
+ ...mark.attrs,
3538
+ ...attributes
3539
+ })
3540
+ );
3541
+ }
3542
+ });
3543
+ }
3544
+ }
3545
+ });
3546
+ return canUpdate;
3547
+ };
3548
+ var wrapIn = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
3549
+ const type = getNodeType(typeOrName, state.schema);
3550
+ return wrapIn$1(type, attributes)(state, dispatch);
3551
+ };
3552
+ var wrapInList = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
3553
+ const type = getNodeType(typeOrName, state.schema);
3554
+ return wrapInList$1(type, attributes)(state, dispatch);
3555
+ };
3556
+ function getType(value) {
3557
+ return Object.prototype.toString.call(value).slice(8, -1);
3558
+ }
3559
+ function isPlainObject(value) {
3560
+ if (getType(value) !== "Object") {
3561
+ return false;
3562
+ }
3563
+ return value.constructor === Object && Object.getPrototypeOf(value) === Object.prototype;
3564
+ }
3565
+ function mergeDeep(target, source) {
3566
+ const output = { ...target };
3567
+ if (isPlainObject(target) && isPlainObject(source)) {
3568
+ Object.keys(source).forEach((key) => {
3569
+ if (isPlainObject(source[key]) && isPlainObject(target[key])) {
3570
+ output[key] = mergeDeep(target[key], source[key]);
3571
+ } else {
3572
+ output[key] = source[key];
3573
+ }
3574
+ });
3575
+ }
3576
+ return output;
3577
+ }
3578
+ var Extendable = class {
3579
+ constructor(config = {}) {
3580
+ this.type = "extendable";
3581
+ this.parent = null;
3582
+ this.child = null;
3583
+ this.name = "";
3584
+ this.config = {
3585
+ name: this.name
3586
+ };
3587
+ this.config = {
3588
+ ...this.config,
3589
+ ...config
3590
+ };
3591
+ this.name = this.config.name;
3592
+ }
3593
+ get options() {
3594
+ return {
3595
+ ...callOrReturn(
3596
+ getExtensionField(this, "addOptions", {
3597
+ name: this.name
3598
+ })
3599
+ )
3600
+ };
3601
+ }
3602
+ get storage() {
3603
+ return {
3604
+ ...callOrReturn(
3605
+ getExtensionField(this, "addStorage", {
3606
+ name: this.name,
3607
+ options: this.options
3608
+ })
3609
+ )
3610
+ };
3611
+ }
3612
+ configure(options = {}) {
3613
+ const extension = this.extend({
3614
+ ...this.config,
3615
+ addOptions: () => {
3616
+ return mergeDeep(this.options, options);
3617
+ }
3618
+ });
3619
+ extension.name = this.name;
3620
+ extension.parent = this.parent;
3621
+ this.child = null;
3622
+ return extension;
3623
+ }
3624
+ extend(extendedConfig = {}) {
3625
+ const extension = new this.constructor({ ...this.config, ...extendedConfig });
3626
+ extension.parent = this;
3627
+ this.child = extension;
3628
+ extension.name = "name" in extendedConfig ? extendedConfig.name : extension.parent.name;
3629
+ return extension;
3630
+ }
3631
+ };
3632
+ var Mark = class _Mark extends Extendable {
3633
+ constructor() {
3634
+ super(...arguments);
3635
+ this.type = "mark";
3636
+ }
3637
+ /**
3638
+ * Create a new Mark instance
3639
+ * @param config - Mark configuration object or a function that returns a configuration object
3640
+ */
3641
+ static create(config = {}) {
3642
+ const resolvedConfig = typeof config === "function" ? config() : config;
3643
+ return new _Mark(resolvedConfig);
3644
+ }
3645
+ static handleExit({ editor, mark }) {
3646
+ const { tr } = editor.state;
3647
+ const currentPos = editor.state.selection.$from;
3648
+ const isAtEnd = currentPos.pos === currentPos.end();
3649
+ if (isAtEnd) {
3650
+ const currentMarks = currentPos.marks();
3651
+ const isInMark = !!currentMarks.find((m) => (m == null ? void 0 : m.type.name) === mark.name);
3652
+ if (!isInMark) {
3653
+ return false;
3654
+ }
3655
+ const removeMark = currentMarks.find((m) => (m == null ? void 0 : m.type.name) === mark.name);
3656
+ if (removeMark) {
3657
+ tr.removeStoredMark(removeMark);
3658
+ }
3659
+ tr.insertText(" ", currentPos.pos);
3660
+ editor.view.dispatch(tr);
3661
+ return true;
3662
+ }
3663
+ return false;
3664
+ }
3665
+ configure(options) {
3666
+ return super.configure(options);
3667
+ }
3668
+ extend(extendedConfig) {
3669
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
3670
+ return super.extend(resolvedConfig);
3671
+ }
3672
+ };
3673
+ var extensions_exports = {};
3674
+ __export(extensions_exports, {
3675
+ ClipboardTextSerializer: () => ClipboardTextSerializer,
3676
+ Commands: () => Commands,
3677
+ Delete: () => Delete,
3678
+ Drop: () => Drop,
3679
+ Editable: () => Editable,
3680
+ FocusEvents: () => FocusEvents,
3681
+ Keymap: () => Keymap,
3682
+ Paste: () => Paste,
3683
+ Tabindex: () => Tabindex,
3684
+ TextDirection: () => TextDirection,
3685
+ focusEventsPluginKey: () => focusEventsPluginKey
3686
+ });
3687
+ var Extension = class _Extension extends Extendable {
3688
+ constructor() {
3689
+ super(...arguments);
3690
+ this.type = "extension";
3691
+ }
3692
+ /**
3693
+ * Create a new Extension instance
3694
+ * @param config - Extension configuration object or a function that returns a configuration object
3695
+ */
3696
+ static create(config = {}) {
3697
+ const resolvedConfig = typeof config === "function" ? config() : config;
3698
+ return new _Extension(resolvedConfig);
3699
+ }
3700
+ configure(options) {
3701
+ return super.configure(options);
3702
+ }
3703
+ extend(extendedConfig) {
3704
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
3705
+ return super.extend(resolvedConfig);
3706
+ }
3707
+ };
3708
+ var ClipboardTextSerializer = Extension.create({
3709
+ name: "clipboardTextSerializer",
3710
+ addOptions() {
3711
+ return {
3712
+ blockSeparator: void 0
3713
+ };
3714
+ },
3715
+ addProseMirrorPlugins() {
3716
+ return [
3717
+ new Plugin({
3718
+ key: new PluginKey("clipboardTextSerializer"),
3719
+ props: {
3720
+ clipboardTextSerializer: () => {
3721
+ const { editor } = this;
3722
+ const { state, schema } = editor;
3723
+ const { doc, selection } = state;
3724
+ const textSerializers = getTextSerializersFromSchema(schema);
3725
+ const { blockSeparator } = this.options;
3726
+ const options = {
3727
+ ...blockSeparator !== void 0 ? { blockSeparator } : {},
3728
+ textSerializers
3729
+ };
3730
+ const sortedRanges = [...selection.ranges].sort((a, b) => a.$from.pos - b.$from.pos);
3731
+ return sortedRanges.map(
3732
+ ({ $from, $to }) => getTextBetween(doc, { from: $from.pos, to: $to.pos }, options)
3733
+ ).join(blockSeparator != null ? blockSeparator : "\n\n");
3734
+ }
3735
+ }
3736
+ })
3737
+ ];
3738
+ }
3739
+ });
3740
+ var Commands = Extension.create({
3741
+ name: "commands",
3742
+ addCommands() {
3743
+ return {
3744
+ ...commands_exports
3745
+ };
3746
+ }
3747
+ });
3748
+ var Delete = Extension.create({
3749
+ name: "delete",
3750
+ onUpdate({ transaction, appendedTransactions }) {
3751
+ var _a, _b, _c;
3752
+ const callback = () => {
3753
+ var _a2, _b2, _c2, _d;
3754
+ if ((_d = (_c2 = (_b2 = (_a2 = this.editor.options.coreExtensionOptions) == null ? void 0 : _a2.delete) == null ? void 0 : _b2.filterTransaction) == null ? void 0 : _c2.call(_b2, transaction)) != null ? _d : transaction.getMeta("y-sync$")) {
3755
+ return;
3756
+ }
3757
+ const nextTransaction = combineTransactionSteps(transaction.before, [
3758
+ transaction,
3759
+ ...appendedTransactions
3760
+ ]);
3761
+ const changes = getChangedRanges(nextTransaction);
3762
+ changes.forEach((change) => {
3763
+ if (nextTransaction.mapping.mapResult(change.oldRange.from).deletedAfter && nextTransaction.mapping.mapResult(change.oldRange.to).deletedBefore) {
3764
+ nextTransaction.before.nodesBetween(
3765
+ change.oldRange.from,
3766
+ change.oldRange.to,
3767
+ (node, from) => {
3768
+ const to = from + node.nodeSize - 2;
3769
+ const isFullyWithinRange = change.oldRange.from <= from && to <= change.oldRange.to;
3770
+ this.editor.emit("delete", {
3771
+ type: "node",
3772
+ node,
3773
+ from,
3774
+ to,
3775
+ newFrom: nextTransaction.mapping.map(from),
3776
+ newTo: nextTransaction.mapping.map(to),
3777
+ deletedRange: change.oldRange,
3778
+ newRange: change.newRange,
3779
+ partial: !isFullyWithinRange,
3780
+ editor: this.editor,
3781
+ transaction,
3782
+ combinedTransform: nextTransaction
3783
+ });
3784
+ }
3785
+ );
3786
+ }
3787
+ });
3788
+ const mapping = nextTransaction.mapping;
3789
+ nextTransaction.steps.forEach((step, index) => {
3790
+ var _a3, _b3;
3791
+ if (step instanceof RemoveMarkStep) {
3792
+ const newStart = mapping.slice(index).map(step.from, -1);
3793
+ const newEnd = mapping.slice(index).map(step.to);
3794
+ const oldStart = mapping.invert().map(newStart, -1);
3795
+ const oldEnd = mapping.invert().map(newEnd);
3796
+ const foundBeforeMark = newStart > 0 ? (_a3 = nextTransaction.doc.nodeAt(newStart - 1)) == null ? void 0 : _a3.marks.some((mark) => mark.eq(step.mark)) : false;
3797
+ const foundAfterMark = (_b3 = nextTransaction.doc.nodeAt(newEnd)) == null ? void 0 : _b3.marks.some((mark) => mark.eq(step.mark));
3798
+ this.editor.emit("delete", {
3799
+ type: "mark",
3800
+ mark: step.mark,
3801
+ from: step.from,
3802
+ to: step.to,
3803
+ deletedRange: {
3804
+ from: oldStart,
3805
+ to: oldEnd
3806
+ },
3807
+ newRange: {
3808
+ from: newStart,
3809
+ to: newEnd
3810
+ },
3811
+ partial: Boolean(foundAfterMark || foundBeforeMark),
3812
+ editor: this.editor,
3813
+ transaction,
3814
+ combinedTransform: nextTransaction
3815
+ });
3816
+ }
3817
+ });
3818
+ };
3819
+ if ((_c = (_b = (_a = this.editor.options.coreExtensionOptions) == null ? void 0 : _a.delete) == null ? void 0 : _b.async) != null ? _c : true) {
3820
+ setTimeout(callback, 0);
3821
+ } else {
3822
+ callback();
3823
+ }
3824
+ }
3825
+ });
3826
+ var Drop = Extension.create({
3827
+ name: "drop",
3828
+ addProseMirrorPlugins() {
3829
+ return [
3830
+ new Plugin({
3831
+ key: new PluginKey("tiptapDrop"),
3832
+ props: {
3833
+ handleDrop: (_, e, slice, moved) => {
3834
+ this.editor.emit("drop", {
3835
+ editor: this.editor,
3836
+ event: e,
3837
+ slice,
3838
+ moved
3839
+ });
3840
+ }
3841
+ }
3842
+ })
3843
+ ];
3844
+ }
3845
+ });
3846
+ var Editable = Extension.create({
3847
+ name: "editable",
3848
+ addProseMirrorPlugins() {
3849
+ return [
3850
+ new Plugin({
3851
+ key: new PluginKey("editable"),
3852
+ props: {
3853
+ editable: () => this.editor.options.editable
3854
+ }
3855
+ })
3856
+ ];
3857
+ }
3858
+ });
3859
+ var focusEventsPluginKey = new PluginKey("focusEvents");
3860
+ var FocusEvents = Extension.create({
3861
+ name: "focusEvents",
3862
+ addProseMirrorPlugins() {
3863
+ const { editor } = this;
3864
+ return [
3865
+ new Plugin({
3866
+ key: focusEventsPluginKey,
3867
+ props: {
3868
+ handleDOMEvents: {
3869
+ focus: (view, event) => {
3870
+ editor.isFocused = true;
3871
+ const transaction = editor.state.tr.setMeta("focus", { event }).setMeta("addToHistory", false);
3872
+ view.dispatch(transaction);
3873
+ return false;
3874
+ },
3875
+ blur: (view, event) => {
3876
+ editor.isFocused = false;
3877
+ const transaction = editor.state.tr.setMeta("blur", { event }).setMeta("addToHistory", false);
3878
+ view.dispatch(transaction);
3879
+ return false;
3880
+ }
3881
+ }
3882
+ }
3883
+ })
3884
+ ];
3885
+ }
3886
+ });
3887
+ var Keymap = Extension.create({
3888
+ name: "keymap",
3889
+ addKeyboardShortcuts() {
3890
+ const handleBackspace = () => this.editor.commands.first(({ commands }) => [
3891
+ () => commands.undoInputRule(),
3892
+ // maybe convert first text block node to default node
3893
+ () => commands.command(({ tr }) => {
3894
+ const { selection, doc } = tr;
3895
+ const { empty, $anchor } = selection;
3896
+ const { pos, parent } = $anchor;
3897
+ const $parentPos = $anchor.parent.isTextblock && pos > 0 ? tr.doc.resolve(pos - 1) : $anchor;
3898
+ const parentIsIsolating = $parentPos.parent.type.spec.isolating;
3899
+ const parentPos = $anchor.pos - $anchor.parentOffset;
3900
+ const isAtStart = parentIsIsolating && $parentPos.parent.childCount === 1 ? parentPos === $anchor.pos : Selection.atStart(doc).from === pos;
3901
+ if (!empty || !parent.type.isTextblock || parent.textContent.length || !isAtStart || isAtStart && $anchor.parent.type.name === "paragraph") {
3902
+ return false;
3903
+ }
3904
+ return commands.clearNodes();
3905
+ }),
3906
+ () => commands.deleteSelection(),
3907
+ () => commands.joinBackward(),
3908
+ () => commands.selectNodeBackward()
3909
+ ]);
3910
+ const handleDelete = () => this.editor.commands.first(({ commands }) => [
3911
+ () => commands.deleteSelection(),
3912
+ () => commands.deleteCurrentNode(),
3913
+ () => commands.joinForward(),
3914
+ () => commands.selectNodeForward()
3915
+ ]);
3916
+ const handleEnter = () => this.editor.commands.first(({ commands }) => [
3917
+ () => commands.newlineInCode(),
3918
+ () => commands.createParagraphNear(),
3919
+ () => commands.liftEmptyBlock(),
3920
+ () => commands.splitBlock()
3921
+ ]);
3922
+ const baseKeymap = {
3923
+ Enter: handleEnter,
3924
+ "Mod-Enter": () => this.editor.commands.exitCode(),
3925
+ Backspace: handleBackspace,
3926
+ "Mod-Backspace": handleBackspace,
3927
+ "Shift-Backspace": handleBackspace,
3928
+ Delete: handleDelete,
3929
+ "Mod-Delete": handleDelete,
3930
+ "Mod-a": () => this.editor.commands.selectAll()
3931
+ };
3932
+ const pcKeymap = {
3933
+ ...baseKeymap
3934
+ };
3935
+ const macKeymap = {
3936
+ ...baseKeymap,
3937
+ "Ctrl-h": handleBackspace,
3938
+ "Alt-Backspace": handleBackspace,
3939
+ "Ctrl-d": handleDelete,
3940
+ "Ctrl-Alt-Backspace": handleDelete,
3941
+ "Alt-Delete": handleDelete,
3942
+ "Alt-d": handleDelete,
3943
+ "Ctrl-a": () => this.editor.commands.selectTextblockStart(),
3944
+ "Ctrl-e": () => this.editor.commands.selectTextblockEnd()
3945
+ };
3946
+ if (isiOS() || isMacOS()) {
3947
+ return macKeymap;
3948
+ }
3949
+ return pcKeymap;
3950
+ },
3951
+ addProseMirrorPlugins() {
3952
+ return [
3953
+ // With this plugin we check if the whole document was selected and deleted.
3954
+ // In this case we will additionally call `clearNodes()` to convert e.g. a heading
3955
+ // to a paragraph if necessary.
3956
+ // This is an alternative to ProseMirror's `AllSelection`, which doesn’t work well
3957
+ // with many other commands.
3958
+ new Plugin({
3959
+ key: new PluginKey("clearDocument"),
3960
+ appendTransaction: (transactions, oldState, newState) => {
3961
+ if (transactions.some((tr2) => tr2.getMeta("composition"))) {
3962
+ return;
3963
+ }
3964
+ const docChanges = transactions.some((transaction) => transaction.docChanged) && !oldState.doc.eq(newState.doc);
3965
+ const ignoreTr = transactions.some(
3966
+ (transaction) => transaction.getMeta("preventClearDocument")
3967
+ );
3968
+ if (!docChanges || ignoreTr) {
3969
+ return;
3970
+ }
3971
+ const { empty, from, to } = oldState.selection;
3972
+ const allFrom = Selection.atStart(oldState.doc).from;
3973
+ const allEnd = Selection.atEnd(oldState.doc).to;
3974
+ const allWasSelected = from === allFrom && to === allEnd;
3975
+ if (empty || !allWasSelected) {
3976
+ return;
3977
+ }
3978
+ const isEmpty = isNodeEmpty(newState.doc);
3979
+ if (!isEmpty) {
3980
+ return;
3981
+ }
3982
+ const tr = newState.tr;
3983
+ const state = createChainableState({
3984
+ state: newState,
3985
+ transaction: tr
3986
+ });
3987
+ const { commands } = new CommandManager({
3988
+ editor: this.editor,
3989
+ state
3990
+ });
3991
+ commands.clearNodes();
3992
+ if (!tr.steps.length) {
3993
+ return;
3994
+ }
3995
+ return tr;
3996
+ }
3997
+ })
3998
+ ];
3999
+ }
4000
+ });
4001
+ var Paste = Extension.create({
4002
+ name: "paste",
4003
+ addProseMirrorPlugins() {
4004
+ return [
4005
+ new Plugin({
4006
+ key: new PluginKey("tiptapPaste"),
4007
+ props: {
4008
+ handlePaste: (_view, e, slice) => {
4009
+ this.editor.emit("paste", {
4010
+ editor: this.editor,
4011
+ event: e,
4012
+ slice
4013
+ });
4014
+ }
4015
+ }
4016
+ })
4017
+ ];
4018
+ }
4019
+ });
4020
+ var Tabindex = Extension.create({
4021
+ name: "tabindex",
4022
+ addOptions() {
4023
+ return {
4024
+ value: void 0
4025
+ };
4026
+ },
4027
+ addProseMirrorPlugins() {
4028
+ return [
4029
+ new Plugin({
4030
+ key: new PluginKey("tabindex"),
4031
+ props: {
4032
+ attributes: () => {
4033
+ var _a;
4034
+ if (!this.editor.isEditable && this.options.value === void 0) {
4035
+ return {};
4036
+ }
4037
+ return { tabindex: (_a = this.options.value) != null ? _a : "0" };
4038
+ }
4039
+ }
4040
+ })
4041
+ ];
4042
+ }
4043
+ });
4044
+ var TextDirection = Extension.create({
4045
+ name: "textDirection",
4046
+ addOptions() {
4047
+ return {
4048
+ direction: void 0
4049
+ };
4050
+ },
4051
+ addGlobalAttributes() {
4052
+ if (!this.options.direction) {
4053
+ return [];
4054
+ }
4055
+ const { nodeExtensions } = splitExtensions(this.extensions);
4056
+ return [
4057
+ {
4058
+ types: nodeExtensions.filter((extension) => extension.name !== "text").map((extension) => extension.name),
4059
+ attributes: {
4060
+ dir: {
4061
+ default: this.options.direction,
4062
+ parseHTML: (element) => {
4063
+ const dir = element.getAttribute("dir");
4064
+ if (dir && (dir === "ltr" || dir === "rtl" || dir === "auto")) {
4065
+ return dir;
4066
+ }
4067
+ return this.options.direction;
4068
+ },
4069
+ renderHTML: (attributes) => {
4070
+ if (!attributes.dir) {
4071
+ return {};
4072
+ }
4073
+ return {
4074
+ dir: attributes.dir
4075
+ };
4076
+ }
4077
+ }
4078
+ }
4079
+ }
4080
+ ];
4081
+ },
4082
+ addProseMirrorPlugins() {
4083
+ return [
4084
+ new Plugin({
4085
+ key: new PluginKey("textDirection"),
4086
+ props: {
4087
+ attributes: () => {
4088
+ const direction = this.options.direction;
4089
+ if (!direction) {
4090
+ return {};
4091
+ }
4092
+ return {
4093
+ dir: direction
4094
+ };
4095
+ }
4096
+ }
4097
+ })
4098
+ ];
4099
+ }
4100
+ });
4101
+ var markdown_exports = {};
4102
+ __export(markdown_exports, {
4103
+ createAtomBlockMarkdownSpec: () => createAtomBlockMarkdownSpec,
4104
+ createBlockMarkdownSpec: () => createBlockMarkdownSpec,
4105
+ createInlineMarkdownSpec: () => createInlineMarkdownSpec,
4106
+ parseAttributes: () => parseAttributes,
4107
+ parseIndentedBlocks: () => parseIndentedBlocks,
4108
+ renderNestedMarkdownContent: () => renderNestedMarkdownContent,
4109
+ serializeAttributes: () => serializeAttributes
4110
+ });
4111
+ function parseAttributes(attrString) {
4112
+ if (!(attrString == null ? void 0 : attrString.trim())) {
4113
+ return {};
4114
+ }
4115
+ const attributes = {};
4116
+ const quotedStrings = [];
4117
+ const tempString = attrString.replace(/["']([^"']*)["']/g, (match) => {
4118
+ quotedStrings.push(match);
4119
+ return `__QUOTED_${quotedStrings.length - 1}__`;
4120
+ });
4121
+ const classMatches = tempString.match(/(?:^|\s)\.([a-zA-Z][\w-]*)/g);
4122
+ if (classMatches) {
4123
+ const classes = classMatches.map((match) => match.trim().slice(1));
4124
+ attributes.class = classes.join(" ");
4125
+ }
4126
+ const idMatch = tempString.match(/(?:^|\s)#([a-zA-Z][\w-]*)/);
4127
+ if (idMatch) {
4128
+ attributes.id = idMatch[1];
4129
+ }
4130
+ const kvRegex = /([a-zA-Z][\w-]*)\s*=\s*(__QUOTED_\d+__)/g;
4131
+ const kvMatches = Array.from(tempString.matchAll(kvRegex));
4132
+ kvMatches.forEach(([, key, quotedRef]) => {
4133
+ var _a;
4134
+ const quotedIndex = parseInt(((_a = quotedRef.match(/__QUOTED_(\d+)__/)) == null ? void 0 : _a[1]) || "0", 10);
4135
+ const quotedValue = quotedStrings[quotedIndex];
4136
+ if (quotedValue) {
4137
+ attributes[key] = quotedValue.slice(1, -1);
4138
+ }
4139
+ });
4140
+ const cleanString = tempString.replace(/(?:^|\s)\.([a-zA-Z][\w-]*)/g, "").replace(/(?:^|\s)#([a-zA-Z][\w-]*)/g, "").replace(/([a-zA-Z][\w-]*)\s*=\s*__QUOTED_\d+__/g, "").trim();
4141
+ if (cleanString) {
4142
+ const booleanAttrs = cleanString.split(/\s+/).filter(Boolean);
4143
+ booleanAttrs.forEach((attr) => {
4144
+ if (attr.match(/^[a-zA-Z][\w-]*$/)) {
4145
+ attributes[attr] = true;
4146
+ }
4147
+ });
4148
+ }
4149
+ return attributes;
4150
+ }
4151
+ function serializeAttributes(attributes) {
4152
+ if (!attributes || Object.keys(attributes).length === 0) {
4153
+ return "";
4154
+ }
4155
+ const parts = [];
4156
+ if (attributes.class) {
4157
+ const classes = String(attributes.class).split(/\s+/).filter(Boolean);
4158
+ classes.forEach((cls) => parts.push(`.${cls}`));
4159
+ }
4160
+ if (attributes.id) {
4161
+ parts.push(`#${attributes.id}`);
4162
+ }
4163
+ Object.entries(attributes).forEach(([key, value]) => {
4164
+ if (key === "class" || key === "id") {
4165
+ return;
4166
+ }
4167
+ if (value === true) {
4168
+ parts.push(key);
4169
+ } else if (value !== false && value != null) {
4170
+ parts.push(`${key}="${String(value)}"`);
4171
+ }
4172
+ });
4173
+ return parts.join(" ");
4174
+ }
4175
+ function createAtomBlockMarkdownSpec(options) {
4176
+ const {
4177
+ nodeName,
4178
+ name: markdownName,
4179
+ parseAttributes: parseAttributes2 = parseAttributes,
4180
+ serializeAttributes: serializeAttributes2 = serializeAttributes,
4181
+ defaultAttributes = {},
4182
+ requiredAttributes = [],
4183
+ allowedAttributes
4184
+ } = options;
4185
+ const blockName = markdownName || nodeName;
4186
+ const filterAttributes = (attrs) => {
4187
+ if (!allowedAttributes) {
4188
+ return attrs;
4189
+ }
4190
+ const filtered = {};
4191
+ allowedAttributes.forEach((key) => {
4192
+ if (key in attrs) {
4193
+ filtered[key] = attrs[key];
4194
+ }
4195
+ });
4196
+ return filtered;
4197
+ };
4198
+ return {
4199
+ parseMarkdown: (token, h2) => {
4200
+ const attrs = { ...defaultAttributes, ...token.attributes };
4201
+ return h2.createNode(nodeName, attrs, []);
4202
+ },
4203
+ markdownTokenizer: {
4204
+ name: nodeName,
4205
+ level: "block",
4206
+ start(src) {
4207
+ var _a;
4208
+ const regex = new RegExp(`^:::${blockName}(?:\\s|$)`, "m");
4209
+ const index = (_a = src.match(regex)) == null ? void 0 : _a.index;
4210
+ return index !== void 0 ? index : -1;
4211
+ },
4212
+ tokenize(src, _tokens, _lexer) {
4213
+ const regex = new RegExp(`^:::${blockName}(?:\\s+\\{([^}]*)\\})?\\s*:::(?:\\n|$)`);
4214
+ const match = src.match(regex);
4215
+ if (!match) {
4216
+ return void 0;
4217
+ }
4218
+ const attrString = match[1] || "";
4219
+ const attributes = parseAttributes2(attrString);
4220
+ const missingRequired = requiredAttributes.find((required) => !(required in attributes));
4221
+ if (missingRequired) {
4222
+ return void 0;
4223
+ }
4224
+ return {
4225
+ type: nodeName,
4226
+ raw: match[0],
4227
+ attributes
4228
+ };
4229
+ }
4230
+ },
4231
+ renderMarkdown: (node) => {
4232
+ const filteredAttrs = filterAttributes(node.attrs || {});
4233
+ const attrs = serializeAttributes2(filteredAttrs);
4234
+ const attrString = attrs ? ` {${attrs}}` : "";
4235
+ return `:::${blockName}${attrString} :::`;
4236
+ }
4237
+ };
4238
+ }
4239
+ function createBlockMarkdownSpec(options) {
4240
+ const {
4241
+ nodeName,
4242
+ name: markdownName,
4243
+ getContent,
4244
+ parseAttributes: parseAttributes2 = parseAttributes,
4245
+ serializeAttributes: serializeAttributes2 = serializeAttributes,
4246
+ defaultAttributes = {},
4247
+ content = "block",
4248
+ allowedAttributes
4249
+ } = options;
4250
+ const blockName = markdownName || nodeName;
4251
+ const filterAttributes = (attrs) => {
4252
+ if (!allowedAttributes) {
4253
+ return attrs;
4254
+ }
4255
+ const filtered = {};
4256
+ allowedAttributes.forEach((key) => {
4257
+ if (key in attrs) {
4258
+ filtered[key] = attrs[key];
4259
+ }
4260
+ });
4261
+ return filtered;
4262
+ };
4263
+ return {
4264
+ parseMarkdown: (token, h2) => {
4265
+ let nodeContent;
4266
+ if (getContent) {
4267
+ const contentResult = getContent(token);
4268
+ nodeContent = typeof contentResult === "string" ? [{ type: "text", text: contentResult }] : contentResult;
4269
+ } else if (content === "block") {
4270
+ nodeContent = h2.parseChildren(token.tokens || []);
4271
+ } else {
4272
+ nodeContent = h2.parseInline(token.tokens || []);
4273
+ }
4274
+ const attrs = { ...defaultAttributes, ...token.attributes };
4275
+ return h2.createNode(nodeName, attrs, nodeContent);
4276
+ },
4277
+ markdownTokenizer: {
4278
+ name: nodeName,
4279
+ level: "block",
4280
+ start(src) {
4281
+ var _a;
4282
+ const regex = new RegExp(`^:::${blockName}`, "m");
4283
+ const index = (_a = src.match(regex)) == null ? void 0 : _a.index;
4284
+ return index !== void 0 ? index : -1;
4285
+ },
4286
+ tokenize(src, _tokens, lexer) {
4287
+ var _a;
4288
+ const openingRegex = new RegExp(`^:::${blockName}(?:\\s+\\{([^}]*)\\})?\\s*\\n`);
4289
+ const openingMatch = src.match(openingRegex);
4290
+ if (!openingMatch) {
4291
+ return void 0;
4292
+ }
4293
+ const [openingTag, attrString = ""] = openingMatch;
4294
+ const attributes = parseAttributes2(attrString);
4295
+ let level = 1;
4296
+ const position = openingTag.length;
4297
+ let matchedContent = "";
4298
+ const blockPattern = /^:::([\w-]*)(\s.*)?/gm;
4299
+ const remaining = src.slice(position);
4300
+ blockPattern.lastIndex = 0;
4301
+ for (; ; ) {
4302
+ const match = blockPattern.exec(remaining);
4303
+ if (match === null) {
4304
+ break;
4305
+ }
4306
+ const matchPos = match.index;
4307
+ const blockType = match[1];
4308
+ if ((_a = match[2]) == null ? void 0 : _a.endsWith(":::")) {
4309
+ continue;
4310
+ }
4311
+ if (blockType) {
4312
+ level += 1;
4313
+ } else {
4314
+ level -= 1;
4315
+ if (level === 0) {
4316
+ const rawContent = remaining.slice(0, matchPos);
4317
+ matchedContent = rawContent.trim();
4318
+ const fullMatch = src.slice(0, position + matchPos + match[0].length);
4319
+ let contentTokens = [];
4320
+ if (matchedContent) {
4321
+ if (content === "block") {
4322
+ contentTokens = lexer.blockTokens(rawContent);
4323
+ contentTokens.forEach((token) => {
4324
+ if (token.text && (!token.tokens || token.tokens.length === 0)) {
4325
+ token.tokens = lexer.inlineTokens(token.text);
4326
+ }
4327
+ });
4328
+ while (contentTokens.length > 0) {
4329
+ const lastToken = contentTokens[contentTokens.length - 1];
4330
+ if (lastToken.type === "paragraph" && (!lastToken.text || lastToken.text.trim() === "")) {
4331
+ contentTokens.pop();
4332
+ } else {
4333
+ break;
4334
+ }
4335
+ }
4336
+ } else {
4337
+ contentTokens = lexer.inlineTokens(matchedContent);
4338
+ }
4339
+ }
4340
+ return {
4341
+ type: nodeName,
4342
+ raw: fullMatch,
4343
+ attributes,
4344
+ content: matchedContent,
4345
+ tokens: contentTokens
4346
+ };
4347
+ }
4348
+ }
4349
+ }
4350
+ return void 0;
4351
+ }
4352
+ },
4353
+ renderMarkdown: (node, h2) => {
4354
+ const filteredAttrs = filterAttributes(node.attrs || {});
4355
+ const attrs = serializeAttributes2(filteredAttrs);
4356
+ const attrString = attrs ? ` {${attrs}}` : "";
4357
+ const renderedContent = h2.renderChildren(node.content || [], "\n\n");
4358
+ return `:::${blockName}${attrString}
4359
+
4360
+ ${renderedContent}
4361
+
4362
+ :::`;
4363
+ }
4364
+ };
4365
+ }
4366
+ function parseShortcodeAttributes(attrString) {
4367
+ if (!attrString.trim()) {
4368
+ return {};
4369
+ }
4370
+ const attributes = {};
4371
+ const regex = /(\w+)=(?:"([^"]*)"|'([^']*)')/g;
4372
+ let match = regex.exec(attrString);
4373
+ while (match !== null) {
4374
+ const [, key, doubleQuoted, singleQuoted] = match;
4375
+ attributes[key] = doubleQuoted || singleQuoted;
4376
+ match = regex.exec(attrString);
4377
+ }
4378
+ return attributes;
4379
+ }
4380
+ function serializeShortcodeAttributes(attrs) {
4381
+ return Object.entries(attrs).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => `${key}="${value}"`).join(" ");
4382
+ }
4383
+ function createInlineMarkdownSpec(options) {
4384
+ const {
4385
+ nodeName,
4386
+ name: shortcodeName,
4387
+ getContent,
4388
+ parseAttributes: parseAttributes2 = parseShortcodeAttributes,
4389
+ serializeAttributes: serializeAttributes2 = serializeShortcodeAttributes,
4390
+ defaultAttributes = {},
4391
+ selfClosing = false,
4392
+ allowedAttributes
4393
+ } = options;
4394
+ const shortcode = shortcodeName || nodeName;
4395
+ const filterAttributes = (attrs) => {
4396
+ if (!allowedAttributes) {
4397
+ return attrs;
4398
+ }
4399
+ const filtered = {};
4400
+ allowedAttributes.forEach((attr) => {
4401
+ const attrName = typeof attr === "string" ? attr : attr.name;
4402
+ const skipIfDefault = typeof attr === "string" ? void 0 : attr.skipIfDefault;
4403
+ if (attrName in attrs) {
4404
+ const value = attrs[attrName];
4405
+ if (skipIfDefault !== void 0 && value === skipIfDefault) {
4406
+ return;
4407
+ }
4408
+ filtered[attrName] = value;
4409
+ }
4410
+ });
4411
+ return filtered;
4412
+ };
4413
+ const escapedShortcode = shortcode.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4414
+ return {
4415
+ parseMarkdown: (token, h2) => {
4416
+ const attrs = { ...defaultAttributes, ...token.attributes };
4417
+ if (selfClosing) {
4418
+ return h2.createNode(nodeName, attrs);
4419
+ }
4420
+ const content = getContent ? getContent(token) : token.content || "";
4421
+ if (content) {
4422
+ return h2.createNode(nodeName, attrs, [h2.createTextNode(content)]);
4423
+ }
4424
+ return h2.createNode(nodeName, attrs, []);
4425
+ },
4426
+ markdownTokenizer: {
4427
+ name: nodeName,
4428
+ level: "inline",
4429
+ start(src) {
4430
+ const startPattern = selfClosing ? new RegExp(`\\[${escapedShortcode}\\s*[^\\]]*\\]`) : new RegExp(`\\[${escapedShortcode}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${escapedShortcode}\\]`);
4431
+ const match = src.match(startPattern);
4432
+ const index = match == null ? void 0 : match.index;
4433
+ return index !== void 0 ? index : -1;
4434
+ },
4435
+ tokenize(src, _tokens, _lexer) {
4436
+ const tokenPattern = selfClosing ? new RegExp(`^\\[${escapedShortcode}\\s*([^\\]]*)\\]`) : new RegExp(
4437
+ `^\\[${escapedShortcode}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${escapedShortcode}\\]`
4438
+ );
4439
+ const match = src.match(tokenPattern);
4440
+ if (!match) {
4441
+ return void 0;
4442
+ }
4443
+ let content = "";
4444
+ let attrString = "";
4445
+ if (selfClosing) {
4446
+ const [, attrs] = match;
4447
+ attrString = attrs;
4448
+ } else {
4449
+ const [, attrs, contentMatch] = match;
4450
+ attrString = attrs;
4451
+ content = contentMatch || "";
4452
+ }
4453
+ const attributes = parseAttributes2(attrString.trim());
4454
+ return {
4455
+ type: nodeName,
4456
+ raw: match[0],
4457
+ content: content.trim(),
4458
+ attributes
4459
+ };
4460
+ }
4461
+ },
4462
+ renderMarkdown: (node) => {
4463
+ let content = "";
4464
+ if (getContent) {
4465
+ content = getContent(node);
4466
+ } else if (node.content && node.content.length > 0) {
4467
+ content = node.content.filter((child) => child.type === "text").map((child) => child.text).join("");
4468
+ }
4469
+ const filteredAttrs = filterAttributes(node.attrs || {});
4470
+ const attrs = serializeAttributes2(filteredAttrs);
4471
+ const attrString = attrs ? ` ${attrs}` : "";
4472
+ if (selfClosing) {
4473
+ return `[${shortcode}${attrString}]`;
4474
+ }
4475
+ return `[${shortcode}${attrString}]${content}[/${shortcode}]`;
4476
+ }
4477
+ };
4478
+ }
4479
+ function parseIndentedBlocks(src, config, lexer) {
4480
+ var _a, _b, _c, _d;
4481
+ const lines = src.split("\n");
4482
+ const items = [];
4483
+ let totalRaw = "";
4484
+ let i = 0;
4485
+ const baseIndentSize = config.baseIndentSize || 2;
4486
+ while (i < lines.length) {
4487
+ const currentLine = lines[i];
4488
+ const itemMatch = currentLine.match(config.itemPattern);
4489
+ if (!itemMatch) {
4490
+ if (items.length > 0) {
4491
+ break;
4492
+ } else if (currentLine.trim() === "") {
4493
+ i += 1;
4494
+ totalRaw = `${totalRaw}${currentLine}
4495
+ `;
4496
+ continue;
4497
+ } else {
4498
+ return void 0;
4499
+ }
4500
+ }
4501
+ const itemData = config.extractItemData(itemMatch);
4502
+ const { indentLevel, mainContent } = itemData;
4503
+ totalRaw = `${totalRaw}${currentLine}
4504
+ `;
4505
+ const itemContent = [mainContent];
4506
+ i += 1;
4507
+ while (i < lines.length) {
4508
+ const nextLine = lines[i];
4509
+ if (nextLine.trim() === "") {
4510
+ const nextNonEmptyIndex = lines.slice(i + 1).findIndex((l) => l.trim() !== "");
4511
+ if (nextNonEmptyIndex === -1) {
4512
+ break;
4513
+ }
4514
+ const nextNonEmpty = lines[i + 1 + nextNonEmptyIndex];
4515
+ const nextIndent2 = ((_b = (_a = nextNonEmpty.match(/^(\s*)/)) == null ? void 0 : _a[1]) == null ? void 0 : _b.length) || 0;
4516
+ if (nextIndent2 > indentLevel) {
4517
+ itemContent.push(nextLine);
4518
+ totalRaw = `${totalRaw}${nextLine}
4519
+ `;
4520
+ i += 1;
4521
+ continue;
4522
+ } else {
4523
+ break;
4524
+ }
4525
+ }
4526
+ const nextIndent = ((_d = (_c = nextLine.match(/^(\s*)/)) == null ? void 0 : _c[1]) == null ? void 0 : _d.length) || 0;
4527
+ if (nextIndent > indentLevel) {
4528
+ itemContent.push(nextLine);
4529
+ totalRaw = `${totalRaw}${nextLine}
4530
+ `;
4531
+ i += 1;
4532
+ } else {
4533
+ break;
4534
+ }
4535
+ }
4536
+ let nestedTokens;
4537
+ const nestedContent = itemContent.slice(1);
4538
+ if (nestedContent.length > 0) {
4539
+ const dedentedNested = nestedContent.map((nestedLine) => nestedLine.slice(indentLevel + baseIndentSize)).join("\n");
4540
+ if (dedentedNested.trim()) {
4541
+ if (config.customNestedParser) {
4542
+ nestedTokens = config.customNestedParser(dedentedNested);
4543
+ } else {
4544
+ nestedTokens = lexer.blockTokens(dedentedNested);
4545
+ }
4546
+ }
4547
+ }
4548
+ const token = config.createToken(itemData, nestedTokens);
4549
+ items.push(token);
4550
+ }
4551
+ if (items.length === 0) {
4552
+ return void 0;
4553
+ }
4554
+ return {
4555
+ items,
4556
+ raw: totalRaw
4557
+ };
4558
+ }
4559
+ function renderNestedMarkdownContent(node, h2, prefixOrGenerator, ctx) {
4560
+ if (!node || !Array.isArray(node.content)) {
4561
+ return "";
4562
+ }
4563
+ const prefix = typeof prefixOrGenerator === "function" ? prefixOrGenerator(ctx) : prefixOrGenerator;
4564
+ const [content, ...children] = node.content;
4565
+ const mainContent = h2.renderChildren([content]);
4566
+ let output = `${prefix}${mainContent}`;
4567
+ if (children && children.length > 0) {
4568
+ children.forEach((child, index) => {
4569
+ var _a, _b;
4570
+ const childContent = (_b = (_a = h2.renderChild) == null ? void 0 : _a.call(h2, child, index + 1)) != null ? _b : h2.renderChildren([child]);
4571
+ if (childContent !== void 0 && childContent !== null) {
4572
+ const indentedChild = childContent.split("\n").map((line) => line ? h2.indent(line) : h2.indent("")).join("\n");
4573
+ output += child.type === "paragraph" ? `
4574
+
4575
+ ${indentedChild}` : `
4576
+ ${indentedChild}`;
4577
+ }
4578
+ });
4579
+ }
4580
+ return output;
4581
+ }
4582
+ var Node3 = class _Node extends Extendable {
4583
+ constructor() {
4584
+ super(...arguments);
4585
+ this.type = "node";
4586
+ }
4587
+ /**
4588
+ * Create a new Node instance
4589
+ * @param config - Node configuration object or a function that returns a configuration object
4590
+ */
4591
+ static create(config = {}) {
4592
+ const resolvedConfig = typeof config === "function" ? config() : config;
4593
+ return new _Node(resolvedConfig);
4594
+ }
4595
+ configure(options) {
4596
+ return super.configure(options);
4597
+ }
4598
+ extend(extendedConfig) {
4599
+ const resolvedConfig = typeof extendedConfig === "function" ? extendedConfig() : extendedConfig;
4600
+ return super.extend(resolvedConfig);
4601
+ }
4602
+ };
4603
+
4604
+ // src/components/RichTextEditor/extensions/Highlight.ts
4605
+ var Highlight = Mark.create({
4606
+ name: "highlight",
4607
+ renderHTML({ HTMLAttributes }) {
4608
+ return ["mark", { style: "background: #fef08a; border-radius: 2px; padding: 0 2px;", ...HTMLAttributes }, 0];
4609
+ },
4610
+ parseHTML() {
4611
+ return [{ tag: "mark" }];
4612
+ },
4613
+ addKeyboardShortcuts() {
4614
+ return {
4615
+ "Mod-Shift-h": () => this.editor.commands.toggleMark(this.name)
4616
+ };
4617
+ }
4618
+ });
4619
+ var HighlightIcon = () => /* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 14 14", fill: "none", "aria-hidden": "true", children: [
4620
+ /* @__PURE__ */ jsx("rect", { x: "1", y: "8", width: "12", height: "3", rx: "1", fill: "#fef08a", stroke: "currentColor", strokeWidth: "1" }),
4621
+ /* @__PURE__ */ jsx("path", { d: "M4 8L5.5 3h3L10 8", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round", strokeLinejoin: "round" }),
4622
+ /* @__PURE__ */ jsx("line", { x1: "4.5", y1: "6", x2: "9.5", y2: "6", stroke: "currentColor", strokeWidth: "1", strokeLinecap: "round" })
4623
+ ] });
4624
+ var HighlightButton = () => {
4625
+ const { editor } = useCurrentEditor();
4626
+ if (!editor) return null;
4627
+ const active = editor.isActive("highlight");
4628
+ return /* @__PURE__ */ jsx(
4629
+ "button",
4630
+ {
4631
+ type: "button",
4632
+ title: "Highlight (Mod+Shift+H)",
4633
+ "aria-label": "Highlight",
4634
+ "aria-pressed": active,
4635
+ className: [RichTextEditor_module_default.toolbarButton, active ? RichTextEditor_module_default.active : ""].filter(Boolean).join(" "),
4636
+ onMouseDown: (e) => {
4637
+ e.preventDefault();
4638
+ editor.chain().focus().toggleMark("highlight").run();
4639
+ },
4640
+ children: /* @__PURE__ */ jsx(HighlightIcon, {})
4641
+ }
4642
+ );
4643
+ };
4644
+
4645
+ // src/components/RichTextEditor/extensions/PageBreak.ts
4646
+ var PageBreak = Node3.create({
4647
+ name: "pageBreak",
4648
+ group: "block",
4649
+ atom: true,
4650
+ parseHTML() {
4651
+ return [{ tag: 'div[data-type="page-break"]' }];
4652
+ },
4653
+ renderHTML({ HTMLAttributes }) {
4654
+ return ["div", mergeAttributes(HTMLAttributes, { "data-type": "page-break" })];
4655
+ },
4656
+ addKeyboardShortcuts() {
4657
+ return {
4658
+ "Mod-Enter": () => this.editor.commands.insertContent({ type: this.name })
4659
+ };
4660
+ }
4661
+ });
4662
+ var PageBreakIcon = () => /* @__PURE__ */ jsxs("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: [
4663
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "1", width: "10", height: "6", rx: "1", stroke: "currentColor", strokeWidth: "1.2" }),
4664
+ /* @__PURE__ */ jsx("rect", { x: "3", y: "9", width: "10", height: "6", rx: "1", stroke: "currentColor", strokeWidth: "1.2" }),
4665
+ /* @__PURE__ */ jsx("line", { x1: "1", y1: "8", x2: "5", y2: "8", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round", strokeDasharray: "1.5 1.5" }),
4666
+ /* @__PURE__ */ jsx("line", { x1: "7", y1: "8", x2: "9", y2: "8", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round", strokeDasharray: "1.5 1.5" }),
4667
+ /* @__PURE__ */ jsx("line", { x1: "11", y1: "8", x2: "15", y2: "8", stroke: "currentColor", strokeWidth: "1.2", strokeLinecap: "round", strokeDasharray: "1.5 1.5" })
4668
+ ] });
4669
+ var PageBreakButton = () => {
4670
+ const { editor } = useCurrentEditor();
4671
+ if (!editor) return null;
4672
+ return /* @__PURE__ */ jsx(
4673
+ "button",
4674
+ {
4675
+ type: "button",
4676
+ title: "Page break (Mod+Enter)",
4677
+ "aria-label": "Insert page break",
4678
+ className: RichTextEditor_module_default.toolbarButton,
4679
+ onMouseDown: (e) => {
4680
+ e.preventDefault();
4681
+ editor.chain().focus().insertContent({ type: "pageBreak" }).run();
4682
+ },
4683
+ children: /* @__PURE__ */ jsx(PageBreakIcon, {})
4684
+ }
4685
+ );
4686
+ };
4687
+
4688
+ export { Badge, Button, ColorPicker, Highlight, HighlightButton, Input, PageBreak, PageBreakButton, RainCanvas, RichTextEditor, SliderControl, SlidingCounter, Timeline };
994
4689
  //# sourceMappingURL=index.js.map
995
4690
  //# sourceMappingURL=index.js.map