@richscripts/richtexteditor 2.4.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 (184) hide show
  1. package/README.md +360 -0
  2. package/admin/index.d.ts +100 -0
  3. package/admin/index.js +94 -0
  4. package/angular/component.ts +284 -0
  5. package/angular/index.d.ts +80 -0
  6. package/angular/index.ts +24 -0
  7. package/headless/index.d.ts +65 -0
  8. package/headless/index.js +272 -0
  9. package/index.d.ts +1412 -0
  10. package/integrations/shared.d.ts +138 -0
  11. package/integrations/shared.js +5182 -0
  12. package/package.json +130 -0
  13. package/react/index.d.ts +104 -0
  14. package/react/index.js +310 -0
  15. package/richtexteditor/CHANGELOG.md +1876 -0
  16. package/richtexteditor/all_plugins.js +31125 -0
  17. package/richtexteditor/all_plugins.min.js +78 -0
  18. package/richtexteditor/lang/rte-lang-af.js +193 -0
  19. package/richtexteditor/lang/rte-lang-ar.js +193 -0
  20. package/richtexteditor/lang/rte-lang-bg.js +193 -0
  21. package/richtexteditor/lang/rte-lang-bn.js +193 -0
  22. package/richtexteditor/lang/rte-lang-bs.js +193 -0
  23. package/richtexteditor/lang/rte-lang-ca.js +193 -0
  24. package/richtexteditor/lang/rte-lang-cs.js +193 -0
  25. package/richtexteditor/lang/rte-lang-cy.js +193 -0
  26. package/richtexteditor/lang/rte-lang-da.js +193 -0
  27. package/richtexteditor/lang/rte-lang-de.js +193 -0
  28. package/richtexteditor/lang/rte-lang-el.js +193 -0
  29. package/richtexteditor/lang/rte-lang-en.js +6 -0
  30. package/richtexteditor/lang/rte-lang-es.js +193 -0
  31. package/richtexteditor/lang/rte-lang-et.js +193 -0
  32. package/richtexteditor/lang/rte-lang-fa.js +193 -0
  33. package/richtexteditor/lang/rte-lang-fi.js +193 -0
  34. package/richtexteditor/lang/rte-lang-fil.js +193 -0
  35. package/richtexteditor/lang/rte-lang-fj.js +193 -0
  36. package/richtexteditor/lang/rte-lang-fr.js +193 -0
  37. package/richtexteditor/lang/rte-lang-ga.js +193 -0
  38. package/richtexteditor/lang/rte-lang-gu.js +193 -0
  39. package/richtexteditor/lang/rte-lang-he.js +193 -0
  40. package/richtexteditor/lang/rte-lang-hi.js +193 -0
  41. package/richtexteditor/lang/rte-lang-hr.js +193 -0
  42. package/richtexteditor/lang/rte-lang-ht.js +193 -0
  43. package/richtexteditor/lang/rte-lang-hu.js +193 -0
  44. package/richtexteditor/lang/rte-lang-id.js +193 -0
  45. package/richtexteditor/lang/rte-lang-is.js +193 -0
  46. package/richtexteditor/lang/rte-lang-it.js +193 -0
  47. package/richtexteditor/lang/rte-lang-ja.js +193 -0
  48. package/richtexteditor/lang/rte-lang-kn.js +193 -0
  49. package/richtexteditor/lang/rte-lang-ko.js +193 -0
  50. package/richtexteditor/lang/rte-lang-lt.js +193 -0
  51. package/richtexteditor/lang/rte-lang-lv.js +193 -0
  52. package/richtexteditor/lang/rte-lang-mg.js +193 -0
  53. package/richtexteditor/lang/rte-lang-mi.js +193 -0
  54. package/richtexteditor/lang/rte-lang-ml.js +193 -0
  55. package/richtexteditor/lang/rte-lang-mr.js +193 -0
  56. package/richtexteditor/lang/rte-lang-ms.js +193 -0
  57. package/richtexteditor/lang/rte-lang-mt.js +193 -0
  58. package/richtexteditor/lang/rte-lang-mww.js +193 -0
  59. package/richtexteditor/lang/rte-lang-nb.js +193 -0
  60. package/richtexteditor/lang/rte-lang-nl.js +193 -0
  61. package/richtexteditor/lang/rte-lang-otq.js +193 -0
  62. package/richtexteditor/lang/rte-lang-pa.js +193 -0
  63. package/richtexteditor/lang/rte-lang-pl.js +193 -0
  64. package/richtexteditor/lang/rte-lang-pt-pt.js +193 -0
  65. package/richtexteditor/lang/rte-lang-pt.js +193 -0
  66. package/richtexteditor/lang/rte-lang-ro.js +193 -0
  67. package/richtexteditor/lang/rte-lang-ru.js +193 -0
  68. package/richtexteditor/lang/rte-lang-sk.js +193 -0
  69. package/richtexteditor/lang/rte-lang-sl.js +193 -0
  70. package/richtexteditor/lang/rte-lang-sm.js +193 -0
  71. package/richtexteditor/lang/rte-lang-sr-Cyrl.js +193 -0
  72. package/richtexteditor/lang/rte-lang-sr-Latn.js +193 -0
  73. package/richtexteditor/lang/rte-lang-sv.js +193 -0
  74. package/richtexteditor/lang/rte-lang-sw.js +193 -0
  75. package/richtexteditor/lang/rte-lang-ta.js +193 -0
  76. package/richtexteditor/lang/rte-lang-te.js +193 -0
  77. package/richtexteditor/lang/rte-lang-th.js +193 -0
  78. package/richtexteditor/lang/rte-lang-tlh-Latn.js +193 -0
  79. package/richtexteditor/lang/rte-lang-tlh-Piqd.js +193 -0
  80. package/richtexteditor/lang/rte-lang-to.js +193 -0
  81. package/richtexteditor/lang/rte-lang-tr.js +193 -0
  82. package/richtexteditor/lang/rte-lang-ty.js +193 -0
  83. package/richtexteditor/lang/rte-lang-uk.js +193 -0
  84. package/richtexteditor/lang/rte-lang-ur.js +193 -0
  85. package/richtexteditor/lang/rte-lang-vi.js +193 -0
  86. package/richtexteditor/lang/rte-lang-yua.js +193 -0
  87. package/richtexteditor/lang/rte-lang-zh-Hans.js +193 -0
  88. package/richtexteditor/lang/rte-lang-zh-Hant.js +193 -0
  89. package/richtexteditor/lang/rte-lang.js +1 -0
  90. package/richtexteditor/plugins/-combine-plugin.txt +2 -0
  91. package/richtexteditor/plugins/-combine-plugins.bat +20 -0
  92. package/richtexteditor/plugins/a11yenhance.js +90 -0
  93. package/richtexteditor/plugins/accessibilitychecker.js +579 -0
  94. package/richtexteditor/plugins/aitoolkit.css +15830 -0
  95. package/richtexteditor/plugins/aitoolkit.js +19171 -0
  96. package/richtexteditor/plugins/all_plugins.js +31125 -0
  97. package/richtexteditor/plugins/all_plugins.min.js +78 -0
  98. package/richtexteditor/plugins/autoembed.js +174 -0
  99. package/richtexteditor/plugins/blocktypes.js +175 -0
  100. package/richtexteditor/plugins/bookmarkcard.js +226 -0
  101. package/richtexteditor/plugins/charlimit.js +195 -0
  102. package/richtexteditor/plugins/comments.js +672 -0
  103. package/richtexteditor/plugins/contentminimap.js +369 -0
  104. package/richtexteditor/plugins/crdt-engine.js +8905 -0
  105. package/richtexteditor/plugins/crdt-engine.min.js +5 -0
  106. package/richtexteditor/plugins/dialoga11y.js +174 -0
  107. package/richtexteditor/plugins/dictation.js +268 -0
  108. package/richtexteditor/plugins/documentimport.js +369 -0
  109. package/richtexteditor/plugins/documentoutline.js +341 -0
  110. package/richtexteditor/plugins/emailtoolkit.js +165 -0
  111. package/richtexteditor/plugins/emojiautocomplete.js +241 -0
  112. package/richtexteditor/plugins/foldheadings.js +181 -0
  113. package/richtexteditor/plugins/ghostcomplete.js +297 -0
  114. package/richtexteditor/plugins/html2pdf.js +158 -0
  115. package/richtexteditor/plugins/imageeditor.js +159 -0
  116. package/richtexteditor/plugins/insertcode.js +319 -0
  117. package/richtexteditor/plugins/insertemoji.js +229 -0
  118. package/richtexteditor/plugins/insertgallery.js +362 -0
  119. package/richtexteditor/plugins/inserttemplate.js +261 -0
  120. package/richtexteditor/plugins/localdraft.js +213 -0
  121. package/richtexteditor/plugins/markdownexport.js +110 -0
  122. package/richtexteditor/plugins/mathdialog.js +153 -0
  123. package/richtexteditor/plugins/mentionplugin.js +534 -0
  124. package/richtexteditor/plugins/mermaiddiagram.js +294 -0
  125. package/richtexteditor/plugins/readabilitystats.js +148 -0
  126. package/richtexteditor/plugins/readaloud.js +243 -0
  127. package/richtexteditor/plugins/restrictedediting.js +208 -0
  128. package/richtexteditor/plugins/revisionhistory.js +670 -0
  129. package/richtexteditor/plugins/samples/insertcode_v1.js +76 -0
  130. package/richtexteditor/plugins/slashcommand.js +705 -0
  131. package/richtexteditor/plugins/smartchips.js +250 -0
  132. package/richtexteditor/plugins/spellcheck.js +181 -0
  133. package/richtexteditor/plugins/todolist.js +137 -0
  134. package/richtexteditor/plugins/trackedchanges.js +658 -0
  135. package/richtexteditor/plugins/tui.image-editor/fabric.min.js +8 -0
  136. package/richtexteditor/plugins/tui.image-editor/note.txt +5 -0
  137. package/richtexteditor/plugins/tui.image-editor/svg/icon-a.svg +235 -0
  138. package/richtexteditor/plugins/tui.image-editor/svg/icon-b.svg +224 -0
  139. package/richtexteditor/plugins/tui.image-editor/svg/icon-c.svg +224 -0
  140. package/richtexteditor/plugins/tui.image-editor/svg/icon-d.svg +224 -0
  141. package/richtexteditor/plugins/tui.image-editor/tui-code-snippet.min.js +7 -0
  142. package/richtexteditor/plugins/tui.image-editor/tui-color-picker.min.css +6 -0
  143. package/richtexteditor/plugins/tui.image-editor/tui-color-picker.min.js +7 -0
  144. package/richtexteditor/plugins/tui.image-editor/tui-image-editor.min.css +7 -0
  145. package/richtexteditor/plugins/tui.image-editor/tui-image-editor.min.js +15 -0
  146. package/richtexteditor/plugins/typewriter.js +203 -0
  147. package/richtexteditor/plugins/wordexport.js +0 -0
  148. package/richtexteditor/plugins/yjscollab.js +693 -0
  149. package/richtexteditor/plugins/zz_richtextbox_dialog_style.js +335 -0
  150. package/richtexteditor/rte-config.js +933 -0
  151. package/richtexteditor/rte.js +943 -0
  152. package/richtexteditor/rte_mobile.css +234 -0
  153. package/richtexteditor/rte_theme_default.css +4819 -0
  154. package/richtexteditor/runtime/colorpicker_more_ns.htm +2613 -0
  155. package/richtexteditor/runtime/help.htm +162 -0
  156. package/richtexteditor/runtime/images/1x1.gif +0 -0
  157. package/richtexteditor/runtime/images/cpie_Color.cur +0 -0
  158. package/richtexteditor/runtime/images/cpie_GradientPositionDark.gif +0 -0
  159. package/richtexteditor/runtime/images/cpie_GradientPositionLight.gif +0 -0
  160. package/richtexteditor/runtime/images/cpie_VerticalPosition.gif +0 -0
  161. package/richtexteditor/runtime/images/cpie_WebSafe.gif +0 -0
  162. package/richtexteditor/runtime/images/cpie_gradients.png +0 -0
  163. package/richtexteditor/runtime/images/cpns_Color.cur +0 -0
  164. package/richtexteditor/runtime/images/cpns_ColorSpace1.png +0 -0
  165. package/richtexteditor/runtime/images/cpns_ColorSpace2.png +0 -0
  166. package/richtexteditor/runtime/images/cpns_GradientPositionDark.gif +0 -0
  167. package/richtexteditor/runtime/images/cpns_GradientPositionLight.gif +0 -0
  168. package/richtexteditor/runtime/images/cpns_Vertical1.png +0 -0
  169. package/richtexteditor/runtime/images/cpns_Vertical2.png +0 -0
  170. package/richtexteditor/runtime/images/cpns_VerticalPosition.gif +0 -0
  171. package/richtexteditor/runtime/images/cpns_WebSafe.gif +0 -0
  172. package/richtexteditor/runtime/images/cpns_gradients.png +0 -0
  173. package/richtexteditor/runtime/images/cpns_hue2.png +0 -0
  174. package/richtexteditor/runtime/images/formbn.gif +0 -0
  175. package/richtexteditor/runtime/images/multiclavier.gif +0 -0
  176. package/richtexteditor/runtime/richtexteditor_content.css +362 -0
  177. package/richtexteditor/runtime/richtexteditor_preview.css +302 -0
  178. package/richtexteditor/runtime/richtexteditor_preview.js +1 -0
  179. package/server/index.d.ts +21 -0
  180. package/server/index.js +23 -0
  181. package/svelte/index.d.ts +19 -0
  182. package/svelte/index.js +59 -0
  183. package/vue/index.d.ts +94 -0
  184. package/vue/index.js +291 -0
