react-next-editor-js 0.1.0

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 (102) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +877 -0
  3. package/dist/chunk-3QWXTDLY.cjs +486 -0
  4. package/dist/chunk-3QWXTDLY.cjs.map +1 -0
  5. package/dist/chunk-5F6SPYCN.cjs +180 -0
  6. package/dist/chunk-5F6SPYCN.cjs.map +1 -0
  7. package/dist/chunk-6NTSXJX4.js +174 -0
  8. package/dist/chunk-6NTSXJX4.js.map +1 -0
  9. package/dist/chunk-7VYJDBH7.js +261 -0
  10. package/dist/chunk-7VYJDBH7.js.map +1 -0
  11. package/dist/chunk-DBSFCCBG.cjs +1712 -0
  12. package/dist/chunk-DBSFCCBG.cjs.map +1 -0
  13. package/dist/chunk-EFE6RHDL.cjs +4 -0
  14. package/dist/chunk-EFE6RHDL.cjs.map +1 -0
  15. package/dist/chunk-G6YRIEK4.js +3 -0
  16. package/dist/chunk-G6YRIEK4.js.map +1 -0
  17. package/dist/chunk-GFNFJ3FL.cjs +119 -0
  18. package/dist/chunk-GFNFJ3FL.cjs.map +1 -0
  19. package/dist/chunk-IG2YLUFW.js +114 -0
  20. package/dist/chunk-IG2YLUFW.js.map +1 -0
  21. package/dist/chunk-JQXTWLHL.js +176 -0
  22. package/dist/chunk-JQXTWLHL.js.map +1 -0
  23. package/dist/chunk-NJCEHQV3.cjs +454 -0
  24. package/dist/chunk-NJCEHQV3.cjs.map +1 -0
  25. package/dist/chunk-O4GTLC3T.js +478 -0
  26. package/dist/chunk-O4GTLC3T.js.map +1 -0
  27. package/dist/chunk-ODHABIIC.cjs +82 -0
  28. package/dist/chunk-ODHABIIC.cjs.map +1 -0
  29. package/dist/chunk-PZ5AY32C.js +9 -0
  30. package/dist/chunk-PZ5AY32C.js.map +1 -0
  31. package/dist/chunk-Q7SFCCGT.cjs +11 -0
  32. package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
  33. package/dist/chunk-QIUIYBCZ.js +80 -0
  34. package/dist/chunk-QIUIYBCZ.js.map +1 -0
  35. package/dist/chunk-QROUNVQK.js +450 -0
  36. package/dist/chunk-QROUNVQK.js.map +1 -0
  37. package/dist/chunk-T6FR37IC.js +41 -0
  38. package/dist/chunk-T6FR37IC.js.map +1 -0
  39. package/dist/chunk-TI44I654.cjs +265 -0
  40. package/dist/chunk-TI44I654.cjs.map +1 -0
  41. package/dist/chunk-TXPLBAH5.cjs +47 -0
  42. package/dist/chunk-TXPLBAH5.cjs.map +1 -0
  43. package/dist/chunk-U3O54IYI.cjs +187 -0
  44. package/dist/chunk-U3O54IYI.cjs.map +1 -0
  45. package/dist/chunk-VLC7SZMT.js +1669 -0
  46. package/dist/chunk-VLC7SZMT.js.map +1 -0
  47. package/dist/core/index.cjs +232 -0
  48. package/dist/core/index.cjs.map +1 -0
  49. package/dist/core/index.d.cts +122 -0
  50. package/dist/core/index.d.ts +122 -0
  51. package/dist/core/index.js +7 -0
  52. package/dist/core/index.js.map +1 -0
  53. package/dist/defaults-EQD5QKCU.js +4 -0
  54. package/dist/defaults-EQD5QKCU.js.map +1 -0
  55. package/dist/defaults-MLYXD2BG.cjs +49 -0
  56. package/dist/defaults-MLYXD2BG.cjs.map +1 -0
  57. package/dist/docx-BUrf4PFj.d.ts +49 -0
  58. package/dist/docx-DLfSdvXm.d.cts +49 -0
  59. package/dist/docx-LDETXV3L.js +5 -0
  60. package/dist/docx-LDETXV3L.js.map +1 -0
  61. package/dist/docx-N2LKIOK3.cjs +14 -0
  62. package/dist/docx-N2LKIOK3.cjs.map +1 -0
  63. package/dist/export/index.cjs +54 -0
  64. package/dist/export/index.cjs.map +1 -0
  65. package/dist/export/index.d.cts +60 -0
  66. package/dist/export/index.d.ts +60 -0
  67. package/dist/export/index.js +9 -0
  68. package/dist/export/index.js.map +1 -0
  69. package/dist/html-5BXJPQU3.js +7 -0
  70. package/dist/html-5BXJPQU3.js.map +1 -0
  71. package/dist/html-KU2KHLRF.cjs +24 -0
  72. package/dist/html-KU2KHLRF.cjs.map +1 -0
  73. package/dist/import/index.cjs +15 -0
  74. package/dist/import/index.cjs.map +1 -0
  75. package/dist/import/index.d.cts +37 -0
  76. package/dist/import/index.d.ts +37 -0
  77. package/dist/import/index.js +6 -0
  78. package/dist/import/index.js.map +1 -0
  79. package/dist/index.cjs +1035 -0
  80. package/dist/index.cjs.map +1 -0
  81. package/dist/index.d.cts +248 -0
  82. package/dist/index.d.ts +248 -0
  83. package/dist/index.js +885 -0
  84. package/dist/index.js.map +1 -0
  85. package/dist/persistence/index.cjs +37 -0
  86. package/dist/persistence/index.cjs.map +1 -0
  87. package/dist/persistence/index.d.cts +279 -0
  88. package/dist/persistence/index.d.ts +279 -0
  89. package/dist/persistence/index.js +4 -0
  90. package/dist/persistence/index.js.map +1 -0
  91. package/dist/sanitize-7IZ-SW1f.d.ts +361 -0
  92. package/dist/sanitize-CvmgqbsA.d.cts +361 -0
  93. package/dist/server/index.cjs +400 -0
  94. package/dist/server/index.cjs.map +1 -0
  95. package/dist/server/index.d.cts +229 -0
  96. package/dist/server/index.d.ts +229 -0
  97. package/dist/server/index.js +390 -0
  98. package/dist/server/index.js.map +1 -0
  99. package/dist/styles.css +680 -0
  100. package/dist/types-B4z0Quvv.d.cts +193 -0
  101. package/dist/types-B4z0Quvv.d.ts +193 -0
  102. package/package.json +183 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,1035 @@