package/package.json ADDED
@@ -0,0 +1,130 @@
1
+ {
2
+ "name": "@richscripts/richtexteditor",
3
+ "publishConfig": { "access": "public" },
4
+ "version": "2.4.0",
5
+ "description": "A full-featured JavaScript rich text editor (WYSIWYG) with toolbar, plugins, i18n support, a built-in AI Toolkit (Ask AI, AI Chat, AI Review drawer, BYOK resolver), structured content APIs (JSON/Markdown), and an optional collaboration / review stack: slash commands, @mentions, human-author Track Changes, threaded comments, revision history, and Yjs-backed presence. Ships React, Vue, and server-safe conversion helpers.",
6
+ "main": "./richtexteditor/rte.js",
7
+ "scripts": {
8
+ "test:server": "node tests/run-all.test.js",
9
+ "test:admin": "node tests/run-all.test.js",
10
+ "test": "node tests/run-all.test.js",
11
+ "smoke:pack": "node tests/smoke-pack.js",
12
+ "guard:protected": "node tests/guard-protected-bundle.js",
13
+ "prepublishOnly": "node tests/guard-protected-bundle.js"
14
+ },
15
+ "types": "./index.d.ts",
16
+ "style": "./richtexteditor/rte_theme_default.css",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./index.d.ts",
20
+ "default": "./richtexteditor/rte.js"
21
+ },
22
+ "./angular": {
23
+ "types": "./angular/index.d.ts",
24
+ "default": "./angular/index.ts"
25
+ },
26
+ "./react": {
27
+ "types": "./react/index.d.ts",
28
+ "default": "./react/index.js"
29
+ },
30
+ "./vue": {
31
+ "types": "./vue/index.d.ts",
32
+ "default": "./vue/index.js"
33
+ },
34
+ "./svelte": {
35
+ "types": "./svelte/index.d.ts",
36
+ "default": "./svelte/index.js"
37
+ },
38
+ "./headless": {
39
+ "types": "./headless/index.d.ts",
40
+ "default": "./headless/index.js"
41
+ },
42
+ "./server": {
43
+ "types": "./server/index.d.ts",
44
+ "default": "./server/index.js"
45
+ },
46
+ "./admin": {
47
+ "types": "./admin/index.d.ts",
48
+ "default": "./admin/index.js"
49
+ },
50
+ "./integrations/shared": {
51
+ "types": "./integrations/shared.d.ts",
52
+ "default": "./integrations/shared.js"
53
+ },
54
+ "./richtexteditor/*": "./richtexteditor/*",
55
+ "./package.json": "./package.json"
56
+ },
57
+ "files": [
58
+ "angular",
59
+ "admin",
60
+ "headless",
61
+ "index.d.ts",
62
+ "integrations",
63
+ "react",
64
+ "richtexteditor",
65
+ "server",
66
+ "svelte",
67
+ "vue"
68
+ ],
69
+ "peerDependencies": {
70
+ "react": ">=18",
71
+ "svelte": ">=3",
72
+ "vue": ">=3"
73
+ },
74
+ "peerDependenciesMeta": {
75
+ "react": {
76
+ "optional": true
77
+ },
78
+ "svelte": {
79
+ "optional": true
80
+ },
81
+ "vue": {
82
+ "optional": true
83
+ }
84
+ },
85
+ "keywords": [
86
+ "rich-text-editor",
87
+ "wysiwyg",
88
+ "editor",
89
+ "html-editor",
90
+ "structured-content",
91
+ "json",
92
+ "markdown",
93
+ "react",
94
+ "vue",
95
+ "angular",
96
+ "svelte",
97
+ "headless",
98
+ "use-editor",
99
+ "ssr",
100
+ "server-rendering",
101
+ "text-editor",
102
+ "contenteditable",
103
+ "toolbar",
104
+ "formatting",
105
+ "image-editor",
106
+ "pdf-export",
107
+ "i18n",
108
+ "plugins",
109
+ "javascript",
110
+ "vanilla-js",
111
+ "no-dependencies",
112
+ "slash-commands",
113
+ "mentions",
114
+ "track-changes",
115
+ "comments",
116
+ "revision-history",
117
+ "collaboration",
118
+ "yjs",
119
+ "crdt",
120
+ "ai-toolkit",
121
+ "ai-editor"
122
+ ],
123
+ "author": "CuteSoft Components Inc.",
124
+ "license": "SEE LICENSE IN http://richtexteditor.com/license.aspx",
125
+ "homepage": "https://richtexteditor.com",
126
+ "repository": {
127
+ "type": "git",
128
+ "url": "https://github.com/richtexteditor/richtexteditor"
129
+ }
130
+ }
@@ -0,0 +1,104 @@
1
+ import type * as React from "react";
2
+ import type {
3
+ RichTextEditorAccessibilityResult,
4
+ RichTextEditorAiToolkit,
5
+ RichTextEditorCollab,
6
+ RichTextEditorComments,
7
+ RichTextEditorDictation,
8
+ RichTextEditorDocumentMetrics,
9
+ RichTextEditorDocumentOutlineItem,
10
+ RichTextEditorFootnoteItem,
11
+ RichTextEditorInstance,
12
+ RichTextEditorLinkAuditOptions,
13
+ RichTextEditorLinkAuditResult,
14
+ RichTextEditorMentions,
15
+ RichTextEditorPageSetup,
16
+ RichTextEditorReviewLedger,
17
+ RichTextEditorRevisionHistory,
18
+ RichTextEditorSlashCommands,
19
+ RichTextEditorStructuredDocument,
20
+ RichTextEditorStructuredInput,
21
+ RichTextEditorTableOfContentsItem,
22
+ RichTextEditorTableOfContentsOptions,
23
+ RichTextEditorTextStatistics,
24
+ RichTextEditorValueFormat
25
+ } from "../index";
26
+
27
+ export interface RichTextEditorReactHandle {
28
+ focus(): void;
29
+ getEditor(): RichTextEditorInstance | null;
30
+ getHTMLCode(): string;
31
+ getJSON(): RichTextEditorStructuredDocument | null;
32
+ setHTMLCode(value: string): void;
33
+ setJSON(value: RichTextEditorStructuredInput): void;
34
+ getTextStatistics(): RichTextEditorTextStatistics | null;
35
+ getSelectionStatistics(): RichTextEditorTextStatistics | null;
36
+ getDocumentMetrics(): RichTextEditorDocumentMetrics | null;
37
+ getDocumentPageSetup(): RichTextEditorPageSetup | null;
38
+ setDocumentPageSetup(pageSetup: RichTextEditorPageSetup | null): RichTextEditorInstance | null;
39
+ getDocumentOutline(): RichTextEditorDocumentOutlineItem[];
40
+ getFootnotes(): RichTextEditorFootnoteItem[];
41
+ getTableOfContents(options?: RichTextEditorTableOfContentsOptions): RichTextEditorTableOfContentsItem[];
42
+ syncTableOfContents(options?: RichTextEditorTableOfContentsOptions): RichTextEditorStructuredDocument | null;
43
+ auditAccessibility(): RichTextEditorAccessibilityResult | null;
44
+ auditLinks(options?: RichTextEditorLinkAuditOptions): RichTextEditorLinkAuditResult | null;
45
+
46
+ /**
47
+ * Convenience accessors that forward to the underlying RichTextEditor
48
+ * instance's v2.0 plugin namespaces. Each returns `null` when the editor
49
+ * is not yet initialised, and `undefined` when the corresponding plugin
50
+ * is not loaded for this build.
51
+ */
52
+ getAiToolkit(): RichTextEditorAiToolkit | null | undefined;
53
+ getDictation(): RichTextEditorDictation | null | undefined;
54
+ getRevisionHistory(): RichTextEditorRevisionHistory | null | undefined;
55
+ getCollab(): RichTextEditorCollab | null | undefined;
56
+ getSlashCommands(): RichTextEditorSlashCommands | null | undefined;
57
+ getMentions(): RichTextEditorMentions | null | undefined;
58
+ getComments(): RichTextEditorComments | null | undefined;
59
+ getReviewLedger(): RichTextEditorReviewLedger | null | undefined;
60
+ }
61
+
62
+ export interface RichTextEditorReactProps
63
+ extends Omit<React.HTMLAttributes<HTMLDivElement>, "defaultValue" | "onChange"> {
64
+ assetBasePath?: string;
65
+ autoload?: boolean;
66
+ config?: Record<string, unknown>;
67
+ defaultValue?: RichTextEditorStructuredInput;
68
+ onChange?: (
69
+ value: string | RichTextEditorStructuredDocument,
70
+ editor: RichTextEditorInstance
71
+ ) => void;
72
+ onError?: (error: Error) => void;
73
+ onReady?: (editor: RichTextEditorInstance) => void;
74
+ value?: RichTextEditorStructuredInput;
75
+ valueFormat?: RichTextEditorValueFormat;
76
+ }
77
+
78
+ export const RichTextEditorReact: React.ForwardRefExoticComponent<
79
+ RichTextEditorReactProps & React.RefAttributes<RichTextEditorReactHandle>
80
+ >;
81
+
82
+ export const RichTextEditor: typeof RichTextEditorReact;
83
+
84
+ export {
85
+ auditAccessibility,
86
+ auditLinks,
87
+ createStructuredContent,
88
+ createStructuredDocument,
89
+ fromMarkdown,
90
+ getDocumentPageSetup,
91
+ getDocumentMetrics,
92
+ getDocumentOutline,
93
+ getFootnotes,
94
+ getTableOfContents,
95
+ getTextStatistics,
96
+ loadRichTextEditorAssets,
97
+ renderHTML,
98
+ setDocumentPageSetup,
99
+ syncTableOfContents,
100
+ toMarkdown,
101
+ validateStructuredContent
102
+ } from "../integrations/shared";
103
+
104
+ export { RichTextEditorLinkAuditOptions, RichTextEditorLinkAuditResult };
package/react/index.js ADDED
@@ -0,0 +1,310 @@
1
+ var React = require("react");
2
+ var shared = require("../integrations/shared");
3
+ var headless = require("../headless");
4
+
5
+ function pluginAccessor(editorRef, name) {
6
+ return function () {
7
+ var ed = editorRef.current;
8
+ if (!ed) return null;
9
+ return ed[name]; // undefined when the plugin isn't loaded for this build
10
+ };
11
+ }
12
+
13
+ function editorMethodAccessor(editorRef, name, emptyValue) {
14
+ return function () {
15
+ var ed = editorRef.current;
16
+ if (!ed || typeof ed[name] !== "function") {
17
+ return emptyValue;
18
+ }
19
+ return ed[name].apply(ed, arguments);
20
+ };
21
+ }
22
+
23
+ function getEditorHandle(editorRef) {
24
+ return {
25
+ getEditor: function () {
26
+ return editorRef.current;
27
+ },
28
+ focus: function () {
29
+ if (editorRef.current) {
30
+ editorRef.current.focus();
31
+ }
32
+ },
33
+ getHTMLCode: function () {
34
+ return editorRef.current ? editorRef.current.getHTMLCode() : "";
35
+ },
36
+ setHTMLCode: function (value) {
37
+ if (editorRef.current) {
38
+ editorRef.current.setHTMLCode(value || "");
39
+ }
40
+ },
41
+ getJSON: function () {
42
+ return editorRef.current ? editorRef.current.getJSON() : null;
43
+ },
44
+ setJSON: function (value) {
45
+ if (editorRef.current) {
46
+ editorRef.current.setJSON(value);
47
+ }
48
+ },
49
+ getTextStatistics: editorMethodAccessor(editorRef, "getTextStatistics", null),
50
+ getSelectionStatistics: editorMethodAccessor(editorRef, "getSelectionStatistics", null),
51
+ getDocumentMetrics: editorMethodAccessor(editorRef, "getDocumentMetrics", null),
52
+ getDocumentPageSetup: editorMethodAccessor(editorRef, "getDocumentPageSetup", null),
53
+ setDocumentPageSetup: editorMethodAccessor(editorRef, "setDocumentPageSetup", null),
54
+ getDocumentOutline: function () {
55
+ var ed = editorRef.current;
56
+ if (!ed) {
57
+ return [];
58
+ }
59
+ return shared.getDocumentOutline(ed.getJSON());
60
+ },
61
+ getFootnotes: function () {
62
+ var ed = editorRef.current;
63
+ if (!ed) {
64
+ return [];
65
+ }
66
+ return shared.getFootnotes(ed.getJSON());
67
+ },
68
+ getTableOfContents: function (options) {
69
+ var ed = editorRef.current;
70
+ if (!ed) {
71
+ return [];
72
+ }
73
+ return shared.getTableOfContents(ed.getJSON(), options);
74
+ },
75
+ syncTableOfContents: function (options) {
76
+ var ed = editorRef.current;
77
+ if (!ed) {
78
+ return null;
79
+ }
80
+ var documentModel = shared.syncTableOfContents(ed.getJSON(), options);
81
+ ed.setJSON(documentModel);
82
+ return documentModel;
83
+ },
84
+ auditAccessibility: function () {
85
+ var ed = editorRef.current;
86
+ if (!ed) {
87
+ return null;
88
+ }
89
+ return shared.auditAccessibility(ed.getJSON());
90
+ },
91
+ auditLinks: function (options) {
92
+ var ed = editorRef.current;
93
+ if (!ed) {
94
+ return null;
95
+ }
96
+ return shared.auditLinks(ed.getJSON(), options);
97
+ },
98
+ // v2.0 plugin convenience accessors. Each returns the underlying
99
+ // namespace, or `undefined` when the plugin isn't bundled.
100
+ getAiToolkit: pluginAccessor(editorRef, "aiToolkit"),
101
+ getDictation: pluginAccessor(editorRef, "dictation"),
102
+ getRevisionHistory: pluginAccessor(editorRef, "revisionHistory"),
103
+ getCollab: pluginAccessor(editorRef, "collab"),
104
+ getSlashCommands: pluginAccessor(editorRef, "slashCommands"),
105
+ getMentions: pluginAccessor(editorRef, "mentions"),
106
+ getComments: pluginAccessor(editorRef, "comments"),
107
+ getReviewLedger: pluginAccessor(editorRef, "reviewLedger")
108
+ };
109
+ }
110
+
111
+ var RichTextEditorReact = React.forwardRef(function RichTextEditorReact(props, forwardedRef) {
112
+ var hostRef = React.useRef(null);
113
+ var editorRef = React.useRef(null);
114
+ var onChangeRef = React.useRef(props.onChange);
115
+ var onReadyRef = React.useRef(props.onReady);
116
+ var onErrorRef = React.useRef(props.onError);
117
+ var formatRef = React.useRef(props.valueFormat || "html");
118
+ var configRef = React.useRef(props.config || {});
119
+
120
+ React.useEffect(function () {
121
+ onChangeRef.current = props.onChange;
122
+ onReadyRef.current = props.onReady;
123
+ onErrorRef.current = props.onError;
124
+ formatRef.current = props.valueFormat || "html";
125
+ configRef.current = props.config || {};
126
+ });
127
+
128
+ React.useImperativeHandle(forwardedRef, function () {
129
+ return getEditorHandle(editorRef);
130
+ }, []);
131
+
132
+ React.useEffect(function () {
133
+ var disposed = false;
134
+ var changeHandler = null;
135
+ var activeHost = hostRef.current;
136
+
137
+ var readyPromise = props.autoload === false
138
+ ? Promise.resolve().then(function () {
139
+ return shared.installStructuredContentBridge();
140
+ })
141
+ : shared.loadRichTextEditorAssets({ basePath: props.assetBasePath });
142
+
143
+ readyPromise
144
+ .then(function () {
145
+ if (disposed || !activeHost) {
146
+ return;
147
+ }
148
+
149
+ var editor = shared.createEditor(activeHost, configRef.current);
150
+ editorRef.current = editor;
151
+
152
+ var initialValue = props.value !== undefined ? props.value : props.defaultValue;
153
+ if (initialValue !== undefined) {
154
+ shared.setEditorValue(editor, initialValue, formatRef.current);
155
+ }
156
+
157
+ changeHandler = function () {
158
+ if (onChangeRef.current) {
159
+ onChangeRef.current(shared.getEditorValue(editor, formatRef.current), editor);
160
+ }
161
+ };
162
+
163
+ editor.attachEvent("change", changeHandler);
164
+
165
+ if (onReadyRef.current) {
166
+ onReadyRef.current(editor);
167
+ }
168
+ })
169
+ .catch(function (error) {
170
+ if (!disposed && onErrorRef.current) {
171
+ onErrorRef.current(error);
172
+ }
173
+ });
174
+
175
+ return function () {
176
+ disposed = true;
177
+ var ed = editorRef.current;
178
+ if (ed) {
179
+ if (changeHandler && typeof ed.detachEvent === "function") {
180
+ ed.detachEvent("change", changeHandler);
181
+ }
182
+ // Tear down the editor's instance-level global listeners so an
183
+ // unmount (or React 18 StrictMode's mount→unmount→mount) doesn't leak.
184
+ if (typeof ed.destroy === "function") {
185
+ try { ed.destroy(); } catch (e) { /* ignore */ }
186
+ }
187
+ }
188
+ if (activeHost) {
189
+ activeHost.innerHTML = "";
190
+ }
191
+ editorRef.current = null;
192
+ };
193
+ }, []);
194
+
195
+ React.useEffect(function () {
196
+ if (!editorRef.current || props.value === undefined) {
197
+ return;
198
+ }
199
+
200
+ var nextHtml = shared.normalizeStructuredContent(props.value);
201
+ if (editorRef.current.getHTMLCode() !== nextHtml) {
202
+ shared.setEditorValue(editorRef.current, props.value, props.valueFormat || "html");
203
+ }
204
+ }, [props.value, props.valueFormat]);
205
+
206
+ var divProps = Object.assign({}, props);
207
+ delete divProps.assetBasePath;
208
+ delete divProps.autoload;
209
+ delete divProps.config;
210
+ delete divProps.defaultValue;
211
+ delete divProps.onChange;
212
+ delete divProps.onError;
213
+ delete divProps.onReady;
214
+ delete divProps.value;
215
+ delete divProps.valueFormat;
216
+
217
+ divProps.ref = hostRef;
218
+
219
+ return React.createElement("div", divProps);
220
+ });
221
+
222
+ RichTextEditorReact.defaultProps = {
223
+ assetBasePath: "/richtexteditor",
224
+ autoload: true,
225
+ valueFormat: "html"
226
+ };
227
+
228
+ // ---- Headless hook: bring-your-own-UI, Tiptap-style ----
229
+ // const editor = useRichTextEditor({ value: "<p>Hi</p>" });
230
+ // <button onMouseDown={e => { e.preventDefault(); editor.run("bold"); }}
231
+ // className={editor.state.bold ? "is-active" : ""}>B</button>
232
+ // <EditorContent editor={editor} />
233
+ function useRichTextEditor(options) {
234
+ var optionsRef = React.useRef(options || {});
235
+ var hostRef = React.useRef(null);
236
+ var controllerRef = React.useRef(null);
237
+ var stateRef = React.useRef({});
238
+ var rerender = React.useReducer(function (c) { return (c + 1) | 0; }, 0)[1];
239
+
240
+ React.useEffect(function () {
241
+ var disposed = false;
242
+ var ctl = null;
243
+ headless.createHeadlessEditor(hostRef.current, optionsRef.current)
244
+ .then(function (controller) {
245
+ if (disposed) { controller.destroy(); return; }
246
+ ctl = controller;
247
+ controllerRef.current = controller;
248
+ controller.on("update", function (snapshot) {
249
+ stateRef.current = snapshot;
250
+ rerender();
251
+ });
252
+ stateRef.current = controller.state();
253
+ if (optionsRef.current.onReady) { optionsRef.current.onReady(controller); }
254
+ rerender();
255
+ })
256
+ .catch(function (error) {
257
+ if (optionsRef.current.onError) { optionsRef.current.onError(error); }
258
+ });
259
+ return function () {
260
+ disposed = true;
261
+ if (ctl) { ctl.destroy(); }
262
+ controllerRef.current = null;
263
+ };
264
+ }, []);
265
+
266
+ return {
267
+ ref: hostRef,
268
+ get editor() { return controllerRef.current; }, // controller (null until ready)
269
+ get state() { return stateRef.current; },
270
+ isActive: function (name) { return controllerRef.current ? controllerRef.current.isActive(name) : false; },
271
+ can: function (cmd) { return controllerRef.current ? controllerRef.current.can(cmd) : false; },
272
+ run: function (cmd, value) { if (controllerRef.current) { controllerRef.current.run(cmd, value); } return this; },
273
+ getHTML: function () { return controllerRef.current ? controllerRef.current.getHTML() : ""; },
274
+ getMarkdown: function () { return controllerRef.current ? controllerRef.current.getMarkdown() : ""; },
275
+ focus: function () { if (controllerRef.current) { controllerRef.current.focus(); } return this; }
276
+ };
277
+ }
278
+
279
+ // Mount point for the headless editor returned by useRichTextEditor.
280
+ function EditorContent(props) {
281
+ var rest = Object.assign({}, props);
282
+ delete rest.editor;
283
+ rest.ref = props.editor ? props.editor.ref : undefined;
284
+ return React.createElement("div", rest);
285
+ }
286
+
287
+ module.exports = {
288
+ auditAccessibility: shared.auditAccessibility,
289
+ auditLinks: shared.auditLinks,
290
+ createStructuredDocument: shared.createStructuredDocument,
291
+ RichTextEditor: RichTextEditorReact,
292
+ RichTextEditorReact: RichTextEditorReact,
293
+ useRichTextEditor: useRichTextEditor,
294
+ EditorContent: EditorContent,
295
+ createHeadlessEditor: headless.createHeadlessEditor,
296
+ createStructuredContent: shared.createStructuredContent,
297
+ fromMarkdown: shared.fromMarkdown,
298
+ getDocumentPageSetup: shared.getDocumentPageSetup,
299
+ getDocumentMetrics: shared.getDocumentMetrics,
300
+ getDocumentOutline: shared.getDocumentOutline,
301
+ getFootnotes: shared.getFootnotes,
302
+ getTableOfContents: shared.getTableOfContents,
303
+ getTextStatistics: shared.getTextStatistics,
304
+ loadRichTextEditorAssets: shared.loadRichTextEditorAssets,
305
+ renderHTML: shared.renderHTML,
306
+ setDocumentPageSetup: shared.setDocumentPageSetup,
307
+ syncTableOfContents: shared.syncTableOfContents,
308
+ toMarkdown: shared.toMarkdown,
309
+ validateStructuredContent: shared.validateStructuredContent
310
+ };