1
+ 'use strict';
2
+
3
+ var chunkDBSFCCBG_cjs = require('./chunk-DBSFCCBG.cjs');
4
+ var chunkGFNFJ3FL_cjs = require('./chunk-GFNFJ3FL.cjs');
5
+ var chunk3QWXTDLY_cjs = require('./chunk-3QWXTDLY.cjs');
6
+ var chunkNJCEHQV3_cjs = require('./chunk-NJCEHQV3.cjs');
7
+ require('./chunk-EFE6RHDL.cjs');
8
+ var chunkODHABIIC_cjs = require('./chunk-ODHABIIC.cjs');
9
+ var chunkTI44I654_cjs = require('./chunk-TI44I654.cjs');
10
+ require('./chunk-TXPLBAH5.cjs');
11
+ var chunk5F6SPYCN_cjs = require('./chunk-5F6SPYCN.cjs');
12
+ var chunkU3O54IYI_cjs = require('./chunk-U3O54IYI.cjs');
13
+ require('./chunk-Q7SFCCGT.cjs');
14
+ var react = require('react');
15
+ var prosemirrorView = require('prosemirror-view');
16
+ var prosemirrorState = require('prosemirror-state');
17
+ var prosemirrorModel = require('prosemirror-model');
18
+ var jsxRuntime = require('react/jsx-runtime');
19
+
20
+ var EditorContext = react.createContext(null);
21
+ function useEditorContext() {
22
+ const ctx = react.useContext(EditorContext);
23
+ if (!ctx) {
24
+ throw new Error("useEditorContext must be used within a react-next-editor <Editor>.");
25
+ }
26
+ return ctx;
27
+ }
28
+ var EditorErrorBoundary = class extends react.Component {
29
+ constructor(props) {
30
+ super(props);
31
+ this.handleReset = () => {
32
+ this.setState({ error: null });
33
+ };
34
+ this.state = { error: null };
35
+ }
36
+ static getDerivedStateFromError(error) {
37
+ return { error };
38
+ }
39
+ componentDidCatch(error, info) {
40
+ console.error("[react-next-editor] Editor error contained by boundary:", error, info);
41
+ this.props.onError?.(error);
42
+ }
43
+ render() {
44
+ if (this.state.error) {
45
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rne-root", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rne-error", role: "alert", children: [
46
+ /* @__PURE__ */ jsxRuntime.jsx("strong", { children: this.props.fallbackMessage ?? "The editor encountered a problem." }),
47
+ /* @__PURE__ */ jsxRuntime.jsx("p", { children: "Your latest saved content is preserved locally. You can try to recover the editor." }),
48
+ /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: this.handleReset, children: "Reload editor" })
49
+ ] }) });
50
+ }
51
+ return this.props.children;
52
+ }
53
+ };
54
+ var PATHS = {
55
+ undo: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 5V1L7 6l5 5V7a6 6 0 1 1-6 6H4a8 8 0 1 0 8-8z" }),
56
+ redo: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 5V1l5 5-5 5V7a6 6 0 1 0 6 6h2a8 8 0 1 1-8-8z" }),
57
+ bold: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M7 5h6a3.5 3.5 0 0 1 1.5 6.66A3.5 3.5 0 0 1 13 19H7V5zm3 2v3h3a1.5 1.5 0 0 0 0-3h-3zm0 5v4h3a2 2 0 0 0 0-4h-3z" }),
58
+ italic: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M10 4h7v2h-2.3l-3 12H14v2H7v-2h2.3l3-12H10V4z" }),
59
+ underline: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 4v7a6 6 0 0 0 12 0V4h-2.5v7a3.5 3.5 0 0 1-7 0V4H6zm-1 16h14v2H5v-2z" }),
60
+ strikethrough: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 11h18v2H3v-2zm9-7c2.5 0 4 1.3 4.3 3h-2.4c-.2-.7-.8-1.2-1.9-1.2-1.2 0-2 .6-2 1.5 0 .5.3.9 1 1.2H9.2C8.5 9 8 8.2 8 7.2 8 5.3 9.7 4 12 4zm2 11.5c0 1.9-1.6 3.5-4.2 3.5-2.6 0-4.3-1.4-4.5-3.4h2.4c.2.9 1 1.5 2.2 1.5 1.3 0 2.1-.6 2.1-1.6 0-.2 0-.4-.1-.5H14z" }),
61
+ superscript: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 7l4 5-4 5h2.5L9 13.5 11.5 17H14l-4-5 4-5h-2.5L9 10.5 6.5 7H4zm16-1c0-.8-.6-1.5-1.7-1.5-.9 0-1.6.5-1.8 1.3h1c.1-.3.4-.5.8-.5.4 0 .7.2.7.6 0 .6-1 1-2.3 2.1V9h3.6v-.9h-1.9c1-.8 1.6-1.3 1.6-2.2z" }),
62
+ subscript: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 4l4 5-4 5h2.5L9 10.5 11.5 14H14l-4-5 4-5h-2.5L9 7.5 6.5 4H4zm16 13c0-.8-.6-1.5-1.7-1.5-.9 0-1.6.5-1.8 1.3h1c.1-.3.4-.5.8-.5.4 0 .7.2.7.6 0 .6-1 1-2.3 2.1V20h3.6v-.9h-1.9c1-.8 1.6-1.3 1.6-2.1z" }),
63
+ code: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M9 7l-5 5 5 5 1.4-1.4L6.8 12l3.6-3.6L9 7zm6 0l-1.4 1.4L17.2 12l-3.6 3.6L15 17l5-5-5-5z" }),
64
+ textColor: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 18h14v2H5v-2zM9.6 4h2.8l4.1 11h-2.3l-1-3H8.8l-1 3H5.5L9.6 4zm-.2 6.1h3.2L11 5.6 9.4 10.1z" }),
65
+ highlight: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 18h16v3H4v-3zM15.6 3.4l3 3-7.8 7.8-3.6.6.6-3.6 7.8-7.8zM6 13l3 3H6v-3z" }),
66
+ clearFormatting: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 5v2h5l-2.8 9h2.5l2.8-9H19V5H6zM4.7 17.3 17.3 4.7l1.4 1.4L6.1 18.7l-1.4-1.4z" }),
67
+ alignLeft: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 4h18v2H3V4zm0 5h12v2H3V9zm0 5h18v2H3v-2zm0 5h12v2H3v-2z" }),
68
+ alignCenter: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 4h18v2H3V4zm3 5h12v2H6V9zm-3 5h18v2H3v-2zm3 5h12v2H6v-2z" }),
69
+ alignRight: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 4h18v2H3V4zm6 5h12v2H9V9zm-6 5h18v2H3v-2zm6 5h12v2H9v-2z" }),
70
+ alignJustify: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 4h18v2H3V4zm0 5h18v2H3V9zm0 5h18v2H3v-2zm0 5h18v2H3v-2z" }),
71
+ bulletList: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 5.5a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3zm4 .5h13v2H8V6zm-4 4.5a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3zm4 .5h13v2H8v-2zm-4 4.5a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3zm4 .5h13v2H8v-2z" }),
72
+ orderedList: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 6h1V3H2v1h1v2zm5 0h13v2H8V6zm0 5h13v2H8v-2zm0 5h13v2H8v-2zM2 12.8h2v.5H3v.5h1v.5H2v.7h3v-3H2v.8zm1 4.2H2v.8h1.8v.4L2 19v.9h3V17H4l-1 .5V17z" }),
73
+ taskList: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 5h6v6H3V5zm2 2v2h2V7H5zm6-1h10v2H11V6zm0 5h10v2H11v-2zm0 5h10v2H11v-2zM3 15.4l1.4-1.4 1.1 1.1 2.6-2.6L9.5 14l-4 4L3 15.4z" }),
74
+ indent: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 4h18v2H3V4zm8 5h10v2H11V9zm0 5h10v2H11v-2zm-8 5h18v2H3v-2zm0-9 4 3-4 3V10z" }),
75
+ outdent: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 4h18v2H3V4zm8 5h10v2H11V9zm0 5h10v2H11v-2zm-8 5h18v2H3v-2zM7 10v6l-4-3 4-3z" }),
76
+ blockquote: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M7 7c-2 0-3.5 1.6-3.5 3.6 0 1.8 1.3 3 2.9 3 .2 0 .4 0 .6-.1-.4 1-1.4 1.8-2.5 2.1l.6 1.4C7.7 16.9 9.5 14.8 9.5 12 9.5 9.2 8.4 7 7 7zm9 0c-2 0-3.5 1.6-3.5 3.6 0 1.8 1.3 3 2.9 3 .2 0 .4 0 .6-.1-.4 1-1.4 1.8-2.5 2.1l.6 1.4c2.1-.6 3.9-2.7 3.9-5.5C18.5 9.2 17.4 7 16 7z" }),
77
+ horizontalRule: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 11h18v2H3v-2z" }),
78
+ link: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M10.6 13.4a1 1 0 0 0 1.4 0l3-3a3 3 0 0 0-4.3-4.3l-1.5 1.5 1.4 1.4 1.5-1.5a1 1 0 0 1 1.5 1.5l-3 3a1 1 0 0 0 0 1.4zm2.8-2.8a1 1 0 0 0-1.4 0l-3 3A3 3 0 0 0 13.3 18l1.5-1.5-1.4-1.4-1.5 1.5a1 1 0 0 1-1.5-1.5l3-3a1 1 0 0 0 0-1.4z" }),
79
+ image: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 4h16a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1zm1 2v9l4-4 3 3 3-3 3 3V6H5zm3 1.5a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3z" }),
80
+ table: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M3 4h18v16H3V4zm2 2v3h5V6H5zm7 0v3h7V6h-7zm-7 5v3h5v-3H5zm7 0v3h7v-3h-7zm-7 5v2h5v-2H5zm7 0v2h7v-2h-7z" }),
81
+ pageBreak: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M6 3h8l4 4v4h-2V8h-3V5H6v6H4V3h2zm-2 13h2v2h2v-2h2v2h2v-2h2v2h2v-2h2v5H4v-5z" }),
82
+ importDocx: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 3h9l5 5v6h-2V9h-4V5H7v14h5v2H5V3zm8 11 4 4 4-4h-3v-4h-2v4h-3z" })
83
+ };
84
+ function ToolbarIcon({ name }) {
85
+ const path = PATHS[name];
86
+ if (!path) {
87
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: name.slice(0, 2) });
88
+ }
89
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { className: "rne-btn-icon", viewBox: "0 0 24 24", "aria-hidden": "true", focusable: "false", children: path });
90
+ }
91
+ function ToolbarButton({ iconName, label, command }) {
92
+ const { state, run } = useEditorContext();
93
+ const active = state ? command.isActive?.(state) ?? false : false;
94
+ const enabled = state ? command.isEnabled ? command.isEnabled(state) : true : false;
95
+ return /* @__PURE__ */ jsxRuntime.jsx(
96
+ "button",
97
+ {
98
+ type: "button",
99
+ className: `rne-btn${active ? " rne-btn--active" : ""}`,
100
+ title: label,
101
+ "aria-label": label,
102
+ "aria-pressed": command.isActive ? active : void 0,
103
+ disabled: !enabled,
104
+ onMouseDown: (e) => e.preventDefault(),
105
+ onClick: () => run(command.run),
106
+ children: /* @__PURE__ */ jsxRuntime.jsx(ToolbarIcon, { name: iconName })
107
+ }
108
+ );
109
+ }
110
+ function ColorButton({ iconName, label, apply, clear, activeColor }) {
111
+ const { run, colorPalette } = useEditorContext();
112
+ const [open, setOpen] = react.useState(false);
113
+ const containerRef = react.useRef(null);
114
+ const buttonRef = react.useRef(null);
115
+ react.useEffect(() => {
116
+ if (!open) return;
117
+ const onDown = (e) => {
118
+ if (containerRef.current && !containerRef.current.contains(e.target)) {
119
+ setOpen(false);
120
+ }
121
+ };
122
+ document.addEventListener("mousedown", onDown);
123
+ return () => document.removeEventListener("mousedown", onDown);
124
+ }, [open]);
125
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rne-color-btn", ref: containerRef, children: [
126
+ /* @__PURE__ */ jsxRuntime.jsx(
127
+ "button",
128
+ {
129
+ ref: buttonRef,
130
+ type: "button",
131
+ className: "rne-btn",
132
+ title: label,
133
+ "aria-label": label,
134
+ "aria-haspopup": "true",
135
+ "aria-expanded": open,
136
+ onMouseDown: (e) => e.preventDefault(),
137
+ onClick: () => setOpen((v) => !v),
138
+ children: /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { display: "flex", flexDirection: "column", alignItems: "center" }, children: [
139
+ /* @__PURE__ */ jsxRuntime.jsx(ToolbarIcon, { name: iconName }),
140
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rne-color-swatch", style: { background: activeColor ?? "#000" } })
141
+ ] })
142
+ }
143
+ ),
144
+ open && /* @__PURE__ */ jsxRuntime.jsxs(
145
+ "div",
146
+ {
147
+ className: "rne-color-popover",
148
+ role: "menu",
149
+ onKeyDown: (e) => {
150
+ if (e.key === "Escape") {
151
+ setOpen(false);
152
+ buttonRef.current?.focus();
153
+ }
154
+ },
155
+ children: [
156
+ colorPalette.map((color) => /* @__PURE__ */ jsxRuntime.jsx(
157
+ "button",
158
+ {
159
+ type: "button",
160
+ className: "rne-color-cell",
161
+ style: { background: color },
162
+ title: color,
163
+ "aria-label": color,
164
+ onMouseDown: (e) => e.preventDefault(),
165
+ onClick: () => {
166
+ run(apply(color));
167
+ setOpen(false);
168
+ }
169
+ },
170
+ color
171
+ )),
172
+ clear && /* @__PURE__ */ jsxRuntime.jsx(
173
+ "button",
174
+ {
175
+ type: "button",
176
+ className: "rne-color-cell",
177
+ style: { background: "#fff", gridColumn: "span 8", height: 22 },
178
+ onMouseDown: (e) => e.preventDefault(),
179
+ onClick: () => {
180
+ run(clear());
181
+ setOpen(false);
182
+ },
183
+ children: "\u2715"
184
+ }
185
+ )
186
+ ]
187
+ }
188
+ )
189
+ ] });
190
+ }
191
+ var FEATURE_OF = {
192
+ bold: "bold",
193
+ italic: "italic",
194
+ underline: "underline",
195
+ strikethrough: "strikethrough",
196
+ superscript: "superscript",
197
+ subscript: "subscript",
198
+ code: "code",
199
+ paragraphStyle: "headings",
200
+ fontFamily: "fontFamily",
201
+ fontSize: "fontSize",
202
+ textColor: "textColor",
203
+ highlight: "highlight",
204
+ clearFormatting: "clearFormatting",
205
+ alignLeft: "alignment",
206
+ alignCenter: "alignment",
207
+ alignRight: "alignment",
208
+ alignJustify: "alignment",
209
+ bulletList: "bulletList",
210
+ orderedList: "orderedList",
211
+ taskList: "taskList",
212
+ indent: "indentation",
213
+ outdent: "indentation",
214
+ blockquote: "blockquote",
215
+ horizontalRule: "horizontalRule",
216
+ link: "link",
217
+ image: "image",
218
+ table: "table",
219
+ pageBreak: "pageBreak",
220
+ importDocx: "docxImport",
221
+ undo: "history",
222
+ redo: "history"
223
+ };
224
+ var COMMAND_ITEMS = /* @__PURE__ */ new Set([
225
+ "undo",
226
+ "redo",
227
+ "bold",
228
+ "italic",
229
+ "underline",
230
+ "strikethrough",
231
+ "superscript",
232
+ "subscript",
233
+ "code",
234
+ "clearFormatting",
235
+ "alignLeft",
236
+ "alignCenter",
237
+ "alignRight",
238
+ "alignJustify",
239
+ "bulletList",
240
+ "orderedList",
241
+ "taskList",
242
+ "indent",
243
+ "outdent",
244
+ "blockquote",
245
+ "horizontalRule",
246
+ "pageBreak"
247
+ ]);
248
+ function activeBlockValue(state) {
249
+ if (!state) return "p";
250
+ const node = state.selection.$head.parent;
251
+ if (node.type.name === "heading") return `h${node.attrs.level}`;
252
+ return "p";
253
+ }
254
+ function Toolbar({ config }) {
255
+ const ctx = useEditorContext();
256
+ const { state, commands, strings, features, run, fontFamilies, fontSizes, importDocx: importDocx2 } = ctx;
257
+ const groups = config?.groups ?? chunkU3O54IYI_cjs.DEFAULT_TOOLBAR_GROUPS;
258
+ const sticky = config?.sticky ?? true;
259
+ const toolbarRef = react.useRef(null);
260
+ const fileInputRef = react.useRef(null);
261
+ const onImportFile = react.useCallback(
262
+ async (e) => {
263
+ const file = e.target.files?.[0];
264
+ e.target.value = "";
265
+ if (!file) return;
266
+ try {
267
+ await importDocx2(file);
268
+ } catch (err) {
269
+ console.error("[react-next-editor] DOCX import failed:", err);
270
+ }
271
+ },
272
+ [importDocx2]
273
+ );
274
+ const onToolbarKeyDown = react.useCallback((e) => {
275
+ if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(e.key)) return;
276
+ const active = document.activeElement;
277
+ if (active?.tagName === "SELECT") return;
278
+ const root = toolbarRef.current;
279
+ if (!root) return;
280
+ const items = Array.from(root.querySelectorAll("button:not([disabled])"));
281
+ if (items.length === 0) return;
282
+ const idx = active ? items.indexOf(active) : -1;
283
+ if (idx === -1) return;
284
+ e.preventDefault();
285
+ let next = idx;
286
+ if (e.key === "ArrowRight") next = (idx + 1) % items.length;
287
+ else if (e.key === "ArrowLeft") next = (idx - 1 + items.length) % items.length;
288
+ else if (e.key === "Home") next = 0;
289
+ else if (e.key === "End") next = items.length - 1;
290
+ items[next]?.focus();
291
+ }, []);
292
+ const renderedGroups = react.useMemo(() => {
293
+ return groups.map((group) => group.filter((id) => isItemAvailable(id, features, commands))).filter((group) => group.length > 0);
294
+ }, [groups, features, commands]);
295
+ const labelFor = (id) => strings[id] ?? id;
296
+ function renderItem(id) {
297
+ if (COMMAND_ITEMS.has(id)) {
298
+ const command = commands.registry[id];
299
+ if (!command) return null;
300
+ return /* @__PURE__ */ jsxRuntime.jsx(ToolbarButton, { iconName: id, label: labelFor(id), command }, id);
301
+ }
302
+ switch (id) {
303
+ case "paragraphStyle":
304
+ return /* @__PURE__ */ jsxRuntime.jsxs(
305
+ "select",
306
+ {
307
+ className: "rne-select",
308
+ "aria-label": strings.paragraphStyle,
309
+ value: activeBlockValue(state),
310
+ onMouseDown: (e) => e.stopPropagation(),
311
+ onChange: (e) => {
312
+ const v = e.target.value;
313
+ if (v === "p") run(commands.blocks.setParagraph());
314
+ else run(commands.blocks.setHeading(Number(v.slice(1))));
315
+ },
316
+ children: [
317
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "p", children: strings.paragraph }),
318
+ [1, 2, 3, 4, 5, 6].map((lvl) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: `h${lvl}`, children: `${strings.heading} ${lvl}` }, lvl))
319
+ ]
320
+ },
321
+ id
322
+ );
323
+ case "fontFamily":
324
+ return /* @__PURE__ */ jsxRuntime.jsxs(
325
+ "select",
326
+ {
327
+ className: "rne-select",
328
+ "aria-label": strings.fontFamily,
329
+ value: state ? commands.marks.getActiveFontFamily(state) ?? "" : "",
330
+ onChange: (e) => {
331
+ const v = e.target.value;
332
+ run(v ? commands.marks.setFontFamily(v) : commands.marks.clearFontFamily());
333
+ },
334
+ children: [
335
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "", children: strings.fontFamily }),
336
+ fontFamilies.map((f) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: f, style: { fontFamily: f }, children: f }, f))
337
+ ]
338
+ },
339
+ id
340
+ );
341
+ case "fontSize":
342
+ return /* @__PURE__ */ jsxRuntime.jsxs(
343
+ "select",
344
+ {
345
+ className: "rne-select",
346
+ style: { maxWidth: 70 },
347
+ "aria-label": strings.fontSize,
348
+ value: state ? commands.marks.getActiveFontSize(state) ?? "" : "",
349
+ onChange: (e) => {
350
+ const v = e.target.value;
351
+ run(v ? commands.marks.setFontSize(Number(v)) : commands.marks.clearFontSize());
352
+ },
353
+ children: [
354
+ /* @__PURE__ */ jsxRuntime.jsx("option", { value: "", children: strings.fontSize }),
355
+ fontSizes.map((s) => /* @__PURE__ */ jsxRuntime.jsx("option", { value: s, children: s }, s))
356
+ ]
357
+ },
358
+ id
359
+ );
360
+ case "textColor":
361
+ return /* @__PURE__ */ jsxRuntime.jsx(
362
+ ColorButton,
363
+ {
364
+ iconName: "textColor",
365
+ label: strings.textColor,
366
+ apply: (c) => commands.marks.setTextColor(c),
367
+ clear: () => commands.marks.clearTextColor(),
368
+ activeColor: state ? commands.marks.getActiveTextColor(state) : null
369
+ },
370
+ id
371
+ );
372
+ case "highlight":
373
+ return /* @__PURE__ */ jsxRuntime.jsx(
374
+ ColorButton,
375
+ {
376
+ iconName: "highlight",
377
+ label: strings.highlight,
378
+ apply: (c) => commands.marks.setHighlight(c),
379
+ clear: () => commands.marks.clearHighlight()
380
+ },
381
+ id
382
+ );
383
+ case "link":
384
+ return /* @__PURE__ */ jsxRuntime.jsx(
385
+ "button",
386
+ {
387
+ type: "button",
388
+ className: "rne-btn",
389
+ title: strings.link,
390
+ "aria-label": strings.link,
391
+ onMouseDown: (e) => e.preventDefault(),
392
+ onClick: () => {
393
+ if (!state) return;
394
+ const prev = commands.links.getActiveLink(state);
395
+ const url = window.prompt(strings.linkPrompt, prev?.href ?? "https://");
396
+ if (url === null) return;
397
+ if (url.trim() === "") run(commands.links.removeLink);
398
+ else run(commands.links.setLink({ href: url.trim() }));
399
+ },
400
+ children: /* @__PURE__ */ jsxRuntime.jsx(ToolbarIcon, { name: "link" })
401
+ },
402
+ id
403
+ );
404
+ case "image":
405
+ return /* @__PURE__ */ jsxRuntime.jsx(
406
+ "button",
407
+ {
408
+ type: "button",
409
+ className: "rne-btn",
410
+ title: strings.image,
411
+ "aria-label": strings.image,
412
+ onMouseDown: (e) => e.preventDefault(),
413
+ onClick: () => {
414
+ const url = window.prompt(strings.imagePrompt, "https://");
415
+ if (!url || !url.trim()) return;
416
+ const alt = window.prompt(strings.imageAltPrompt, "");
417
+ run(commands.insert.image({ src: url.trim(), alt: alt?.trim() || null }));
418
+ },
419
+ children: /* @__PURE__ */ jsxRuntime.jsx(ToolbarIcon, { name: "image" })
420
+ },
421
+ id
422
+ );
423
+ case "table":
424
+ return /* @__PURE__ */ jsxRuntime.jsx(
425
+ "button",
426
+ {
427
+ type: "button",
428
+ className: "rne-btn",
429
+ title: strings.insertTable,
430
+ "aria-label": strings.insertTable,
431
+ onMouseDown: (e) => e.preventDefault(),
432
+ onClick: () => run(commands.insert.table(3, 3, true)),
433
+ children: /* @__PURE__ */ jsxRuntime.jsx(ToolbarIcon, { name: "table" })
434
+ },
435
+ id
436
+ );
437
+ case "importDocx":
438
+ return /* @__PURE__ */ jsxRuntime.jsx(
439
+ "button",
440
+ {
441
+ type: "button",
442
+ className: "rne-btn",
443
+ title: strings.importDocx,
444
+ "aria-label": strings.importDocx,
445
+ onMouseDown: (e) => e.preventDefault(),
446
+ onClick: () => fileInputRef.current?.click(),
447
+ children: /* @__PURE__ */ jsxRuntime.jsx(ToolbarIcon, { name: "importDocx" })
448
+ },
449
+ id
450
+ );
451
+ default:
452
+ return null;
453
+ }
454
+ }
455
+ return /* @__PURE__ */ jsxRuntime.jsxs(
456
+ "div",
457
+ {
458
+ ref: toolbarRef,
459
+ className: `rne-toolbar${sticky ? " rne-toolbar--sticky" : ""}`,
460
+ role: "toolbar",
461
+ "aria-label": "Formatting",
462
+ onKeyDown: onToolbarKeyDown,
463
+ children: [
464
+ renderedGroups.map((group, gi) => /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
465
+ gi > 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "rne-toolbar-separator", "aria-hidden": "true" }),
466
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rne-toolbar-group", children: group.map(renderItem) })
467
+ ] }, gi)),
468
+ /* @__PURE__ */ jsxRuntime.jsx(
469
+ "input",
470
+ {
471
+ ref: fileInputRef,
472
+ type: "file",
473
+ accept: ".docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
474
+ style: { display: "none" },
475
+ "aria-hidden": "true",
476
+ tabIndex: -1,
477
+ onChange: onImportFile
478
+ }
479
+ )
480
+ ]
481
+ }
482
+ );
483
+ }
484
+ function isItemAvailable(id, features, commands) {
485
+ if (id === "separator") return false;
486
+ const feature = FEATURE_OF[id];
487
+ if (feature && !features[feature]) return false;
488
+ if (COMMAND_ITEMS.has(id) && !commands.registry[id]) return false;
489
+ return true;
490
+ }
491
+ var STATUS_LABEL = {
492
+ idle: "",
493
+ savingLocal: "Saving\u2026",
494
+ savedLocal: "Saved locally",
495
+ syncing: "Syncing\u2026",
496
+ synced: "Synced",
497
+ syncFailed: "Sync failed",
498
+ offline: "Offline"
499
+ };
500
+ function StatusBar({ saveStatus, hasPersistence }) {
501
+ const { state, strings } = useEditorContext();
502
+ const doc = state?.doc;
503
+ const [stats, setStats] = react.useState(null);
504
+ react.useEffect(() => {
505
+ if (!doc) {
506
+ setStats(null);
507
+ return;
508
+ }
509
+ const id = setTimeout(() => setStats(chunkDBSFCCBG_cjs.countDocument(doc)), 300);
510
+ return () => clearTimeout(id);
511
+ }, [doc]);
512
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rne-statusbar", children: [
513
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: stats ? `${stats.words} ${strings.words} \xB7 ${stats.characters} ${strings.characters}` : "" }),
514
+ hasPersistence && saveStatus !== "idle" && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "rne-status-badge", children: [
515
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: `rne-status-dot rne-status-dot--${saveStatus}` }),
516
+ STATUS_LABEL[saveStatus]
517
+ ] })
518
+ ] });
519
+ }
520
+ function resolveConfig(props) {
521
+ return {
522
+ features: { ...chunkU3O54IYI_cjs.DEFAULT_FEATURES, ...props.features },
523
+ page: {
524
+ ...chunkU3O54IYI_cjs.DEFAULT_PAGE,
525
+ ...props.page,
526
+ margins: { ...chunkU3O54IYI_cjs.DEFAULT_PAGE.margins, ...props.page?.margins }
527
+ },
528
+ strings: { ...chunkU3O54IYI_cjs.DEFAULT_STRINGS, ...props.strings },
529
+ fontFamilies: props.fontFamilies ?? chunkU3O54IYI_cjs.DEFAULT_FONT_FAMILIES,
530
+ fontSizes: props.fontSizes ?? chunkU3O54IYI_cjs.DEFAULT_FONT_SIZES,
531
+ colorPalette: props.colorPalette ?? chunkU3O54IYI_cjs.DEFAULT_COLOR_PALETTE,
532
+ editable: !(props.readOnly || props.mode === "readonly"),
533
+ placeholder: props.placeholder
534
+ };
535
+ }
536
+ var PX_PER_MM = 96 / 25.4;
537
+ var PAGE_GAP_PX = 24;
538
+ function computePaginationGeometry(page) {
539
+ if (page.pagination !== "visual") return null;
540
+ const { width, height } = chunkU3O54IYI_cjs.resolvePageDimensions(page);
541
+ const m = page.margins;
542
+ const pageWidthPx = width * PX_PER_MM;
543
+ const pageHeightPx = height * PX_PER_MM;
544
+ const marginTopPx = m.top * PX_PER_MM;
545
+ const marginBottomPx = m.bottom * PX_PER_MM;
546
+ const marginLeftPx = m.left * PX_PER_MM;
547
+ const contentWidthPx = Math.max(1, (width - m.left - m.right) * PX_PER_MM);
548
+ const contentHeightPx = pageHeightPx - marginTopPx - marginBottomPx;
549
+ if (contentHeightPx <= 0) return null;
550
+ return {
551
+ pageWidthPx,
552
+ pageHeightPx,
553
+ marginTopPx,
554
+ marginBottomPx,
555
+ marginLeftPx,
556
+ contentWidthPx,
557
+ contentHeightPx,
558
+ interPageOffsetPx: marginBottomPx + PAGE_GAP_PX + marginTopPx
559
+ };
560
+ }
561
+ var EditorInner = react.forwardRef(function EditorInner2(props, ref) {
562
+ const mountRef = react.useRef(null);
563
+ const viewRef = react.useRef(null);
564
+ const persistenceRef = react.useRef(null);
565
+ const pageBgRef = react.useRef(null);
566
+ const remeasureRef = react.useRef(null);
567
+ const propsRef = react.useRef(props);
568
+ propsRef.current = props;
569
+ const config = react.useMemo(() => resolveConfig(props), [props]);
570
+ const cfgRef = react.useRef(config);
571
+ cfgRef.current = config;
572
+ const featureKey = react.useMemo(() => JSON.stringify(config.features), [config.features]);
573
+ const engine = react.useMemo(() => {
574
+ const schema = chunkDBSFCCBG_cjs.buildSchema(config.features);
575
+ const commands = chunkDBSFCCBG_cjs.createCommands(schema);
576
+ return { schema, commands };
577
+ }, [featureKey]);
578
+ const [editorState, setEditorState] = react.useState(null);
579
+ const [saveStatus, setSaveStatus] = react.useState("idle");
580
+ const [ready, setReady] = react.useState(false);
581
+ const getJSON = react.useCallback(() => {
582
+ const view = viewRef.current;
583
+ return view ? view.state.doc.toJSON() : chunkDBSFCCBG_cjs.createDoc(engine.schema, null).toJSON();
584
+ }, [engine.schema]);
585
+ const setContent = react.useCallback(
586
+ (content) => {
587
+ const view = viewRef.current;
588
+ if (!view) return;
589
+ const doc = chunkDBSFCCBG_cjs.createDoc(view.state.schema, content);
590
+ const state = prosemirrorState.EditorState.create({ doc, plugins: view.state.plugins });
591
+ view.updateState(state);
592
+ setEditorState(state);
593
+ },
594
+ []
595
+ );
596
+ const importDocxIntoEditor = react.useCallback(
597
+ async (file) => {
598
+ const view = viewRef.current;
599
+ if (!view) return { warnings: [] };
600
+ const { importDocx: importDocx2 } = await import('./docx-N2LKIOK3.cjs');
601
+ const result = await importDocx2(file, view.state.schema);
602
+ const node = prosemirrorModel.Node.fromJSON(view.state.schema, result.doc);
603
+ const v = viewRef.current;
604
+ if (v) {
605
+ const tr = v.state.tr.replaceWith(0, v.state.doc.content.size, node.content);
606
+ v.dispatch(tr.scrollIntoView());
607
+ }
608
+ return { warnings: result.warnings };
609
+ },
610
+ []
611
+ );
612
+ const handle = react.useMemo(
613
+ () => ({
614
+ getJSON,
615
+ getText: (options) => chunkNJCEHQV3_cjs.documentToText(getJSON(), options),
616
+ getHTML: () => chunkTI44I654_cjs.documentToHtml(getJSON()),
617
+ setContent,
618
+ importDocx: importDocxIntoEditor,
619
+ focus: () => viewRef.current?.focus(),
620
+ isDirty: () => persistenceRef.current?.isDirty() ?? false,
621
+ save: async () => {
622
+ await persistenceRef.current?.saveNow(getJSON());
623
+ },
624
+ clearLocalData: async () => {
625
+ await persistenceRef.current?.clearLocal();
626
+ },
627
+ exportAs: (format, filename) => chunkGFNFJ3FL_cjs.exportDocument(getJSON(), format, {
628
+ filename: filename ?? propsRef.current.documentId,
629
+ page: cfgRef.current.page,
630
+ title: filename ?? propsRef.current.documentId
631
+ }),
632
+ getView: () => viewRef.current,
633
+ getState: () => viewRef.current?.state ?? null,
634
+ getSchema: () => viewRef.current?.state.schema ?? null
635
+ }),
636
+ [getJSON, setContent, importDocxIntoEditor]
637
+ );
638
+ react.useImperativeHandle(ref, () => handle, [handle]);
639
+ react.useEffect(() => {
640
+ const mount = mountRef.current;
641
+ if (!mount) return;
642
+ void chunk5F6SPYCN_cjs.preloadSanitizer();
643
+ const paginated2 = cfgRef.current.page.pagination === "visual";
644
+ const plugins = chunkDBSFCCBG_cjs.buildPlugins(engine.schema, {
645
+ placeholder: cfgRef.current.placeholder,
646
+ history: cfgRef.current.features.history,
647
+ extraPlugins: propsRef.current.extensions?.plugins,
648
+ pagination: paginated2 ? {
649
+ getGeometry: () => computePaginationGeometry(cfgRef.current.page),
650
+ getBackgroundLayer: () => pageBgRef.current,
651
+ header: cfgRef.current.page.header,
652
+ footer: cfgRef.current.page.footer,
653
+ register: (fn) => {
654
+ remeasureRef.current = fn;
655
+ }
656
+ } : void 0
657
+ });
658
+ const initialContent = propsRef.current.value ?? propsRef.current.initialContent ?? null;
659
+ const state = chunkDBSFCCBG_cjs.createEditorState({ schema: engine.schema, plugins, content: initialContent });
660
+ const view = new prosemirrorView.EditorView(mount, {
661
+ state,
662
+ editable: () => !(propsRef.current.readOnly || propsRef.current.mode === "readonly"),
663
+ attributes: {
664
+ class: "rne-prosemirror",
665
+ role: "textbox",
666
+ "aria-multiline": "true",
667
+ "aria-label": propsRef.current.ariaLabel ?? "Document editor",
668
+ dir: propsRef.current.dir ?? "ltr"
669
+ },
670
+ dispatchTransaction(tr) {
671
+ const v = viewRef.current;
672
+ if (!v) return;
673
+ const newState = v.state.apply(tr);
674
+ v.updateState(newState);
675
+ setEditorState(newState);
676
+ const p = propsRef.current;
677
+ if (tr.docChanged) {
678
+ const json = newState.doc.toJSON();
679
+ p.onChange?.(json, handle);
680
+ persistenceRef.current?.scheduleSave(json);
681
+ }
682
+ if (tr.selectionSet) {
683
+ p.onSelectionChange?.(newState);
684
+ }
685
+ }
686
+ });
687
+ viewRef.current = view;
688
+ setEditorState(view.state);
689
+ setReady(true);
690
+ propsRef.current.onReady?.(handle);
691
+ return () => {
692
+ view.destroy();
693
+ viewRef.current = null;
694
+ setReady(false);
695
+ };
696
+ }, [engine]);
697
+ react.useEffect(() => {
698
+ viewRef.current?.setProps({
699
+ editable: () => config.editable
700
+ });
701
+ setEditorState((s) => s);
702
+ }, [config.editable]);
703
+ react.useEffect(() => {
704
+ const documentId = props.documentId;
705
+ const persistenceEnabled = props.persistence?.enabled ?? !!documentId;
706
+ if (!documentId || !persistenceEnabled || !ready) return;
707
+ const store = props.persistence?.store ?? new chunk3QWXTDLY_cjs.IndexedDBStore();
708
+ const sync = props.sync;
709
+ const auto = sync?.auto ?? true;
710
+ let engine2 = null;
711
+ let monitor = null;
712
+ const handleStatus = (status, detail) => {
713
+ setSaveStatus(status);
714
+ propsRef.current.onSaveStatusChange?.(status, detail);
715
+ if (status === "savedLocal" && engine2 && auto && (monitor?.isOnline() ?? true)) {
716
+ void engine2.flush();
717
+ }
718
+ };
719
+ const persistence = new chunk3QWXTDLY_cjs.DocumentPersistence({
720
+ documentId,
721
+ store,
722
+ debounceMs: props.persistence?.debounceMs,
723
+ metadata: props.metadata,
724
+ onStatus: handleStatus
725
+ });
726
+ persistenceRef.current = persistence;
727
+ if (sync?.remote) {
728
+ engine2 = new chunk3QWXTDLY_cjs.SyncEngine({
729
+ store,
730
+ remote: sync.remote,
731
+ maxAttempts: sync.maxAttempts,
732
+ onStatus: handleStatus,
733
+ onConflict: sync.onConflict
734
+ });
735
+ const remotePing = sync.remote.ping?.bind(sync.remote);
736
+ monitor = new chunk3QWXTDLY_cjs.ConnectivityMonitor({
737
+ ping: remotePing,
738
+ intervalMs: sync.pingIntervalMs,
739
+ onChange: (online) => {
740
+ if (online) {
741
+ if (auto && engine2) void engine2.flush();
742
+ } else {
743
+ handleStatus("offline");
744
+ }
745
+ }
746
+ });
747
+ monitor.start();
748
+ if (auto) void engine2.flush();
749
+ }
750
+ if (props.persistence?.requestPersistent !== false) {
751
+ void chunk3QWXTDLY_cjs.requestPersistentStorage();
752
+ }
753
+ let cancelled = false;
754
+ void (async () => {
755
+ const record = await persistence.load();
756
+ if (cancelled || !record) return;
757
+ if (propsRef.current.value == null) {
758
+ setContent(record.doc);
759
+ }
760
+ })();
761
+ return () => {
762
+ cancelled = true;
763
+ monitor?.stop();
764
+ engine2?.cancel();
765
+ void persistence.destroy();
766
+ persistenceRef.current = null;
767
+ };
768
+ }, [props.documentId, ready, props.sync?.remote]);
769
+ react.useEffect(() => {
770
+ const view = viewRef.current;
771
+ if (!view || props.value == null) return;
772
+ const current = JSON.stringify(view.state.doc.toJSON());
773
+ const next = JSON.stringify(props.value);
774
+ if (current === next) return;
775
+ const doc = chunkDBSFCCBG_cjs.createDoc(view.state.schema, props.value);
776
+ const selectionPos = Math.min(view.state.selection.from, doc.content.size);
777
+ const state = prosemirrorState.EditorState.create({ doc, plugins: view.state.plugins });
778
+ const withSel = state.apply(
779
+ state.tr.setSelection(prosemirrorState.TextSelection.create(state.doc, Math.max(0, selectionPos)))
780
+ );
781
+ view.updateState(withSel);
782
+ setEditorState(withSel);
783
+ }, [props.value]);
784
+ const runCommand = react.useCallback((command) => {
785
+ const view = viewRef.current;
786
+ if (!view) return false;
787
+ const result = command(view.state, view.dispatch, view);
788
+ view.focus();
789
+ return result;
790
+ }, []);
791
+ const contextValue = react.useMemo(
792
+ () => ({
793
+ view: viewRef.current,
794
+ state: editorState,
795
+ schema: engine.schema,
796
+ commands: engine.commands,
797
+ strings: config.strings,
798
+ features: config.features,
799
+ fontFamilies: config.fontFamilies,
800
+ fontSizes: config.fontSizes,
801
+ colorPalette: config.colorPalette,
802
+ editable: config.editable,
803
+ run: runCommand,
804
+ importDocx: importDocxIntoEditor
805
+ }),
806
+ [editorState, engine, config, runCommand, importDocxIntoEditor]
807
+ );
808
+ const { width } = chunkU3O54IYI_cjs.resolvePageDimensions(config.page);
809
+ const showChrome = config.page.showPageChrome;
810
+ const paginated = config.page.pagination === "visual";
811
+ const pageGeometryKey = react.useMemo(
812
+ () => JSON.stringify({
813
+ p: config.page.pagination,
814
+ s: config.page.size,
815
+ o: config.page.orientation,
816
+ w: config.page.widthMm,
817
+ h: config.page.heightMm,
818
+ m: config.page.margins,
819
+ hdr: config.page.header,
820
+ ftr: config.page.footer
821
+ }),
822
+ [config.page]
823
+ );
824
+ react.useEffect(() => {
825
+ if (paginated) remeasureRef.current?.();
826
+ }, [pageGeometryKey, paginated]);
827
+ const geometry = react.useMemo(
828
+ () => computePaginationGeometry(config.page),
829
+ // eslint-disable-next-line react-hooks/exhaustive-deps
830
+ [pageGeometryKey]
831
+ );
832
+ const rootStyle = react.useMemo(() => {
833
+ const base = {
834
+ ...chunkU3O54IYI_cjs.themeToCssVars(props.theme),
835
+ "--rne-page-width": `${width}mm`,
836
+ "--rne-page-padding": `${config.page.margins.top}mm ${config.page.margins.right}mm ${config.page.margins.bottom}mm ${config.page.margins.left}mm`
837
+ };
838
+ if (geometry) {
839
+ base["--rne-page-w"] = `${geometry.pageWidthPx}px`;
840
+ base["--rne-page-h"] = `${geometry.pageHeightPx}px`;
841
+ base["--rne-content-w"] = `${geometry.contentWidthPx}px`;
842
+ base["--rne-mt"] = `${geometry.marginTopPx}px`;
843
+ base["--rne-ml"] = `${geometry.marginLeftPx}px`;
844
+ }
845
+ return { ...base, ...props.style };
846
+ }, [props.theme, props.style, width, config.page.margins, geometry]);
847
+ const toolbarEnabled = props.toolbar !== false && (props.toolbar?.enabled ?? true) && config.editable;
848
+ const statusBarEnabled = props.statusBar ?? true;
849
+ return /* @__PURE__ */ jsxRuntime.jsx(EditorContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsxs(
850
+ "div",
851
+ {
852
+ className: `rne-root${props.className ? ` ${props.className}` : ""}`,
853
+ style: rootStyle,
854
+ "data-ready": ready,
855
+ dir: props.dir ?? "ltr",
856
+ children: [
857
+ toolbarEnabled && /* @__PURE__ */ jsxRuntime.jsx(Toolbar, { config: props.toolbar || void 0 }),
858
+ props.children,
859
+ /* @__PURE__ */ jsxRuntime.jsx(
860
+ "div",
861
+ {
862
+ className: `rne-canvas${showChrome ? "" : " rne-canvas--plain"}${paginated ? " rne-canvas--paged" : ""}`,
863
+ children: paginated ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rne-paged", children: [
864
+ /* @__PURE__ */ jsxRuntime.jsx("div", { ref: pageBgRef, className: "rne-page-bg", "aria-hidden": "true" }),
865
+ /* @__PURE__ */ jsxRuntime.jsx("div", { ref: mountRef, className: "rne-mount rne-mount--paged" })
866
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "rne-page", children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: mountRef, className: "rne-mount" }) })
867
+ }
868
+ ),
869
+ statusBarEnabled && /* @__PURE__ */ jsxRuntime.jsx(StatusBar, { saveStatus, hasPersistence: !!props.documentId })
870
+ ]
871
+ }
872
+ ) });
873
+ });
874
+ var Editor = react.forwardRef(function Editor2(props, ref) {
875
+ return /* @__PURE__ */ jsxRuntime.jsx(EditorErrorBoundary, { onError: props.onError, children: /* @__PURE__ */ jsxRuntime.jsx(EditorInner, { ...props, ref }) });
876
+ });
877
+
878
+ Object.defineProperty(exports, "buildPlugins", {
879
+ enumerable: true,
880
+ get: function () { return chunkDBSFCCBG_cjs.buildPlugins; }
881
+ });
882
+ Object.defineProperty(exports, "buildSchema", {
883
+ enumerable: true,
884
+ get: function () { return chunkDBSFCCBG_cjs.buildSchema; }
885
+ });
886
+ Object.defineProperty(exports, "countDocument", {
887
+ enumerable: true,
888
+ get: function () { return chunkDBSFCCBG_cjs.countDocument; }
889
+ });
890
+ Object.defineProperty(exports, "createCommands", {
891
+ enumerable: true,
892
+ get: function () { return chunkDBSFCCBG_cjs.createCommands; }
893
+ });
894
+ Object.defineProperty(exports, "createDoc", {
895
+ enumerable: true,
896
+ get: function () { return chunkDBSFCCBG_cjs.createDoc; }
897
+ });
898
+ Object.defineProperty(exports, "createEditorState", {
899
+ enumerable: true,
900
+ get: function () { return chunkDBSFCCBG_cjs.createEditorState; }
901
+ });
902
+ Object.defineProperty(exports, "defaultSchema", {
903
+ enumerable: true,
904
+ get: function () { return chunkDBSFCCBG_cjs.defaultSchema; }
905
+ });
906
+ Object.defineProperty(exports, "downloadBlob", {
907
+ enumerable: true,
908
+ get: function () { return chunkGFNFJ3FL_cjs.downloadBlob; }
909
+ });
910
+ Object.defineProperty(exports, "downloadText", {
911
+ enumerable: true,
912
+ get: function () { return chunkGFNFJ3FL_cjs.downloadText; }
913
+ });
914
+ Object.defineProperty(exports, "exportDocument", {
915
+ enumerable: true,
916
+ get: function () { return chunkGFNFJ3FL_cjs.exportDocument; }
917
+ });
918
+ Object.defineProperty(exports, "printDocumentToPdf", {
919
+ enumerable: true,
920
+ get: function () { return chunkGFNFJ3FL_cjs.printDocumentToPdf; }
921
+ });
922
+ Object.defineProperty(exports, "ConflictError", {
923
+ enumerable: true,
924
+ get: function () { return chunk3QWXTDLY_cjs.ConflictError; }
925
+ });
926
+ Object.defineProperty(exports, "ConnectivityMonitor", {
927
+ enumerable: true,
928
+ get: function () { return chunk3QWXTDLY_cjs.ConnectivityMonitor; }
929
+ });
930
+ Object.defineProperty(exports, "DocumentPersistence", {
931
+ enumerable: true,
932
+ get: function () { return chunk3QWXTDLY_cjs.DocumentPersistence; }
933
+ });
934
+ Object.defineProperty(exports, "IndexedDBStore", {
935
+ enumerable: true,
936
+ get: function () { return chunk3QWXTDLY_cjs.IndexedDBStore; }
937
+ });
938
+ Object.defineProperty(exports, "MemoryStore", {
939
+ enumerable: true,
940
+ get: function () { return chunk3QWXTDLY_cjs.MemoryStore; }
941
+ });
942
+ Object.defineProperty(exports, "SyncEngine", {
943
+ enumerable: true,
944
+ get: function () { return chunk3QWXTDLY_cjs.SyncEngine; }
945
+ });
946
+ Object.defineProperty(exports, "requestPersistentStorage", {
947
+ enumerable: true,
948
+ get: function () { return chunk3QWXTDLY_cjs.requestPersistentStorage; }
949
+ });
950
+ Object.defineProperty(exports, "documentToDocxBlob", {
951
+ enumerable: true,
952
+ get: function () { return chunkNJCEHQV3_cjs.documentToDocxBlob; }
953
+ });
954
+ Object.defineProperty(exports, "documentToDocxBuffer", {
955
+ enumerable: true,
956
+ get: function () { return chunkNJCEHQV3_cjs.documentToDocxBuffer; }
957
+ });
958
+ Object.defineProperty(exports, "documentToText", {
959
+ enumerable: true,
960
+ get: function () { return chunkNJCEHQV3_cjs.documentToText; }
961
+ });
962
+ Object.defineProperty(exports, "importDocx", {
963
+ enumerable: true,
964
+ get: function () { return chunkODHABIIC_cjs.importDocx; }
965
+ });
966
+ Object.defineProperty(exports, "buildPrintDocument", {
967
+ enumerable: true,
968
+ get: function () { return chunkTI44I654_cjs.buildPrintDocument; }
969
+ });
970
+ Object.defineProperty(exports, "documentToHtml", {
971
+ enumerable: true,
972
+ get: function () { return chunkTI44I654_cjs.documentToHtml; }
973
+ });
974
+ Object.defineProperty(exports, "sanitizeHtml", {
975
+ enumerable: true,
976
+ get: function () { return chunk5F6SPYCN_cjs.sanitizeHtml; }
977
+ });
978
+ Object.defineProperty(exports, "sanitizeImageSrc", {
979
+ enumerable: true,
980
+ get: function () { return chunk5F6SPYCN_cjs.sanitizeImageSrc; }
981
+ });
982
+ Object.defineProperty(exports, "sanitizeUrl", {
983
+ enumerable: true,
984
+ get: function () { return chunk5F6SPYCN_cjs.sanitizeUrl; }
985
+ });
986
+ Object.defineProperty(exports, "DEFAULT_COLOR_PALETTE", {
987
+ enumerable: true,
988
+ get: function () { return chunkU3O54IYI_cjs.DEFAULT_COLOR_PALETTE; }
989
+ });
990
+ Object.defineProperty(exports, "DEFAULT_FEATURES", {
991
+ enumerable: true,
992
+ get: function () { return chunkU3O54IYI_cjs.DEFAULT_FEATURES; }
993
+ });
994
+ Object.defineProperty(exports, "DEFAULT_FONT_FAMILIES", {
995
+ enumerable: true,
996
+ get: function () { return chunkU3O54IYI_cjs.DEFAULT_FONT_FAMILIES; }
997
+ });
998
+ Object.defineProperty(exports, "DEFAULT_FONT_SIZES", {
999
+ enumerable: true,
1000
+ get: function () { return chunkU3O54IYI_cjs.DEFAULT_FONT_SIZES; }
1001
+ });
1002
+ Object.defineProperty(exports, "DEFAULT_PAGE", {
1003
+ enumerable: true,
1004
+ get: function () { return chunkU3O54IYI_cjs.DEFAULT_PAGE; }
1005
+ });
1006
+ Object.defineProperty(exports, "DEFAULT_STRINGS", {
1007
+ enumerable: true,
1008
+ get: function () { return chunkU3O54IYI_cjs.DEFAULT_STRINGS; }
1009
+ });
1010
+ Object.defineProperty(exports, "DEFAULT_TOOLBAR_GROUPS", {
1011
+ enumerable: true,
1012
+ get: function () { return chunkU3O54IYI_cjs.DEFAULT_TOOLBAR_GROUPS; }
1013
+ });
1014
+ Object.defineProperty(exports, "PAGE_DIMENSIONS_MM", {
1015
+ enumerable: true,
1016
+ get: function () { return chunkU3O54IYI_cjs.PAGE_DIMENSIONS_MM; }
1017
+ });
1018
+ Object.defineProperty(exports, "resolvePageDimensions", {
1019
+ enumerable: true,
1020
+ get: function () { return chunkU3O54IYI_cjs.resolvePageDimensions; }
1021
+ });
1022
+ Object.defineProperty(exports, "themeToCssVars", {
1023
+ enumerable: true,
1024
+ get: function () { return chunkU3O54IYI_cjs.themeToCssVars; }
1025
+ });
1026
+ exports.Editor = Editor;
1027
+ exports.EditorContext = EditorContext;
1028
+ exports.EditorErrorBoundary = EditorErrorBoundary;
1029
+ exports.StatusBar = StatusBar;
1030
+ exports.Toolbar = Toolbar;
1031
+ exports.ToolbarButton = ToolbarButton;
1032
+ exports.ToolbarIcon = ToolbarIcon;
1033
+ exports.useEditorContext = useEditorContext;
1034
+ //# sourceMappingURL=index.cjs.map
1035
+ //# sourceMappingURL=index.cjs.map