@novaprose/tinymce-compat 0.7.0 → 0.9.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 (240) hide show
  1. package/README.md +1 -1
  2. package/THIRD_PARTY_NOTICES.md +2 -0
  3. package/dist/ai-XVSDIIQI.js +127 -0
  4. package/dist/ai-XVSDIIQI.js.map +1 -0
  5. package/dist/dialog-3UZZZW6Y.js +300 -0
  6. package/dist/dialog-3UZZZW6Y.js.map +1 -0
  7. package/dist/index.cjs +1335 -409
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +92 -45
  10. package/dist/index.d.ts +92 -45
  11. package/dist/index.js +831 -366
  12. package/dist/index.js.map +1 -1
  13. package/dist/novaprose.css +376 -550
  14. package/dist/tinymce-chunks/a11ychecker-fe78c552.js +2 -0
  15. package/dist/tinymce-chunks/a11ychecker-fe78c552.js.map +7 -0
  16. package/dist/tinymce-chunks/accordion-ui-4272c63b.js +2 -0
  17. package/dist/tinymce-chunks/accordion-ui-4272c63b.js.map +7 -0
  18. package/dist/tinymce-chunks/advcode-840793ca.js +2 -0
  19. package/dist/tinymce-chunks/advcode-840793ca.js.map +7 -0
  20. package/dist/tinymce-chunks/advcode-editor-37bc0a02.js +26 -0
  21. package/dist/tinymce-chunks/advcode-editor-37bc0a02.js.map +7 -0
  22. package/dist/tinymce-chunks/advlist-67b98670.js +2 -0
  23. package/dist/tinymce-chunks/{advlist-7a360f16.js.map → advlist-67b98670.js.map} +2 -2
  24. package/dist/tinymce-chunks/advtable-ui-db2e667d.js +2 -0
  25. package/dist/tinymce-chunks/advtable-ui-db2e667d.js.map +7 -0
  26. package/dist/tinymce-chunks/ai-e0658729.js +6 -0
  27. package/dist/tinymce-chunks/ai-e0658729.js.map +7 -0
  28. package/dist/tinymce-chunks/ai2-ddf912a7.js +34 -0
  29. package/dist/tinymce-chunks/ai2-ddf912a7.js.map +7 -0
  30. package/dist/tinymce-chunks/anchor-ui-da0966bb.js +2 -0
  31. package/dist/tinymce-chunks/anchor-ui-da0966bb.js.map +7 -0
  32. package/dist/tinymce-chunks/autocorrect-907e1296.js +3 -0
  33. package/dist/tinymce-chunks/autocorrect-907e1296.js.map +7 -0
  34. package/dist/tinymce-chunks/autolink-897e8650.js +2 -0
  35. package/dist/tinymce-chunks/{autolink-7e2e7be2.js.map → autolink-897e8650.js.map} +2 -2
  36. package/dist/tinymce-chunks/autoresize-f8a4a52a.js +2 -0
  37. package/dist/tinymce-chunks/autoresize-f8a4a52a.js.map +7 -0
  38. package/dist/tinymce-chunks/autosave-60381295.js +2 -0
  39. package/dist/tinymce-chunks/autosave-60381295.js.map +7 -0
  40. package/dist/tinymce-chunks/bash-f3f8783a.js +2 -0
  41. package/dist/tinymce-chunks/bash-f3f8783a.js.map +7 -0
  42. package/dist/tinymce-chunks/c-8e3b278b.js +2 -0
  43. package/dist/tinymce-chunks/c-8e3b278b.js.map +7 -0
  44. package/dist/tinymce-chunks/casechange-8ad6a2c3.js +6 -0
  45. package/dist/tinymce-chunks/casechange-8ad6a2c3.js.map +7 -0
  46. package/dist/tinymce-chunks/charmap-5deb524c.js +2 -0
  47. package/dist/tinymce-chunks/charmap-5deb524c.js.map +7 -0
  48. package/dist/tinymce-chunks/checklist-5a0c95d3.js +2 -0
  49. package/dist/tinymce-chunks/checklist-5a0c95d3.js.map +7 -0
  50. package/dist/tinymce-chunks/codesample-b91dcd91.js +4 -0
  51. package/dist/tinymce-chunks/codesample-b91dcd91.js.map +7 -0
  52. package/dist/tinymce-chunks/comments-panel-152e9cbe.js +2 -0
  53. package/dist/tinymce-chunks/comments-panel-152e9cbe.js.map +7 -0
  54. package/dist/tinymce-chunks/core-f5b3fd3e.js +4 -0
  55. package/dist/tinymce-chunks/core-f5b3fd3e.js.map +7 -0
  56. package/dist/tinymce-chunks/cpp-525b2c81.js +2 -0
  57. package/dist/tinymce-chunks/cpp-525b2c81.js.map +7 -0
  58. package/dist/tinymce-chunks/csharp-b95db858.js +2 -0
  59. package/dist/tinymce-chunks/csharp-b95db858.js.map +7 -0
  60. package/dist/tinymce-chunks/css-bb736f0c.js +2 -0
  61. package/dist/tinymce-chunks/css-bb736f0c.js.map +7 -0
  62. package/dist/tinymce-chunks/de-21549c7e.js +2 -0
  63. package/dist/tinymce-chunks/de-21549c7e.js.map +7 -0
  64. package/dist/tinymce-chunks/dialog-126a0355.js +2 -0
  65. package/dist/tinymce-chunks/dialog-126a0355.js.map +7 -0
  66. package/dist/tinymce-chunks/diff-02578ed2.js +2 -0
  67. package/dist/tinymce-chunks/diff-02578ed2.js.map +7 -0
  68. package/dist/tinymce-chunks/directionality-185b3810.js +2 -0
  69. package/dist/tinymce-chunks/{directionality-60dba768.js.map → directionality-185b3810.js.map} +2 -2
  70. package/dist/tinymce-chunks/dockerfile-ff44475c.js +2 -0
  71. package/dist/tinymce-chunks/dockerfile-ff44475c.js.map +7 -0
  72. package/dist/tinymce-chunks/draghandle-a1d99987.js +4 -0
  73. package/dist/tinymce-chunks/draghandle-a1d99987.js.map +7 -0
  74. package/dist/tinymce-chunks/editimage-36199bc6.js +2 -0
  75. package/dist/tinymce-chunks/editimage-36199bc6.js.map +7 -0
  76. package/dist/tinymce-chunks/email-1926dd8a.js +62 -0
  77. package/dist/tinymce-chunks/email-1926dd8a.js.map +7 -0
  78. package/dist/tinymce-chunks/email2-e9c49586.js +2 -0
  79. package/dist/tinymce-chunks/email2-e9c49586.js.map +7 -0
  80. package/dist/tinymce-chunks/emoticons-a5ab437d.js +2 -0
  81. package/dist/tinymce-chunks/emoticons-a5ab437d.js.map +7 -0
  82. package/dist/tinymce-chunks/es-1de93a3f.js +2 -0
  83. package/dist/tinymce-chunks/es-1de93a3f.js.map +7 -0
  84. package/dist/tinymce-chunks/exportpdf-1dfcbddc.js +2 -0
  85. package/dist/tinymce-chunks/exportpdf-1dfcbddc.js.map +7 -0
  86. package/dist/tinymce-chunks/exportword-ad95abb4.js +2 -0
  87. package/dist/tinymce-chunks/exportword-ad95abb4.js.map +7 -0
  88. package/dist/tinymce-chunks/footnotes-ui-3f167c2c.js +2 -0
  89. package/dist/tinymce-chunks/footnotes-ui-3f167c2c.js.map +7 -0
  90. package/dist/tinymce-chunks/form-dialog-9eb62199.js +2 -0
  91. package/dist/tinymce-chunks/form-dialog-9eb62199.js.map +7 -0
  92. package/dist/tinymce-chunks/formatpainter-cbeeffa7.js +2 -0
  93. package/dist/tinymce-chunks/formatpainter-cbeeffa7.js.map +7 -0
  94. package/dist/tinymce-chunks/fr-6fbcca9f.js +2 -0
  95. package/dist/tinymce-chunks/fr-6fbcca9f.js.map +7 -0
  96. package/dist/tinymce-chunks/fullpagehtml-ui-9dd804af.js +2 -0
  97. package/dist/tinymce-chunks/fullpagehtml-ui-9dd804af.js.map +7 -0
  98. package/dist/tinymce-chunks/go-14612282.js +2 -0
  99. package/dist/tinymce-chunks/go-14612282.js.map +7 -0
  100. package/dist/tinymce-chunks/graphql-032121b4.js +2 -0
  101. package/dist/tinymce-chunks/graphql-032121b4.js.map +7 -0
  102. package/dist/tinymce-chunks/history-diff-a0db052c.js +2 -0
  103. package/dist/tinymce-chunks/history-diff-a0db052c.js.map +7 -0
  104. package/dist/tinymce-chunks/importcss-28610ab5.js +3 -0
  105. package/dist/tinymce-chunks/importcss-28610ab5.js.map +7 -0
  106. package/dist/tinymce-chunks/importword-d6c2636a.js +2 -0
  107. package/dist/tinymce-chunks/importword-d6c2636a.js.map +7 -0
  108. package/dist/tinymce-chunks/index-a1feed69.js +5 -0
  109. package/dist/tinymce-chunks/index-a1feed69.js.map +7 -0
  110. package/dist/tinymce-chunks/index2-610900bb.js +2 -0
  111. package/dist/tinymce-chunks/index2-610900bb.js.map +7 -0
  112. package/dist/tinymce-chunks/insertdatetime-a48ee6e0.js +2 -0
  113. package/dist/tinymce-chunks/{insertdatetime-e0dbcf63.js.map → insertdatetime-a48ee6e0.js.map} +2 -2
  114. package/dist/tinymce-chunks/it-ca70815f.js +2 -0
  115. package/dist/tinymce-chunks/it-ca70815f.js.map +7 -0
  116. package/dist/tinymce-chunks/java-e051279c.js +2 -0
  117. package/dist/tinymce-chunks/java-e051279c.js.map +7 -0
  118. package/dist/tinymce-chunks/javascript-d7a6fb3d.js +2 -0
  119. package/dist/tinymce-chunks/javascript-d7a6fb3d.js.map +7 -0
  120. package/dist/tinymce-chunks/json-08c0b631.js +2 -0
  121. package/dist/tinymce-chunks/json-08c0b631.js.map +7 -0
  122. package/dist/tinymce-chunks/kotlin-b34d5ff2.js +3 -0
  123. package/dist/tinymce-chunks/kotlin-b34d5ff2.js.map +7 -0
  124. package/dist/tinymce-chunks/linkchecker-820845fd.js +2 -0
  125. package/dist/tinymce-chunks/linkchecker-820845fd.js.map +7 -0
  126. package/dist/tinymce-chunks/lua-9b0ae20a.js +2 -0
  127. package/dist/tinymce-chunks/lua-9b0ae20a.js.map +7 -0
  128. package/dist/tinymce-chunks/markdown-5698ebec.js +34 -0
  129. package/dist/tinymce-chunks/markdown-5698ebec.js.map +7 -0
  130. package/dist/tinymce-chunks/markdown2-943bcf90.js +2 -0
  131. package/dist/tinymce-chunks/markdown2-943bcf90.js.map +7 -0
  132. package/dist/tinymce-chunks/math-ui-1b57f7eb.js +2 -0
  133. package/dist/tinymce-chunks/math-ui-1b57f7eb.js.map +7 -0
  134. package/dist/tinymce-chunks/media-ui-de819f11.js +2 -0
  135. package/dist/tinymce-chunks/media-ui-de819f11.js.map +7 -0
  136. package/dist/tinymce-chunks/mediaembed-ui-7be11324.js +2 -0
  137. package/dist/tinymce-chunks/mediaembed-ui-7be11324.js.map +7 -0
  138. package/dist/tinymce-chunks/mentions-ui-b1bb2d15.js +2 -0
  139. package/dist/tinymce-chunks/mentions-ui-b1bb2d15.js.map +7 -0
  140. package/dist/tinymce-chunks/mergetags-ui-f5bdd1f9.js +2 -0
  141. package/dist/tinymce-chunks/mergetags-ui-f5bdd1f9.js.map +7 -0
  142. package/dist/tinymce-chunks/nonbreaking-f15226ad.js +2 -0
  143. package/dist/tinymce-chunks/{nonbreaking-49bdb0d2.js.map → nonbreaking-f15226ad.js.map} +2 -2
  144. package/dist/tinymce-chunks/pagebreak-ui-7476f5c2.js +2 -0
  145. package/dist/tinymce-chunks/pagebreak-ui-7476f5c2.js.map +7 -0
  146. package/dist/tinymce-chunks/pageembed-ui-da39f1ee.js +2 -0
  147. package/dist/tinymce-chunks/pageembed-ui-da39f1ee.js.map +7 -0
  148. package/dist/tinymce-chunks/pagelayout-ui-01757669.js +2 -0
  149. package/dist/tinymce-chunks/pagelayout-ui-01757669.js.map +7 -0
  150. package/dist/tinymce-chunks/paste-office-4e8e9cb7.js +3 -0
  151. package/dist/tinymce-chunks/paste-office-4e8e9cb7.js.map +7 -0
  152. package/dist/tinymce-chunks/permanentpen-fc96f445.js +2 -0
  153. package/dist/tinymce-chunks/permanentpen-fc96f445.js.map +7 -0
  154. package/dist/tinymce-chunks/php-6b723470.js +3 -0
  155. package/dist/tinymce-chunks/php-6b723470.js.map +7 -0
  156. package/dist/tinymce-chunks/powershell-e6c3fdb8.js +2 -0
  157. package/dist/tinymce-chunks/powershell-e6c3fdb8.js.map +7 -0
  158. package/dist/tinymce-chunks/print-86762549.js +27 -0
  159. package/dist/tinymce-chunks/print-86762549.js.map +7 -0
  160. package/dist/tinymce-chunks/pt-BR-f6958ec0.js +2 -0
  161. package/dist/tinymce-chunks/pt-BR-f6958ec0.js.map +7 -0
  162. package/dist/tinymce-chunks/python-a20cacce.js +2 -0
  163. package/dist/tinymce-chunks/python-a20cacce.js.map +7 -0
  164. package/dist/tinymce-chunks/quickbars-35c87c0e.js +2 -0
  165. package/dist/tinymce-chunks/{quickbars-d937e10a.js.map → quickbars-35c87c0e.js.map} +3 -3
  166. package/dist/tinymce-chunks/revisionhistory-741dfb24.js +2 -0
  167. package/dist/tinymce-chunks/revisionhistory-741dfb24.js.map +7 -0
  168. package/dist/tinymce-chunks/ru-982f3476.js +2 -0
  169. package/dist/tinymce-chunks/ru-982f3476.js.map +7 -0
  170. package/dist/tinymce-chunks/ruby-93c325c7.js +2 -0
  171. package/dist/tinymce-chunks/ruby-93c325c7.js.map +7 -0
  172. package/dist/tinymce-chunks/rust-d80fbab5.js +2 -0
  173. package/dist/tinymce-chunks/rust-d80fbab5.js.map +7 -0
  174. package/dist/tinymce-chunks/save-a65e56cd.js +2 -0
  175. package/dist/tinymce-chunks/save-a65e56cd.js.map +7 -0
  176. package/dist/tinymce-chunks/scss-7cffeb15.js +2 -0
  177. package/dist/tinymce-chunks/scss-7cffeb15.js.map +7 -0
  178. package/dist/tinymce-chunks/search-bar-1c8ef2ee.js +3 -0
  179. package/dist/tinymce-chunks/search-bar-1c8ef2ee.js.map +7 -0
  180. package/dist/tinymce-chunks/spellchecker-91509fc1.js +6 -0
  181. package/dist/tinymce-chunks/spellchecker-91509fc1.js.map +7 -0
  182. package/dist/tinymce-chunks/sql-eeac1a81.js +2 -0
  183. package/dist/tinymce-chunks/sql-eeac1a81.js.map +7 -0
  184. package/dist/tinymce-chunks/suggestions-panel-c29362cf.js +2 -0
  185. package/dist/tinymce-chunks/suggestions-panel-c29362cf.js.map +7 -0
  186. package/dist/tinymce-chunks/suggestions-ui-c5f6bad4.js +2 -0
  187. package/dist/tinymce-chunks/suggestions-ui-c5f6bad4.js.map +7 -0
  188. package/dist/tinymce-chunks/swift-2b081f3e.js +2 -0
  189. package/dist/tinymce-chunks/swift-2b081f3e.js.map +7 -0
  190. package/dist/tinymce-chunks/table-4d43f60d.js +2 -0
  191. package/dist/tinymce-chunks/table-4d43f60d.js.map +7 -0
  192. package/dist/tinymce-chunks/table-dialogs-0445847c.js +2 -0
  193. package/dist/tinymce-chunks/table-dialogs-0445847c.js.map +7 -0
  194. package/dist/tinymce-chunks/tableofcontents-ui-01a9af06.js +2 -0
  195. package/dist/tinymce-chunks/tableofcontents-ui-01a9af06.js.map +7 -0
  196. package/dist/tinymce-chunks/temml-d637f801.js +97 -0
  197. package/dist/tinymce-chunks/temml-d637f801.js.map +7 -0
  198. package/dist/tinymce-chunks/template-b522c8ed.js +2 -0
  199. package/dist/tinymce-chunks/template-b522c8ed.js.map +7 -0
  200. package/dist/tinymce-chunks/typescript-fa085d66.js +2 -0
  201. package/dist/tinymce-chunks/typescript-fa085d66.js.map +7 -0
  202. package/dist/tinymce-chunks/typography-469ce11a.js +3 -0
  203. package/dist/tinymce-chunks/typography-469ce11a.js.map +7 -0
  204. package/dist/tinymce-chunks/visualblocks-8b7cba25.js +2 -0
  205. package/dist/tinymce-chunks/{visualblocks-58c88e5d.js.map → visualblocks-8b7cba25.js.map} +2 -2
  206. package/dist/tinymce-chunks/visualchars-7cda4c00.js +2 -0
  207. package/dist/tinymce-chunks/visualchars-7cda4c00.js.map +7 -0
  208. package/dist/tinymce-chunks/xml-77617a8f.js +2 -0
  209. package/dist/tinymce-chunks/xml-77617a8f.js.map +7 -0
  210. package/dist/tinymce-chunks/yaml-5bb3ad37.js +2 -0
  211. package/dist/tinymce-chunks/yaml-5bb3ad37.js.map +7 -0
  212. package/dist/tinymce.global.js +34 -27
  213. package/dist/tinymce.global.js.map +4 -4
  214. package/dist/tinymce.licenses.txt +1094 -0
  215. package/package.json +2 -2
  216. package/dist/tinymce-chunks/advlist-7a360f16.js +0 -2
  217. package/dist/tinymce-chunks/autolink-7e2e7be2.js +0 -2
  218. package/dist/tinymce-chunks/autoresize-d6c9537b.js +0 -2
  219. package/dist/tinymce-chunks/autoresize-d6c9537b.js.map +0 -7
  220. package/dist/tinymce-chunks/autosave-4fd46720.js +0 -2
  221. package/dist/tinymce-chunks/autosave-4fd46720.js.map +0 -7
  222. package/dist/tinymce-chunks/charmap-4b14307a.js +0 -2
  223. package/dist/tinymce-chunks/charmap-4b14307a.js.map +0 -7
  224. package/dist/tinymce-chunks/comments-panel-37cba890.js +0 -2
  225. package/dist/tinymce-chunks/comments-panel-37cba890.js.map +0 -7
  226. package/dist/tinymce-chunks/directionality-60dba768.js +0 -2
  227. package/dist/tinymce-chunks/emoticons-7e6da0b6.js +0 -2
  228. package/dist/tinymce-chunks/emoticons-7e6da0b6.js.map +0 -7
  229. package/dist/tinymce-chunks/form-dialog-9cde0ef7.js +0 -2
  230. package/dist/tinymce-chunks/form-dialog-9cde0ef7.js.map +0 -7
  231. package/dist/tinymce-chunks/insertdatetime-e0dbcf63.js +0 -2
  232. package/dist/tinymce-chunks/nonbreaking-49bdb0d2.js +0 -2
  233. package/dist/tinymce-chunks/paste-office-a38659d6.js +0 -3
  234. package/dist/tinymce-chunks/paste-office-a38659d6.js.map +0 -7
  235. package/dist/tinymce-chunks/quickbars-d937e10a.js +0 -2
  236. package/dist/tinymce-chunks/revisionhistory-d6306426.js +0 -2
  237. package/dist/tinymce-chunks/revisionhistory-d6306426.js.map +0 -7
  238. package/dist/tinymce-chunks/table-80284f6f.js +0 -2
  239. package/dist/tinymce-chunks/table-80284f6f.js.map +0 -7
  240. package/dist/tinymce-chunks/visualblocks-58c88e5d.js +0 -2
package/dist/index.cjs CHANGED
@@ -1,8 +1,18 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res, err) => function __init() {
9
+ if (err) throw err[0];
10
+ try {
11
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
12
+ } catch (e) {
13
+ throw err = [e], e;
14
+ }
15
+ };
6
16
  var __export = (target, all) => {
7
17
  for (var name in all)
8
18
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -13,9 +23,464 @@ var __copyProps = (to, from, except, desc) => {
13
23
  if (!__hasOwnProp.call(to, key) && key !== except)
14
24
  __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
25
  }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+
38
+ // nova-raw-css:/home/runner/work/novaprose/novaprose/packages/tinymce-compat/src/dialog.css?raw
39
+ var dialog_default;
40
+ var init_dialog = __esm({
41
+ "nova-raw-css:/home/runner/work/novaprose/novaprose/packages/tinymce-compat/src/dialog.css?raw"() {
42
+ dialog_default = ".nova-compat-dialog{display:flex;flex-direction:column;gap:12px}.nova-compat-tabs{display:flex;gap:2px;border-bottom:1px solid var(--nova-border)}.nova-compat-tab{padding:6px 10px;border:0;border-bottom:2px solid transparent;background:none;color:var(--nova-muted);font:inherit;cursor:pointer}.nova-compat-tab[aria-selected=true]{border-bottom-color:var(--nova-accent);color:var(--nova-fg);font-weight:600}.nova-compat-tab:focus-visible{outline:2px solid var(--nova-focus);outline-offset:-2px}.nova-compat-tabpanel{display:flex;flex-direction:column;gap:12px}.nova-compat-tabpanel[hidden]{display:none}.nova-compat-grid{display:grid;gap:10px}.nova-compat-group{display:flex;flex-direction:column;gap:8px}.nova-compat-actions{display:flex;flex-wrap:wrap;gap:8px}.nova-compat-alert{margin:0;padding:8px 10px;border-radius:var(--nova-radius-sm);background:var(--nova-active);color:var(--nova-fg)}.nova-compat-alert.is-warn{background:var(--nova-warning-bg)}.nova-compat-alert.is-error{background:var(--nova-danger-bg);color:var(--nova-danger)}.nova-compat-alert.is-success{background:var(--nova-success-bg)}.nova-compat-html{line-height:1.5;overflow-wrap:anywhere}";
43
+ }
44
+ });
45
+
46
+ // src/dialog.ts
47
+ var dialog_exports = {};
48
+ __export(dialog_exports, {
49
+ openSpecDialog: () => openSpecDialog
50
+ });
51
+ function el(tag, className, text) {
52
+ const node = document.createElement(tag);
53
+ if (className) node.className = className;
54
+ if (text !== void 0) node.textContent = text;
55
+ return node;
56
+ }
57
+ function safeHtml(html) {
58
+ const template = document.createElement("template");
59
+ template.innerHTML = html;
60
+ template.content.querySelectorAll("script, style, iframe, object, embed, link, meta, base, form").forEach((node) => node.remove());
61
+ template.content.querySelectorAll("*").forEach((node) => {
62
+ for (const attr of [...node.attributes]) {
63
+ const value = attr.value.trim().toLowerCase();
64
+ if (attr.name.startsWith("on") || /^(javascript|vbscript|data):/.test(value)) {
65
+ node.removeAttribute(attr.name);
66
+ }
67
+ }
68
+ });
69
+ return template.content;
70
+ }
71
+ function openSpecDialog(editor, spec, reopen) {
72
+ editor.ui.addStyles("nova-compat-dialog", dialog_default);
73
+ const controls = /* @__PURE__ */ new Map();
74
+ const tabs = /* @__PURE__ */ new Map();
75
+ let currentTab = "";
76
+ let closedByApi = false;
77
+ let handle = null;
78
+ const notifyChange = (name) => spec.onChange?.(api, { name });
79
+ function field(item, input) {
80
+ const id = nextId();
81
+ input.id = id;
82
+ const wrap = el("div", "nova-field");
83
+ if (item.label) {
84
+ const label = el("label", "nova-label", item.label);
85
+ label.htmlFor = id;
86
+ wrap.append(label);
87
+ }
88
+ wrap.append(input);
89
+ return wrap;
90
+ }
91
+ function render(item) {
92
+ const name = item.name ?? "";
93
+ const enabled = item.enabled !== false && item.disabled !== true;
94
+ switch (item.type) {
95
+ case "input":
96
+ case "urlinput":
97
+ case "colorinput": {
98
+ const input = el("input", "nova-input");
99
+ input.type = item.type === "colorinput" ? "color" : item.type === "urlinput" ? "url" : "text";
100
+ if (item.inputMode) input.inputMode = item.inputMode;
101
+ if (item.placeholder) input.placeholder = item.placeholder;
102
+ input.disabled = !enabled;
103
+ input.addEventListener("input", () => notifyChange(name));
104
+ if (name) {
105
+ controls.set(name, {
106
+ // urlinput keeps { value }, the others a string.
107
+ get: () => item.type === "urlinput" ? { value: input.value } : input.value,
108
+ set: (value) => {
109
+ input.value = String(
110
+ item.type === "urlinput" && value && typeof value === "object" ? value.value ?? "" : value ?? ""
111
+ );
112
+ },
113
+ focus: () => input.focus(),
114
+ setEnabled: (on) => input.disabled = !on
115
+ });
116
+ }
117
+ return field(item, input);
118
+ }
119
+ case "textarea": {
120
+ const input = el("textarea", "nova-input");
121
+ input.rows = item.maximized ? 10 : 4;
122
+ if (item.placeholder) input.placeholder = item.placeholder;
123
+ input.disabled = !enabled;
124
+ input.addEventListener("input", () => notifyChange(name));
125
+ if (name) {
126
+ controls.set(name, {
127
+ get: () => input.value,
128
+ set: (value) => input.value = String(value ?? ""),
129
+ focus: () => input.focus(),
130
+ setEnabled: (on) => input.disabled = !on
131
+ });
132
+ }
133
+ return field(item, input);
134
+ }
135
+ case "checkbox": {
136
+ const input = el("input", "nova-checkbox");
137
+ input.type = "checkbox";
138
+ input.id = nextId();
139
+ input.disabled = !enabled;
140
+ input.addEventListener("change", () => notifyChange(name));
141
+ const label = el("label", void 0, item.label ?? "");
142
+ label.htmlFor = input.id;
143
+ if (name) {
144
+ controls.set(name, {
145
+ get: () => input.checked,
146
+ set: (value) => input.checked = Boolean(value),
147
+ focus: () => input.focus(),
148
+ setEnabled: (on) => input.disabled = !on
149
+ });
150
+ }
151
+ const wrap = el("div", "nova-field nova-field-inline");
152
+ wrap.append(input, label);
153
+ return wrap;
154
+ }
155
+ case "selectbox":
156
+ case "listbox": {
157
+ const select = el("select", "nova-input nova-select");
158
+ for (const option of item.items ?? []) {
159
+ const node = el("option", void 0, option.text);
160
+ node.value = option.value;
161
+ select.append(node);
162
+ }
163
+ select.disabled = !enabled;
164
+ select.addEventListener("change", () => notifyChange(name));
165
+ if (name) {
166
+ controls.set(name, {
167
+ get: () => select.value,
168
+ set: (value) => select.value = String(value ?? ""),
169
+ focus: () => select.focus(),
170
+ setEnabled: (on) => select.disabled = !on
171
+ });
172
+ }
173
+ return field(item, select);
174
+ }
175
+ case "button": {
176
+ const button = el(
177
+ "button",
178
+ item.primary || item.buttonType === "primary" ? "nova-button nova-button-primary" : "nova-button",
179
+ item.text ?? ""
180
+ );
181
+ button.type = "button";
182
+ button.disabled = !enabled;
183
+ button.addEventListener("click", () => spec.onAction?.(api, { name }));
184
+ if (name) {
185
+ controls.set(name, {
186
+ get: () => void 0,
187
+ set: () => {
188
+ },
189
+ focus: () => button.focus(),
190
+ setEnabled: (on) => button.disabled = !on
191
+ });
192
+ }
193
+ return button;
194
+ }
195
+ case "htmlpanel": {
196
+ const panel = el("div", "nova-compat-html");
197
+ panel.append(safeHtml(item.html ?? ""));
198
+ return panel;
199
+ }
200
+ case "alertbanner": {
201
+ const banner = el("p", `nova-compat-alert is-${item.level ?? "info"}`, item.text ?? "");
202
+ banner.setAttribute("role", item.level === "error" ? "alert" : "status");
203
+ return banner;
204
+ }
205
+ case "label": {
206
+ const group = el("div", "nova-compat-group");
207
+ group.append(el("p", "nova-label", item.label ?? ""));
208
+ for (const child of item.items ?? []) {
209
+ const node = render(child);
210
+ if (node) group.append(node);
211
+ }
212
+ return group;
213
+ }
214
+ case "grid":
215
+ case "bar": {
216
+ const grid = el("div", "nova-compat-grid");
217
+ const columns = item.type === "bar" ? item.items?.length ?? 1 : item.columns === "auto" ? 2 : item.columns ?? 2;
218
+ grid.style.gridTemplateColumns = `repeat(${Number(columns) || 2}, minmax(0, 1fr))`;
219
+ for (const child of item.items ?? []) {
220
+ const node = render(child);
221
+ if (node) grid.append(node);
222
+ }
223
+ return grid;
224
+ }
225
+ default:
226
+ console.warn(`[nova] tinymce-compat: dialog component "${item.type}" is not supported yet`);
227
+ return null;
228
+ }
229
+ }
230
+ const body = el("div", "nova-compat-dialog nova-form");
231
+ if (spec.body.type === "tabpanel") {
232
+ const tabList = el("div", "nova-compat-tabs");
233
+ tabList.setAttribute("role", "tablist");
234
+ body.append(tabList);
235
+ spec.body.tabs.forEach((tab, index) => {
236
+ const name = tab.name ?? tab.title;
237
+ const button = el("button", "nova-compat-tab", tab.title);
238
+ button.type = "button";
239
+ button.setAttribute("role", "tab");
240
+ const panel = el("div", "nova-compat-tabpanel");
241
+ panel.setAttribute("role", "tabpanel");
242
+ for (const item of tab.items) {
243
+ const node = render(item);
244
+ if (node) panel.append(node);
245
+ }
246
+ button.addEventListener("click", () => api.showTab(name));
247
+ tabs.set(name, { button, panel });
248
+ tabList.append(button);
249
+ body.append(panel);
250
+ if (index === 0) currentTab = name;
251
+ });
252
+ } else {
253
+ for (const item of spec.body.items) {
254
+ const node = render(item);
255
+ if (node) body.append(node);
256
+ }
257
+ }
258
+ const buttons = spec.buttons ?? [];
259
+ const submit = buttons.find((b) => b.type === "submit");
260
+ const custom = buttons.filter((b) => b.type === "custom");
261
+ if (custom.length) {
262
+ const row = el("div", "nova-compat-actions");
263
+ for (const b of custom) {
264
+ const button = el(
265
+ "button",
266
+ b.primary ? "nova-button nova-button-primary" : "nova-button",
267
+ b.text
268
+ );
269
+ button.type = "button";
270
+ button.disabled = b.enabled === false;
271
+ button.addEventListener("click", () => spec.onAction?.(api, { name: b.name ?? b.text }));
272
+ if (b.name) {
273
+ controls.set(b.name, {
274
+ get: () => void 0,
275
+ set: () => {
276
+ },
277
+ focus: () => button.focus(),
278
+ setEnabled: (on) => button.disabled = !on
279
+ });
280
+ }
281
+ row.append(button);
282
+ }
283
+ body.append(row);
284
+ }
285
+ const api = {
286
+ getData: () => {
287
+ const data = {};
288
+ controls.forEach((control, name) => {
289
+ const value = control.get();
290
+ if (value !== void 0) data[name] = value;
291
+ });
292
+ return data;
293
+ },
294
+ setData: (data) => {
295
+ for (const [name, value] of Object.entries(data)) controls.get(name)?.set(value);
296
+ },
297
+ close: () => {
298
+ closedByApi = true;
299
+ handle?.close();
300
+ },
301
+ block: () => handle?.setBusy(true),
302
+ unblock: () => handle?.setBusy(false),
303
+ focus: (name) => controls.get(name)?.focus(),
304
+ disable: (name) => controls.get(name)?.setEnabled(false),
305
+ enable: (name) => controls.get(name)?.setEnabled(true),
306
+ showTab: (name) => {
307
+ if (!tabs.has(name)) return;
308
+ const old = currentTab;
309
+ currentTab = name;
310
+ tabs.forEach(({ button, panel }, key) => {
311
+ const on = key === name;
312
+ button.setAttribute("aria-selected", String(on));
313
+ button.tabIndex = on ? 0 : -1;
314
+ panel.hidden = !on;
315
+ });
316
+ if (old && old !== name) spec.onTabChange?.(api, { newTabName: name, oldTabName: old });
317
+ },
318
+ redial: (next) => {
319
+ api.close();
320
+ Object.assign(api, reopen(next));
321
+ }
322
+ };
323
+ if (spec.initialData) api.setData(spec.initialData);
324
+ if (currentTab) api.showTab(currentTab);
325
+ handle = editor.ui.openDialog({
326
+ title: spec.title,
327
+ body,
328
+ ...submit ? { submitLabel: submit.text } : {},
329
+ ...spec.size === "large" ? { size: "large" } : {},
330
+ onSubmit: () => {
331
+ spec.onSubmit?.(api);
332
+ return closedByApi;
333
+ },
334
+ onClose: () => {
335
+ if (!closedByApi) spec.onCancel?.(api);
336
+ spec.onClose?.();
337
+ }
338
+ });
339
+ return api;
340
+ }
341
+ var uid, nextId;
342
+ var init_dialog2 = __esm({
343
+ "src/dialog.ts"() {
344
+ "use strict";
345
+ init_dialog();
346
+ uid = 0;
347
+ nextId = () => `nova-compat-field-${++uid}`;
348
+ }
349
+ });
350
+
351
+ // src/ai.ts
352
+ var ai_exports = {};
353
+ __export(ai_exports, {
354
+ htmlToText: () => htmlToText,
355
+ tinyAiRequest: () => tinyAiRequest,
356
+ toTinyRequest: () => toTinyRequest
357
+ });
358
+ function thread(messages) {
359
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
360
+ const events = [];
361
+ messages.forEach((message, index) => {
362
+ const answer = messages[index + 1];
363
+ if (message.role !== "user" || answer?.role !== "assistant") return;
364
+ events.push({
365
+ eventUid: `nova-ai-${events.length + 1}`,
366
+ timestamp,
367
+ request: { prompt: message.text, query: message.text, context: "", system: [] },
368
+ response: { type: "string", data: answer.text }
369
+ });
370
+ });
371
+ return events;
372
+ }
373
+ function toTinyRequest(request) {
374
+ const context = request.text || (request.action === "chat" ? request.document : "") || (request.action === "complete" ? request.before : "");
375
+ return {
376
+ prompt: request.prompt,
377
+ query: request.instruction,
378
+ context,
379
+ thread: thread(request.messages ?? []),
380
+ system: [...request.rules ?? []]
381
+ };
382
+ }
383
+ function htmlToText(html) {
384
+ const body = new DOMParser().parseFromString(html, "text/html").body;
385
+ const paragraphs = [];
386
+ let line = "";
387
+ const flush = () => {
388
+ const text = line.replace(/[^\S\n]+/g, " ").replace(/ ?\n ?/g, "\n").trim();
389
+ if (text) paragraphs.push(text);
390
+ line = "";
391
+ };
392
+ const walk = (node) => {
393
+ for (const child of Array.from(node.childNodes)) {
394
+ if (child.nodeType === 3) line += (child.textContent ?? "").replace(/\s+/g, " ");
395
+ else if (child.nodeName === "BR") line += "\n";
396
+ else if (child.nodeType === 1 && child.nodeName !== "SCRIPT" && child.nodeName !== "STYLE") {
397
+ const block = BLOCKS2.test(child.nodeName);
398
+ if (block) flush();
399
+ walk(child);
400
+ if (block) flush();
401
+ }
402
+ }
403
+ };
404
+ walk(body);
405
+ flush();
406
+ return paragraphs.join("\n\n");
407
+ }
408
+ function tinyAiRequest(handler, fire) {
409
+ return (request) => {
410
+ const tiny = toTinyRequest(request);
411
+ const queue = [];
412
+ let whole = "";
413
+ let finished = false;
414
+ let failure;
415
+ let wake = null;
416
+ const notify = () => {
417
+ const resume = wake;
418
+ wake = null;
419
+ resume?.();
420
+ };
421
+ const push = (text) => {
422
+ if (finished || text === null || text === void 0) return;
423
+ const piece = String(text);
424
+ whole += piece;
425
+ queue.push(piece);
426
+ notify();
427
+ };
428
+ const finish = (error) => {
429
+ if (finished) return;
430
+ finished = true;
431
+ failure = error;
432
+ notify();
433
+ };
434
+ const settle = (work) => {
435
+ work.then(
436
+ () => finish(),
437
+ (error) => finish(error ?? new Error("The AI request failed"))
438
+ );
439
+ return work.then(
440
+ () => void 0,
441
+ () => void 0
442
+ );
443
+ };
444
+ const respondWith = {
445
+ string: (callback) => settle(Promise.resolve().then(async () => push(await callback(request.signal)))),
446
+ stream: (callback) => settle(Promise.resolve().then(() => callback(request.signal, (message) => push(message))))
447
+ };
448
+ request.signal.addEventListener("abort", () => finish(), { once: true });
449
+ fire("AIRequest", { request: tiny });
450
+ try {
451
+ handler(tiny, respondWith);
452
+ } catch (error) {
453
+ finish(error);
454
+ }
455
+ const html = request.action !== "edit";
456
+ return (async function* () {
457
+ let buffered = false;
458
+ for (; ; ) {
459
+ while (queue.length) {
460
+ const piece = queue.shift();
461
+ if (html && !buffered && /^\s*</.test(whole)) buffered = true;
462
+ if (!buffered) yield piece;
463
+ }
464
+ if (finished) break;
465
+ await new Promise((resolve) => wake = resolve);
466
+ }
467
+ if (request.signal.aborted) return;
468
+ if (failure !== void 0) {
469
+ fire("AIError", { error: failure });
470
+ throw failure instanceof Error ? failure : new Error(String(failure));
471
+ }
472
+ if (buffered) yield htmlToText(whole);
473
+ fire("AIResponse", { response: whole });
474
+ })();
475
+ };
476
+ }
477
+ var BLOCKS2;
478
+ var init_ai = __esm({
479
+ "src/ai.ts"() {
480
+ "use strict";
481
+ BLOCKS2 = /^(P|DIV|H[1-6]|LI|BLOCKQUOTE|PRE|TR|UL|OL|TABLE|SECTION|ARTICLE|HEADER|FOOTER)$/;
482
+ }
483
+ });
19
484
 
20
485
  // src/index.ts
21
486
  var src_exports = {};
@@ -37,7 +502,6 @@ var BUILT_IN = /* @__PURE__ */ new Set([
37
502
  "image",
38
503
  "table",
39
504
  "code",
40
- "codesample",
41
505
  "preview",
42
506
  "searchreplace",
43
507
  "fullscreen",
@@ -52,12 +516,12 @@ var BUILT_IN = /* @__PURE__ */ new Set([
52
516
  "tabfocus",
53
517
  "textpattern",
54
518
  "imagetools",
55
- "powerpaste",
56
- "importcss",
57
- "accordion"
519
+ "powerpaste"
58
520
  ]);
59
521
  var RENAMED = {
60
- tinycomments: "comments"
522
+ tinycomments: "comments",
523
+ tinymcespellchecker: "spellchecker",
524
+ inlinecss: "email"
61
525
  };
62
526
  var IGNORED = /* @__PURE__ */ new Set([
63
527
  "selector",
@@ -119,6 +583,9 @@ var IGNORED = /* @__PURE__ */ new Set([
119
583
  "valid_styles",
120
584
  "toolbar_mode",
121
585
  "toolbar_sticky",
586
+ "toolbar_sticky_offset",
587
+ "content_language",
588
+ "content_langs",
122
589
  "font_family_formats",
123
590
  "font_size_formats",
124
591
  "line_height_formats",
@@ -130,9 +597,180 @@ var IGNORED = /* @__PURE__ */ new Set([
130
597
  "quickbars_insert_toolbar",
131
598
  "mentions_fetch",
132
599
  "tinycomments_author",
133
- "tinycomments_author_name"
600
+ "tinycomments_author_name",
601
+ "codesample_languages",
602
+ "details_initial_state",
603
+ "details_serialized_state",
604
+ "tableofcontents_class",
605
+ "tableofcontents_depth",
606
+ "tableofcontents_header",
607
+ "tableofcontents_orderedlist",
608
+ "tableofcontents_includeheader",
609
+ // Highlighting is our own (highlight.js, lazy); Prism on the site's page isn't needed for it.
610
+ "codesample_global_prismjs",
611
+ "casechange_title_case_minors",
612
+ "permanentpen_properties",
613
+ "visualchars_default_state",
614
+ // save_* are wired in index.ts: the callbacks get the TinyMCE-style editor.
615
+ "save_enablewhendirty",
616
+ "save_onsavecallback",
617
+ "save_oncancelcallback",
618
+ "importcss_append",
619
+ "importcss_file_filter",
620
+ "importcss_selector_filter",
621
+ "importcss_groups",
622
+ "importcss_exclusive",
623
+ "importcss_selector_converter",
624
+ "templates",
625
+ // tinymcespellchecker: the checking goes through your service (spellchecker_languagetool_url or
626
+ // spellchecker_check, NovaProse's own options); Tiny's spellchecker_rpc_url is not used.
627
+ "spellchecker_active",
628
+ "spellchecker_language",
629
+ "spellchecker_languages",
630
+ "spellchecker_ignore_list",
631
+ "spellchecker_dialog",
632
+ "spellchecker_languagetool_url",
633
+ "spellchecker_check",
634
+ // a11ychecker: the level, ignored rules, decorative images, the alt length, a filter. HTML 5 is
635
+ // always checked, and there is no "more info" link.
636
+ "a11ychecker_level",
637
+ "a11ychecker_ignored_rules",
638
+ "a11ychecker_allow_decorative_images",
639
+ "a11y_advanced_options",
640
+ "a11ychecker_alt_text_max_length",
641
+ "a11ychecker_filter_issue",
642
+ "a11ychecker_html_version",
643
+ "a11ychecker_issue_url_callback",
644
+ // ai: ai_request is wired in index.ts (its events go to the TinyMCE-style editor); ai_shortcuts
645
+ // becomes the quick actions.
646
+ "ai_request",
647
+ "ai_shortcuts",
648
+ // inlinecss → the email plugin: the filters of what is put inline.
649
+ "inlinecss_selector_filter",
650
+ "inlinecss_file_filter",
651
+ // linkchecker: the service address (a server that answers our protocol, see the link checker
652
+ // guide) and preprocess; the highlight's look comes from the theme's CSS variables.
653
+ "linkchecker_service_url",
654
+ "linkchecker_preprocess",
655
+ "linkchecker_content_css",
656
+ // pageembed: the sizes (classes) and inline styles; the wrapper keeps TinyMCE's class.
657
+ "tiny_pageembed_classes",
658
+ "tiny_pageembed_inline_styles",
659
+ // fullpagehtml: what a page that doesn't say gets (doctype, title, encoding, body style), and
660
+ // whether the source code view shows the whole page.
661
+ "fullpagehtml_default_doctype",
662
+ "fullpagehtml_default_title",
663
+ "fullpagehtml_default_encoding",
664
+ "fullpagehtml_default_body_style",
665
+ "fullpagehtml_hide_in_source_view",
666
+ // mediaembed: the service address (a server that answers our protocol, see the embeds guide),
667
+ // the widest a card gets and inline styles; cards keep TinyMCE's summary card classes.
668
+ "mediaembed_service_url",
669
+ "mediaembed_max_width",
670
+ "mediaembed_inline_styles",
671
+ // advtable: your series for the numbers column (their generators give each row's value).
672
+ "advtable_value_series",
673
+ // advcode: the code laid out on open, getContent laid out too (index.ts); the code editor opens
674
+ // in a dialog with a full screen button, so advcode_inline isn't needed.
675
+ "advcode_prettify_editor",
676
+ "advcode_prettify_getcontent",
677
+ "advcode_inline",
678
+ // view_show and sidebar_show: opened when the editor is ready (index.ts).
679
+ "view_show",
680
+ "sidebar_show",
681
+ // editimage: the toolbar, the hosts with cookies, your way to fetch an image (editimage_fetch_image
682
+ // gets an <img>). Images are read with CORS, so the CORS host list, the proxy and the upload timeout
683
+ // aren't needed: fetchImage goes through your server instead.
684
+ "editimage_toolbar",
685
+ "editimage_credentials_hosts",
686
+ "editimage_fetch_image",
687
+ "editimage_cors_hosts",
688
+ "editimage_proxy",
689
+ "editimage_proxy_service_url",
690
+ "editimage_upload_timeout",
691
+ // autocorrect: corrections run in the browser, so Tiny's service address isn't needed.
692
+ "autocorrect_autocorrect",
693
+ "autocorrect_capitalize",
694
+ "autocorrect_service_url",
695
+ // typography: the language, the languages of the menu, the rules (Typograf rule ids), tags left alone.
696
+ "typography_default_lang",
697
+ "typography_langs",
698
+ "typography_rules",
699
+ "typography_ignore",
700
+ // text_patterns: false turns the patterns off; a list (and text_patterns_lookup) is TinyMCE's
701
+ // patterns, run through this editor's formatter and execCommand (index.ts).
702
+ "text_patterns",
703
+ "text_patterns_lookup",
704
+ "template_replace_values",
705
+ "template_preview_replace_values",
706
+ "template_selected_content_classes",
707
+ "template_cdate_classes",
708
+ "template_mdate_classes",
709
+ "template_cdate_format",
710
+ "template_mdate_format"
134
711
  ]);
135
712
  var list = (value) => (Array.isArray(value) ? value.join(" ") : String(value ?? "")).split(/[\s,]+/).filter(Boolean);
713
+ function activePlugins(config, has) {
714
+ return list(config.plugins).filter((name) => BUILT_IN.has(name) || has(RENAMED[name] ?? name));
715
+ }
716
+ function typographyRule(id) {
717
+ if (/\/dash\//.test(id)) return "dashes";
718
+ if (/^common\/punctuation\/(quote|apostrophe)$/.test(id)) return "quotes";
719
+ if (id === "common/punctuation/hellip") return "ellipsis";
720
+ if (id === "common/punctuation/delDoublePunctuation" || id.startsWith("common/space/"))
721
+ return "spaces";
722
+ if (id === "common/symbols/arrow") return "arrows";
723
+ if (id.startsWith("common/symbols/")) return "symbols";
724
+ if (id === "common/number/fraction") return "fractions";
725
+ if (id.startsWith("common/number/")) return "math";
726
+ if (id.startsWith("common/nbsp/")) return "nbsp";
727
+ return null;
728
+ }
729
+ var TYPOGRAPHY_TAGS = {
730
+ code: ["code", "code_block"],
731
+ pre: ["code_block"],
732
+ a: ["link"],
733
+ strong: ["bold"],
734
+ b: ["bold"],
735
+ em: ["italic"],
736
+ i: ["italic"],
737
+ blockquote: ["blockquote"]
738
+ };
739
+ function typographyOptions(config) {
740
+ const out = {};
741
+ const lang = config.typography_default_lang;
742
+ const first = Array.isArray(lang) ? lang[0] : lang;
743
+ if (typeof first === "string" && first) out.language = first.replace(/_/g, "-");
744
+ const langs = config.typography_langs;
745
+ const codes = Array.isArray(langs) ? langs : langs && typeof langs === "object" ? Object.keys(langs) : [];
746
+ const languages = codes.filter((c) => typeof c === "string").map((c) => c.replace(/_/g, "-"));
747
+ if (languages.length) out.languages = languages;
748
+ if (Array.isArray(config.typography_rules)) {
749
+ const on = new Set(
750
+ config.typography_rules.map((id) => typeof id === "string" ? typographyRule(id) : null)
751
+ );
752
+ out.rules = Object.fromEntries(
753
+ [
754
+ "quotes",
755
+ "dashes",
756
+ "ellipsis",
757
+ "symbols",
758
+ "arrows",
759
+ "math",
760
+ "fractions",
761
+ "spaces",
762
+ "nbsp"
763
+ ].map((rule) => [rule, on.has(rule)])
764
+ );
765
+ }
766
+ if (Array.isArray(config.typography_ignore)) {
767
+ const ignore = config.typography_ignore.flatMap(
768
+ (tag) => typeof tag === "string" ? TYPOGRAPHY_TAGS[tag.toLowerCase().replace(/\[.*$/, "")] ?? [] : []
769
+ );
770
+ if (ignore.length) out.ignore = [...new Set(ignore)];
771
+ }
772
+ return out;
773
+ }
136
774
  function parseFormats(value) {
137
775
  if (typeof value !== "string") return void 0;
138
776
  return value.split(";").map((item) => item.trim()).filter(Boolean).map((item) => {
@@ -215,6 +853,23 @@ function toStyleFormats(value) {
215
853
  return spec ? [{ title, ...spec }] : [];
216
854
  });
217
855
  }
856
+ function toAiShortcuts(value) {
857
+ return value.flatMap((item) => {
858
+ if (!item || typeof item !== "object") return [];
859
+ const raw = item;
860
+ const title = typeof raw.title === "string" ? raw.title : "";
861
+ if (!title) return [];
862
+ if (Array.isArray(raw.subprompts)) return [{ title, items: toAiShortcuts(raw.subprompts) }];
863
+ if (typeof raw.prompt !== "string") return [];
864
+ return [
865
+ {
866
+ title,
867
+ prompt: raw.prompt,
868
+ ...typeof raw.selection === "boolean" ? { selection: raw.selection } : {}
869
+ }
870
+ ];
871
+ });
872
+ }
218
873
  function mapOptions(config) {
219
874
  const unknown = Object.keys(config).filter((key) => !IGNORED.has(key));
220
875
  const plugins = [];
@@ -225,11 +880,18 @@ function mapOptions(config) {
225
880
  if ((0, import_core.isPluginRegistered)(target)) plugins.push(target);
226
881
  else missingPlugins.push(name);
227
882
  }
883
+ if (plugins.includes("ai") && !plugins.includes("suggestions")) {
884
+ plugins.splice(plugins.indexOf("ai"), 0, "suggestions");
885
+ }
886
+ if (plugins.includes("mediaembed") && !plugins.includes("media")) {
887
+ plugins.splice(plugins.indexOf("mediaembed"), 0, "media");
888
+ }
228
889
  const options = { plugins };
229
890
  if (config.toolbar === false) options.toolbar = false;
230
891
  else if (Array.isArray(config.toolbar)) options.toolbar = config.toolbar.join(" | ");
231
892
  else if (typeof config.toolbar === "string") options.toolbar = config.toolbar;
232
893
  if (config.menubar !== void 0) options.menubar = config.menubar;
894
+ if (config.text_patterns === false) options.textPatterns = false;
233
895
  if (typeof config.statusbar === "boolean") options.statusbar = config.statusbar;
234
896
  if (typeof config.placeholder === "string") options.placeholder = config.placeholder;
235
897
  if (config.readonly === true) options.editable = false;
@@ -269,10 +931,16 @@ function mapOptions(config) {
269
931
  options.blockFormats = blocks.map(({ label, value }) => ({ label, block: value.toLowerCase() })).filter((f) => known.includes(f.block));
270
932
  }
271
933
  if (typeof config.language === "string") options.language = config.language.replace("_", "-");
272
- if (config.toolbar_mode === "sliding" || config.toolbar_mode === "wrap") {
934
+ if (typeof config.content_language === "string" && config.content_language)
935
+ options.contentLanguage = config.content_language.replace(/_/g, "-");
936
+ options.contentLangs = Array.isArray(config.content_langs) ? config.content_langs.flatMap((entry) => {
937
+ const { code, title } = entry ?? {};
938
+ return typeof code === "string" ? [{ code, ...typeof title === "string" ? { title } : {} }] : [];
939
+ }) : [];
940
+ if (typeof config.toolbar_sticky_offset === "number")
941
+ options.toolbarStickyOffset = config.toolbar_sticky_offset;
942
+ if (config.toolbar_mode === "floating" || config.toolbar_mode === "sliding" || config.toolbar_mode === "scrolling" || config.toolbar_mode === "wrap") {
273
943
  options.toolbarMode = config.toolbar_mode;
274
- } else if (config.toolbar_mode === "floating" || config.toolbar_mode === "scrolling") {
275
- options.toolbarMode = "sliding";
276
944
  }
277
945
  if (config.inline === true) options.mode = "inline";
278
946
  if (config.paste_as_text === true) options.pasteAsText = true;
@@ -310,353 +978,322 @@ function mapOptions(config) {
310
978
  return handler(info, progress);
311
979
  };
312
980
  options.uploadImage = upload;
313
- }
314
- if (typeof config.file_picker_callback === "function") {
315
- const pick = config.file_picker_callback;
316
- if (typeof config.file_picker_types === "string") {
317
- options.filePickerTypes = list(config.file_picker_types).filter(
318
- (type) => type === "file" || type === "image" || type === "media"
319
- );
320
- }
321
- options.filePicker = ({ type, value }) => new Promise(
322
- (resolve) => pick((url, meta = {}) => resolve({ url, ...meta }), value, {
323
- filetype: type,
324
- fieldname: "src"
325
- })
326
- );
327
- }
328
- const pluginOptions = {};
329
- if (config.autosave_interval || config.autosave_retention || config.autosave_prefix) {
330
- const seconds = (value) => parseInt(String(value), 10);
331
- pluginOptions.autosave = {
332
- ...config.autosave_interval ? { delay: seconds(config.autosave_interval) * 1e3 } : {},
333
- ...config.autosave_retention ? { retention: seconds(config.autosave_retention) } : {},
334
- ...config.autosave_prefix ? { key: String(config.autosave_prefix) } : {}
335
- };
336
- }
337
- if (config.quickbars_selection_toolbar !== void 0 || config.quickbars_insert_toolbar !== void 0) {
338
- pluginOptions.quickbars = {
339
- ...config.quickbars_selection_toolbar !== void 0 ? { selection: config.quickbars_selection_toolbar } : {},
340
- ...config.quickbars_insert_toolbar !== void 0 ? { insert: config.quickbars_insert_toolbar } : {}
341
- };
342
- }
343
- if (typeof config.mentions_fetch === "function") {
344
- const fetch = config.mentions_fetch;
345
- pluginOptions.mentions = {
346
- fetch: (term) => new Promise((resolve) => fetch({ term }, resolve))
347
- };
348
- }
349
- if (config.tinycomments_author) {
350
- pluginOptions.comments = {
351
- author: {
352
- id: String(config.tinycomments_author),
353
- name: String(config.tinycomments_author_name ?? config.tinycomments_author)
354
- }
355
- };
356
- }
357
- if (Object.keys(pluginOptions).length) options.pluginOptions = pluginOptions;
358
- return { options, unknown, missingPlugins };
359
- }
360
-
361
- // src/editor.ts
362
- var import_core2 = require("@novaprose/core");
363
-
364
- // src/dialog.ts
365
- var uid = 0;
366
- var nextId = () => `nova-compat-field-${++uid}`;
367
- function el(tag, className, text) {
368
- const node = document.createElement(tag);
369
- if (className) node.className = className;
370
- if (text !== void 0) node.textContent = text;
371
- return node;
372
- }
373
- function safeHtml(html) {
374
- const template = document.createElement("template");
375
- template.innerHTML = html;
376
- template.content.querySelectorAll("script, style, iframe, object, embed, link, meta, base, form").forEach((node) => node.remove());
377
- template.content.querySelectorAll("*").forEach((node) => {
378
- for (const attr of [...node.attributes]) {
379
- const value = attr.value.trim().toLowerCase();
380
- if (attr.name.startsWith("on") || /^(javascript|vbscript|data):/.test(value)) {
381
- node.removeAttribute(attr.name);
382
- }
383
- }
384
- });
385
- return template.content;
386
- }
387
- function openSpecDialog(editor, spec, reopen) {
388
- const controls = /* @__PURE__ */ new Map();
389
- const tabs = /* @__PURE__ */ new Map();
390
- let currentTab = "";
391
- let closedByApi = false;
392
- let handle = null;
393
- const notifyChange = (name) => spec.onChange?.(api, { name });
394
- function field(item, input) {
395
- const id = nextId();
396
- input.id = id;
397
- const wrap = el("div", "nova-field");
398
- if (item.label) {
399
- const label = el("label", "nova-label", item.label);
400
- label.htmlFor = id;
401
- wrap.append(label);
402
- }
403
- wrap.append(input);
404
- return wrap;
405
- }
406
- function render(item) {
407
- const name = item.name ?? "";
408
- const enabled = item.enabled !== false && item.disabled !== true;
409
- switch (item.type) {
410
- case "input":
411
- case "urlinput":
412
- case "colorinput": {
413
- const input = el("input", "nova-input");
414
- input.type = item.type === "colorinput" ? "color" : item.type === "urlinput" ? "url" : "text";
415
- if (item.inputMode) input.inputMode = item.inputMode;
416
- if (item.placeholder) input.placeholder = item.placeholder;
417
- input.disabled = !enabled;
418
- input.addEventListener("input", () => notifyChange(name));
419
- if (name) {
420
- controls.set(name, {
421
- // urlinput хранит { value }, остальные — строку.
422
- get: () => item.type === "urlinput" ? { value: input.value } : input.value,
423
- set: (value) => {
424
- input.value = String(
425
- item.type === "urlinput" && value && typeof value === "object" ? value.value ?? "" : value ?? ""
426
- );
427
- },
428
- focus: () => input.focus(),
429
- setEnabled: (on) => input.disabled = !on
430
- });
431
- }
432
- return field(item, input);
433
- }
434
- case "textarea": {
435
- const input = el("textarea", "nova-input");
436
- input.rows = item.maximized ? 10 : 4;
437
- if (item.placeholder) input.placeholder = item.placeholder;
438
- input.disabled = !enabled;
439
- input.addEventListener("input", () => notifyChange(name));
440
- if (name) {
441
- controls.set(name, {
442
- get: () => input.value,
443
- set: (value) => input.value = String(value ?? ""),
444
- focus: () => input.focus(),
445
- setEnabled: (on) => input.disabled = !on
446
- });
447
- }
448
- return field(item, input);
449
- }
450
- case "checkbox": {
451
- const input = el("input", "nova-checkbox");
452
- input.type = "checkbox";
453
- input.id = nextId();
454
- input.disabled = !enabled;
455
- input.addEventListener("change", () => notifyChange(name));
456
- const label = el("label", void 0, item.label ?? "");
457
- label.htmlFor = input.id;
458
- if (name) {
459
- controls.set(name, {
460
- get: () => input.checked,
461
- set: (value) => input.checked = Boolean(value),
462
- focus: () => input.focus(),
463
- setEnabled: (on) => input.disabled = !on
464
- });
465
- }
466
- const wrap = el("div", "nova-field nova-field-inline");
467
- wrap.append(input, label);
468
- return wrap;
469
- }
470
- case "selectbox":
471
- case "listbox": {
472
- const select = el("select", "nova-input nova-select");
473
- for (const option of item.items ?? []) {
474
- const node = el("option", void 0, option.text);
475
- node.value = option.value;
476
- select.append(node);
477
- }
478
- select.disabled = !enabled;
479
- select.addEventListener("change", () => notifyChange(name));
480
- if (name) {
481
- controls.set(name, {
482
- get: () => select.value,
483
- set: (value) => select.value = String(value ?? ""),
484
- focus: () => select.focus(),
485
- setEnabled: (on) => select.disabled = !on
486
- });
487
- }
488
- return field(item, select);
489
- }
490
- case "button": {
491
- const button = el(
492
- "button",
493
- item.primary || item.buttonType === "primary" ? "nova-button nova-button-primary" : "nova-button",
494
- item.text ?? ""
495
- );
496
- button.type = "button";
497
- button.disabled = !enabled;
498
- button.addEventListener("click", () => spec.onAction?.(api, { name }));
499
- if (name) {
500
- controls.set(name, {
501
- get: () => void 0,
502
- set: () => {
503
- },
504
- focus: () => button.focus(),
505
- setEnabled: (on) => button.disabled = !on
506
- });
507
- }
508
- return button;
509
- }
510
- case "htmlpanel": {
511
- const panel = el("div", "nova-compat-html");
512
- panel.append(safeHtml(item.html ?? ""));
513
- return panel;
514
- }
515
- case "alertbanner": {
516
- const banner = el("p", `nova-compat-alert is-${item.level ?? "info"}`, item.text ?? "");
517
- banner.setAttribute("role", item.level === "error" ? "alert" : "status");
518
- return banner;
519
- }
520
- case "label": {
521
- const group = el("div", "nova-compat-group");
522
- group.append(el("p", "nova-label", item.label ?? ""));
523
- for (const child of item.items ?? []) {
524
- const node = render(child);
525
- if (node) group.append(node);
526
- }
527
- return group;
528
- }
529
- case "grid":
530
- case "bar": {
531
- const grid = el("div", "nova-compat-grid");
532
- const columns = item.type === "bar" ? item.items?.length ?? 1 : item.columns === "auto" ? 2 : item.columns ?? 2;
533
- grid.style.gridTemplateColumns = `repeat(${Number(columns) || 2}, minmax(0, 1fr))`;
534
- for (const child of item.items ?? []) {
535
- const node = render(child);
536
- if (node) grid.append(node);
537
- }
538
- return grid;
539
- }
540
- default:
541
- console.warn(`[nova] tinymce-compat: dialog component "${item.type}" is not supported yet`);
542
- return null;
981
+ }
982
+ if (typeof config.file_picker_callback === "function") {
983
+ const pick = config.file_picker_callback;
984
+ if (typeof config.file_picker_types === "string") {
985
+ options.filePickerTypes = list(config.file_picker_types).filter(
986
+ (type) => type === "file" || type === "image" || type === "media"
987
+ );
543
988
  }
989
+ options.filePicker = ({ type, value }) => new Promise(
990
+ (resolve) => pick((url, meta = {}) => resolve({ url, ...meta }), value, {
991
+ filetype: type,
992
+ fieldname: "src"
993
+ })
994
+ );
544
995
  }
545
- const body = el("div", "nova-compat-dialog nova-form");
546
- if (spec.body.type === "tabpanel") {
547
- const tabList = el("div", "nova-compat-tabs");
548
- tabList.setAttribute("role", "tablist");
549
- body.append(tabList);
550
- spec.body.tabs.forEach((tab, index) => {
551
- const name = tab.name ?? tab.title;
552
- const button = el("button", "nova-compat-tab", tab.title);
553
- button.type = "button";
554
- button.setAttribute("role", "tab");
555
- const panel = el("div", "nova-compat-tabpanel");
556
- panel.setAttribute("role", "tabpanel");
557
- for (const item of tab.items) {
558
- const node = render(item);
559
- if (node) panel.append(node);
996
+ const pluginOptions = {};
997
+ if (config.autosave_interval || config.autosave_retention || config.autosave_prefix) {
998
+ const seconds = (value) => parseInt(String(value), 10);
999
+ pluginOptions.autosave = {
1000
+ ...config.autosave_interval ? { delay: seconds(config.autosave_interval) * 1e3 } : {},
1001
+ ...config.autosave_retention ? { retention: seconds(config.autosave_retention) } : {},
1002
+ ...config.autosave_prefix ? { key: String(config.autosave_prefix) } : {}
1003
+ };
1004
+ }
1005
+ if (config.quickbars_selection_toolbar !== void 0 || config.quickbars_insert_toolbar !== void 0) {
1006
+ pluginOptions.quickbars = {
1007
+ ...config.quickbars_selection_toolbar !== void 0 ? { selection: config.quickbars_selection_toolbar } : {},
1008
+ ...config.quickbars_insert_toolbar !== void 0 ? { insert: config.quickbars_insert_toolbar } : {}
1009
+ };
1010
+ }
1011
+ if (typeof config.mentions_fetch === "function") {
1012
+ const fetch = config.mentions_fetch;
1013
+ pluginOptions.mentions = {
1014
+ fetch: (term) => new Promise((resolve) => fetch({ term }, resolve))
1015
+ };
1016
+ }
1017
+ if (config.tinycomments_author) {
1018
+ pluginOptions.comments = {
1019
+ author: {
1020
+ id: String(config.tinycomments_author),
1021
+ name: String(config.tinycomments_author_name ?? config.tinycomments_author)
560
1022
  }
561
- button.addEventListener("click", () => api.showTab(name));
562
- tabs.set(name, { button, panel });
563
- tabList.append(button);
564
- body.append(panel);
565
- if (index === 0) currentTab = name;
1023
+ };
1024
+ }
1025
+ if (Array.isArray(config.codesample_languages)) {
1026
+ const languages = config.codesample_languages.flatMap((item) => {
1027
+ const { text, value } = item ?? {};
1028
+ return typeof value === "string" && value ? [{ value, label: typeof text === "string" && text ? text : value }] : [];
566
1029
  });
567
- } else {
568
- for (const item of spec.body.items) {
569
- const node = render(item);
570
- if (node) body.append(node);
571
- }
1030
+ pluginOptions.codesample = { languages };
572
1031
  }
573
- const buttons = spec.buttons ?? [];
574
- const submit = buttons.find((b) => b.type === "submit");
575
- const custom = buttons.filter((b) => b.type === "custom");
576
- if (custom.length) {
577
- const row = el("div", "nova-compat-actions");
578
- for (const b of custom) {
579
- const button = el(
580
- "button",
581
- b.primary ? "nova-button nova-button-primary" : "nova-button",
582
- b.text
583
- );
584
- button.type = "button";
585
- button.disabled = b.enabled === false;
586
- button.addEventListener("click", () => spec.onAction?.(api, { name: b.name ?? b.text }));
587
- if (b.name) {
588
- controls.set(b.name, {
589
- get: () => void 0,
590
- set: () => {
591
- },
592
- focus: () => button.focus(),
593
- setEnabled: (on) => button.disabled = !on
594
- });
595
- }
596
- row.append(button);
1032
+ const detailsState = (value) => value === "inherited" || value === "collapsed" || value === "expanded" ? value : void 0;
1033
+ if (config.details_initial_state || config.details_serialized_state) {
1034
+ pluginOptions.accordion = {
1035
+ ...detailsState(config.details_initial_state) ? { initialState: detailsState(config.details_initial_state) } : {},
1036
+ ...detailsState(config.details_serialized_state) ? { serializedState: detailsState(config.details_serialized_state) } : {}
1037
+ };
1038
+ }
1039
+ if (list(config.plugins).includes("tableofcontents")) {
1040
+ pluginOptions.tableofcontents = {
1041
+ className: typeof config.tableofcontents_class === "string" ? config.tableofcontents_class : "mce-toc",
1042
+ titleTag: typeof config.tableofcontents_header === "string" ? config.tableofcontents_header : "h2",
1043
+ ...config.tableofcontents_depth !== void 0 ? { depth: Number(config.tableofcontents_depth) } : {},
1044
+ ...config.tableofcontents_orderedlist ? { orderedList: true } : {},
1045
+ ...config.tableofcontents_includeheader === false ? { title: "" } : {}
1046
+ };
1047
+ }
1048
+ if (Array.isArray(config.casechange_title_case_minors)) {
1049
+ pluginOptions.casechange = {
1050
+ titleCaseMinors: config.casechange_title_case_minors.map(String)
1051
+ };
1052
+ }
1053
+ if (config.permanentpen_properties && typeof config.permanentpen_properties === "object") {
1054
+ pluginOptions.permanentpen = { properties: { ...config.permanentpen_properties } };
1055
+ }
1056
+ if (config.visualchars_default_state === true) pluginOptions.visualchars = { default: true };
1057
+ const importcss = Object.fromEntries(
1058
+ [
1059
+ ["append", config.importcss_append],
1060
+ ["fileFilter", config.importcss_file_filter],
1061
+ ["selectorFilter", config.importcss_selector_filter],
1062
+ ["groups", config.importcss_groups],
1063
+ ["exclusive", config.importcss_exclusive],
1064
+ ["converter", config.importcss_selector_converter]
1065
+ ].filter(([, value]) => value !== void 0)
1066
+ );
1067
+ if (Object.keys(importcss).length) pluginOptions.importcss = importcss;
1068
+ const templates = config.templates;
1069
+ const template = Object.fromEntries(
1070
+ [
1071
+ [
1072
+ "templates",
1073
+ typeof templates === "function" ? () => new Promise(
1074
+ (resolve) => templates(resolve)
1075
+ ) : templates
1076
+ ],
1077
+ ["values", config.template_replace_values],
1078
+ ["previewValues", config.template_preview_replace_values],
1079
+ ["selectedContentClasses", config.template_selected_content_classes],
1080
+ ["creationDateClasses", config.template_cdate_classes],
1081
+ ["modifiedDateClasses", config.template_mdate_classes],
1082
+ ["creationDateFormat", config.template_cdate_format],
1083
+ ["modifiedDateFormat", config.template_mdate_format]
1084
+ ].filter(([, value]) => value !== void 0)
1085
+ );
1086
+ if (Object.keys(template).length) pluginOptions.template = template;
1087
+ const spellchecker = {};
1088
+ if (typeof config.spellchecker_active === "boolean")
1089
+ spellchecker.active = config.spellchecker_active;
1090
+ const spellLanguage = config.content_language ?? config.spellchecker_language;
1091
+ if (typeof spellLanguage === "string" && spellLanguage)
1092
+ spellchecker.language = spellLanguage.replace(/_/g, "-");
1093
+ if (typeof config.spellchecker_languages === "string") {
1094
+ spellchecker.languages = config.spellchecker_languages.split(",").map((pair) => pair.split("=")).filter(
1095
+ (pair) => pair.length === 2 && !!pair[0].trim() && !!pair[1].trim()
1096
+ ).map(([name, code]) => ({ name: name.trim(), code: code.trim().replace(/_/g, "-") }));
1097
+ }
1098
+ const ignore = config.spellchecker_ignore_list;
1099
+ const ignored = Array.isArray(ignore) ? ignore : ignore && typeof ignore === "object" ? Object.values(ignore).flatMap((words) => Array.isArray(words) ? words : []) : [];
1100
+ if (ignored.length)
1101
+ spellchecker.ignore = ignored.filter((w) => typeof w === "string");
1102
+ if (typeof config.spellchecker_check === "function")
1103
+ spellchecker.check = config.spellchecker_check;
1104
+ if (typeof config.spellchecker_languagetool_url === "string")
1105
+ spellchecker.languageTool = { url: config.spellchecker_languagetool_url };
1106
+ if (Object.keys(spellchecker).length) pluginOptions.spellchecker = spellchecker;
1107
+ if (list(config.plugins).includes("a11ychecker")) {
1108
+ const a11y = {
1109
+ allowDecorativeImages: (config.a11ychecker_allow_decorative_images ?? config.a11y_advanced_options) === true
1110
+ };
1111
+ if (typeof config.a11ychecker_level === "string") {
1112
+ a11y.level = config.a11ychecker_level.toLowerCase();
597
1113
  }
598
- body.append(row);
1114
+ if (typeof config.a11ychecker_ignored_rules === "string") {
1115
+ a11y.ignoredRules = config.a11ychecker_ignored_rules.split(",").map((rule) => rule.trim()).filter(Boolean);
1116
+ }
1117
+ if (typeof config.a11ychecker_alt_text_max_length === "number") {
1118
+ a11y.altTextMaxLength = config.a11ychecker_alt_text_max_length;
1119
+ }
1120
+ const filter = config.a11ychecker_filter_issue;
1121
+ if (typeof filter === "function") {
1122
+ a11y.filterIssue = (issue) => filter({
1123
+ ...issue,
1124
+ id: issue.rule,
1125
+ contentID: issue.text
1126
+ }) !== false;
1127
+ }
1128
+ pluginOptions.a11ychecker = a11y;
599
1129
  }
600
- const api = {
601
- getData: () => {
602
- const data = {};
603
- controls.forEach((control, name) => {
604
- const value = control.get();
605
- if (value !== void 0) data[name] = value;
606
- });
607
- return data;
608
- },
609
- setData: (data) => {
610
- for (const [name, value] of Object.entries(data)) controls.get(name)?.set(value);
611
- },
612
- close: () => {
613
- closedByApi = true;
614
- handle?.close();
615
- },
616
- block: () => handle?.setBusy(true),
617
- unblock: () => handle?.setBusy(false),
618
- focus: (name) => controls.get(name)?.focus(),
619
- disable: (name) => controls.get(name)?.setEnabled(false),
620
- enable: (name) => controls.get(name)?.setEnabled(true),
621
- showTab: (name) => {
622
- if (!tabs.has(name)) return;
623
- const old = currentTab;
624
- currentTab = name;
625
- tabs.forEach(({ button, panel }, key) => {
626
- const on = key === name;
627
- button.setAttribute("aria-selected", String(on));
628
- button.tabIndex = on ? 0 : -1;
629
- panel.hidden = !on;
630
- });
631
- if (old && old !== name) spec.onTabChange?.(api, { newTabName: name, oldTabName: old });
632
- },
633
- redial: (next) => {
634
- api.close();
635
- Object.assign(api, reopen(next));
1130
+ const aiShortcuts = config.ai_shortcuts;
1131
+ if (aiShortcuts === false || Array.isArray(aiShortcuts) && !aiShortcuts.length) {
1132
+ pluginOptions.ai = { shortcuts: false };
1133
+ } else if (Array.isArray(aiShortcuts)) {
1134
+ pluginOptions.ai = { shortcuts: toAiShortcuts(aiShortcuts) };
1135
+ }
1136
+ const email = {};
1137
+ if (["string", "function"].includes(typeof config.inlinecss_selector_filter) || config.inlinecss_selector_filter instanceof RegExp)
1138
+ email.selectorFilter = config.inlinecss_selector_filter;
1139
+ if (["string", "function"].includes(typeof config.inlinecss_file_filter) || config.inlinecss_file_filter instanceof RegExp)
1140
+ email.fileFilter = config.inlinecss_file_filter;
1141
+ if (Object.keys(email).length) pluginOptions.email = email;
1142
+ const autocorrect = {};
1143
+ if (typeof config.autocorrect_autocorrect === "boolean")
1144
+ autocorrect.autocorrect = config.autocorrect_autocorrect;
1145
+ if (typeof config.autocorrect_capitalize === "boolean")
1146
+ autocorrect.capitalize = config.autocorrect_capitalize;
1147
+ if (Object.keys(autocorrect).length) pluginOptions.autocorrect = autocorrect;
1148
+ const linkchecker = {};
1149
+ if (typeof config.linkchecker_service_url === "string")
1150
+ linkchecker.serviceUrl = config.linkchecker_service_url;
1151
+ const preprocess = config.linkchecker_preprocess;
1152
+ if (typeof preprocess === "function") {
1153
+ linkchecker.preprocess = (url) => {
1154
+ const out = preprocess({ url });
1155
+ return typeof out?.url === "string" ? out.url : url;
1156
+ };
1157
+ }
1158
+ if (Object.keys(linkchecker).length) pluginOptions.linkchecker = linkchecker;
1159
+ if (plugins.includes("pageembed")) {
1160
+ const classes = config.tiny_pageembed_classes;
1161
+ pluginOptions.pageembed = {
1162
+ className: "tiny-pageembed",
1163
+ sizes: Array.isArray(classes) ? classes.filter(
1164
+ (size) => !!size && typeof size.value === "string"
1165
+ ).map((size) => ({
1166
+ value: size.value,
1167
+ ...typeof size.text === "string" ? { text: size.text } : {}
1168
+ })) : ["21by9", "16by9", "4by3", "1by1"].map((ratio) => ({
1169
+ value: `tiny-pageembed--${ratio}`
1170
+ })),
1171
+ inlineStyles: config.tiny_pageembed_inline_styles === true
1172
+ };
1173
+ }
1174
+ if (plugins.includes("fullpagehtml")) {
1175
+ const fullpagehtml = {};
1176
+ const pick = (option, key) => {
1177
+ if (typeof config[option] === "string") fullpagehtml[key] = config[option];
1178
+ };
1179
+ pick("fullpagehtml_default_doctype", "doctype");
1180
+ pick("fullpagehtml_default_title", "title");
1181
+ pick("fullpagehtml_default_encoding", "encoding");
1182
+ pick("fullpagehtml_default_body_style", "bodyStyle");
1183
+ if (config.fullpagehtml_hide_in_source_view === true) fullpagehtml.hideInSourceView = true;
1184
+ if (Object.keys(fullpagehtml).length) pluginOptions.fullpagehtml = fullpagehtml;
1185
+ }
1186
+ if (plugins.includes("mediaembed")) {
1187
+ const mediaembed = {
1188
+ className: "ephox-summary-card",
1189
+ inlineStyles: config.mediaembed_inline_styles === true
1190
+ };
1191
+ if (typeof config.mediaembed_service_url === "string" && config.mediaembed_service_url)
1192
+ mediaembed.serviceUrl = config.mediaembed_service_url;
1193
+ const maxWidth = Number(config.mediaembed_max_width);
1194
+ if (config.mediaembed_max_width !== void 0 && Number.isFinite(maxWidth))
1195
+ mediaembed.maxWidth = maxWidth;
1196
+ pluginOptions.mediaembed = mediaembed;
1197
+ }
1198
+ const valueSeries = config.advtable_value_series;
1199
+ if (plugins.includes("advtable") && valueSeries && typeof valueSeries === "object") {
1200
+ const series = {};
1201
+ for (const [name, def] of Object.entries(valueSeries)) {
1202
+ const { title, generator } = def ?? {};
1203
+ if (typeof title !== "string" || typeof generator !== "function") continue;
1204
+ let prev;
1205
+ series[name] = {
1206
+ title,
1207
+ value: (index) => {
1208
+ if (index === 0) prev = void 0;
1209
+ const info = {
1210
+ sectionType: "tbody",
1211
+ cellType: "td",
1212
+ getRowType: () => "body",
1213
+ classes: [],
1214
+ direction: "column",
1215
+ prev
1216
+ };
1217
+ const out = generator(
1218
+ info,
1219
+ index,
1220
+ 0
1221
+ );
1222
+ prev = out;
1223
+ const value = out?.value;
1224
+ return typeof value === "string" || typeof value === "number" ? String(value) : void 0;
1225
+ }
1226
+ };
636
1227
  }
637
- };
638
- if (spec.initialData) api.setData(spec.initialData);
639
- if (currentTab) api.showTab(currentTab);
640
- handle = editor.ui.openDialog({
641
- title: spec.title,
642
- body,
643
- ...submit ? { submitLabel: submit.text } : {},
644
- ...spec.size === "large" ? { size: "large" } : {},
645
- onSubmit: () => {
646
- spec.onSubmit?.(api);
647
- return closedByApi;
648
- },
649
- onClose: () => {
650
- if (!closedByApi) spec.onCancel?.(api);
651
- spec.onClose?.();
1228
+ if (Object.keys(series).length) pluginOptions.advtable = { series };
1229
+ }
1230
+ if (plugins.includes("editimage")) {
1231
+ const editimage = {};
1232
+ if (typeof config.editimage_toolbar === "string") editimage.toolbar = config.editimage_toolbar;
1233
+ if (Array.isArray(config.editimage_credentials_hosts))
1234
+ editimage.credentialsHosts = config.editimage_credentials_hosts.filter(
1235
+ (host) => typeof host === "string"
1236
+ );
1237
+ const fetchImage = config.editimage_fetch_image;
1238
+ if (typeof fetchImage === "function") {
1239
+ editimage.fetchImage = (src) => {
1240
+ const img = document.createElement("img");
1241
+ img.src = src;
1242
+ return fetchImage(img);
1243
+ };
652
1244
  }
653
- });
654
- return api;
1245
+ if (Object.keys(editimage).length) pluginOptions.editimage = editimage;
1246
+ }
1247
+ if (plugins.includes("advcode") && typeof config.advcode_prettify_editor === "boolean")
1248
+ pluginOptions.advcode = { prettify: config.advcode_prettify_editor };
1249
+ const typography = typographyOptions(config);
1250
+ if (Object.keys(typography).length) pluginOptions.typography = typography;
1251
+ if (Object.keys(pluginOptions).length) options.pluginOptions = pluginOptions;
1252
+ return { options, unknown, missingPlugins };
655
1253
  }
656
1254
 
657
1255
  // src/editor.ts
1256
+ var import_core2 = require("@novaprose/core");
658
1257
  var import_prosemirror_state = require("prosemirror-state");
659
- var serializer = new import_core2.HTMLSerializer();
1258
+ var dialogs = null;
1259
+ var dialogsLoading = null;
1260
+ function loadDialogs() {
1261
+ dialogsLoading ??= Promise.resolve().then(() => (init_dialog2(), dialog_exports)).then((module2) => dialogs = module2);
1262
+ return dialogsLoading;
1263
+ }
1264
+ function openDialog(core, spec, reopen) {
1265
+ if (dialogs) return dialogs.openSpecDialog(core, spec, reopen);
1266
+ let real = null;
1267
+ let data = { ...spec.initialData ?? {} };
1268
+ const queue = [];
1269
+ void loadDialogs().then(
1270
+ (module2) => {
1271
+ real = module2.openSpecDialog(core, { ...spec, initialData: data }, reopen);
1272
+ for (const call of queue.splice(0)) call(real);
1273
+ },
1274
+ (error) => console.error("[nova] windowManager: could not load dialogs", error)
1275
+ );
1276
+ const later = (method) => (...args) => {
1277
+ const call = (api) => api[method](...args);
1278
+ if (real) call(real);
1279
+ else queue.push(call);
1280
+ };
1281
+ return {
1282
+ getData: () => real ? real.getData() : { ...data },
1283
+ setData: (next) => {
1284
+ if (real) real.setData(next);
1285
+ else data = { ...data, ...next };
1286
+ },
1287
+ close: later("close"),
1288
+ block: later("block"),
1289
+ unblock: later("unblock"),
1290
+ focus: later("focus"),
1291
+ disable: later("disable"),
1292
+ enable: later("enable"),
1293
+ showTab: later("showTab"),
1294
+ redial: later("redial")
1295
+ };
1296
+ }
660
1297
  var COMMANDS = {
661
1298
  bold: "bold",
662
1299
  italic: "italic",
@@ -679,6 +1316,69 @@ var COMMANDS = {
679
1316
  inserthorizontalrule: "horizontalRule",
680
1317
  mceblockquote: "blockquote"
681
1318
  };
1319
+ var PLUGIN_COMMANDS = {
1320
+ mcelowercase: "lowercase",
1321
+ mceuppercase: "uppercase",
1322
+ mcetitlecase: "titlecase",
1323
+ mcetoggleformatpainter: "formatpainter",
1324
+ mcetogglepermanentpen: "permanentpen",
1325
+ mceconfigurepermanentpen: "configurepermanentpen",
1326
+ mcevisualchars: "visualchars",
1327
+ mcesave: "save",
1328
+ mcecancel: "cancel",
1329
+ mcetemplate: "template",
1330
+ mceinsertfootnote: "footnotes",
1331
+ mceupdatefootnotes: "footnotesupdate",
1332
+ mcespellcheckdialog: "spellcheckdialog",
1333
+ mcetypography: "typography",
1334
+ mcecodeeditor: "code",
1335
+ mceimagerotateleft: "rotateleft",
1336
+ mceimagerotateright: "rotateright",
1337
+ mceimageflipvertical: "flipv",
1338
+ mceimagefliphorizontal: "fliph",
1339
+ mceeditimage: "editimage",
1340
+ mcefullpagehtmlproperties: "fullpagehtml"
1341
+ };
1342
+ var SPELLCHECK_COMMANDS = /* @__PURE__ */ new Set([
1343
+ "mcespellcheckenable",
1344
+ "mcespellcheckdisable",
1345
+ "mcespellcheckupdate",
1346
+ "mcespellcheckdialogclose"
1347
+ ]);
1348
+ var ADVTABLE_COMMANDS = {
1349
+ mceadvancedtablesort: () => ({ command: "dialog" }),
1350
+ mcesorttablebycolumnasc: () => ({ command: "sort", value: { by: "column", direction: "asc" } }),
1351
+ mcesorttablebycolumndesc: () => ({
1352
+ command: "sort",
1353
+ value: { by: "column", direction: "desc" }
1354
+ }),
1355
+ mcesorttablebyrowasc: () => ({ command: "sort", value: { by: "row", direction: "asc" } }),
1356
+ mcesorttablebyrowdesc: () => ({ command: "sort", value: { by: "row", direction: "desc" } }),
1357
+ // { sortby: 'row' | 'column', roworcol: '0', sort: 'table' | 'selection' | …, order }
1358
+ mcesorttableadvanced: (value) => {
1359
+ const v = value && typeof value === "object" ? value : {};
1360
+ const index = Number(v.roworcol);
1361
+ return {
1362
+ command: "sort",
1363
+ value: {
1364
+ by: v.sortby === "row" ? "row" : "column",
1365
+ ...Number.isInteger(index) && index >= 0 ? { index } : {},
1366
+ direction: v.order === "descending" ? "desc" : "asc",
1367
+ scope: v.sort === "selection" ? "selection" : "table"
1368
+ }
1369
+ };
1370
+ },
1371
+ mcetabletoggleseries: (value) => ({
1372
+ command: "series",
1373
+ value: value?.name
1374
+ })
1375
+ };
1376
+ var ACCORDION_COMMANDS = /* @__PURE__ */ new Set([
1377
+ "insertaccordion",
1378
+ "removeaccordion",
1379
+ "toggleaccordion",
1380
+ "toggleallaccordions"
1381
+ ]);
682
1382
  var FORMAT_BLOCKS = {
683
1383
  p: "paragraph",
684
1384
  h1: "h1",
@@ -810,7 +1510,7 @@ function buttonApi(compat) {
810
1510
  enabled = value;
811
1511
  compat.core.updateUI();
812
1512
  },
813
- // Совместимость со старыми версиями API.
1513
+ // Compatibility with older versions of the API.
814
1514
  isDisabled: () => !enabled,
815
1515
  setDisabled: (value) => {
816
1516
  enabled = !value;
@@ -824,6 +1524,11 @@ var CompatEditor = class {
824
1524
  core;
825
1525
  targetElm;
826
1526
  settings;
1527
+ /**
1528
+ * The plugins by their TinyMCE names (`editor.plugins.lists`): the listed ones that work here, and
1529
+ * what your own plugins return. inlinecss has `getContent()`: the content with its styles inline.
1530
+ */
1531
+ plugins = {};
827
1532
  initialized = false;
828
1533
  removed = false;
829
1534
  handlers = /* @__PURE__ */ new Map();
@@ -834,25 +1539,29 @@ var CompatEditor = class {
834
1539
  this.targetElm = target;
835
1540
  this.id = id;
836
1541
  this.settings = settings;
1542
+ setTimeout(() => void loadDialogs().catch(() => {
1543
+ }), 0);
837
1544
  }
838
- // ---------- содержимое ----------
1545
+ // ---------- content ----------
839
1546
  getContent(args = {}) {
840
1547
  const event = { format: args.format ?? "html", content: "" };
841
- event.content = event.format === "text" ? this.core.getText() : this.core.getHTML();
1548
+ event.content = event.format === "text" ? this.core.getText() : this.core.getHTML({ fullPage: args.fullpagehtml !== false });
1549
+ const prettify = args.prettify === true || this.settings.advcode_prettify_getcontent === true && this.core.hasPlugin("advcode");
1550
+ if (prettify && event.format !== "text") event.content = (0, import_core2.prettyHTML)(event.content);
842
1551
  this.fire("GetContent", event);
843
1552
  return event.content;
844
1553
  }
845
1554
  setContent(content, args = {}) {
846
1555
  const event = { content, ...args };
847
1556
  this.fire("BeforeSetContent", event);
848
- this.core.setContent(event.content);
1557
+ this.core.setContent(event.content, { fullPage: args.fullpagehtml !== false });
849
1558
  this.fire("SetContent", event);
850
1559
  return event.content;
851
1560
  }
852
1561
  /**
853
- * Вставить HTML на место выделения. Блоки (<p>, списки, таблицы) — отдельными блоками (абзац
854
- * разрезается), строчное содержимое — в текущую строку. Разбор — схемой редактора: те же проверки
855
- * ссылок и разметки, что при загрузке содержимого.
1562
+ * Insert HTML in place of the selection. Blocks (<p>, lists, tables) go in as separate blocks (the
1563
+ * paragraph is split), inline content into the current line. Parsed by the editor's schema: the
1564
+ * same link and markup checks as when content is loaded.
856
1565
  */
857
1566
  insertContent(content) {
858
1567
  this.core.insertContent(content);
@@ -881,10 +1590,11 @@ var CompatEditor = class {
881
1590
  getWin() {
882
1591
  return this.core.root.ownerDocument.defaultView;
883
1592
  }
884
- // ---------- команды ----------
885
- /** Значение команды: ToggleSidebar — имя открытой боковой панели. */
1593
+ // ---------- commands ----------
1594
+ /** The value of a command: for ToggleSidebar and ToggleView, the name of the open one. */
886
1595
  queryCommandValue(command) {
887
1596
  if (command.toLowerCase() === "togglesidebar") return this.core.ui.sidebar.active ?? "";
1597
+ if (command.toLowerCase() === "toggleview") return this.core.ui.view.active ?? "";
888
1598
  return "";
889
1599
  }
890
1600
  execCommand(command, _ui, value) {
@@ -897,12 +1607,56 @@ var CompatEditor = class {
897
1607
  } else if (name === "mceinsertcontent" || name === "inserthtml") {
898
1608
  this.insertContent(String(value ?? ""));
899
1609
  done = true;
1610
+ } else if (name === "toggleview") {
1611
+ this.core.ui.view.toggle(String(value ?? ""));
1612
+ done = true;
900
1613
  } else if (name === "togglesidebar") {
901
1614
  void this.core.ui.sidebar.toggle(String(value ?? ""));
902
1615
  done = true;
1616
+ } else if ((name === "mceaidialog" || name === "mceaidialogclose") && this.core.hasPlugin("ai")) {
1617
+ const options = value && typeof value === "object" ? value : {};
1618
+ const detail = {
1619
+ ...typeof options.prompt === "string" ? { prompt: options.prompt } : {},
1620
+ ...options.generate === true ? { generate: true } : {},
1621
+ ...options.display === false ? { display: false } : {}
1622
+ };
1623
+ this.core.root.dispatchEvent(
1624
+ name === "mceaidialog" ? new CustomEvent("nova-ai-dialog", { detail }) : new CustomEvent("nova-ai-dialog-close")
1625
+ );
1626
+ done = true;
903
1627
  } else if (name === "mcesetcontent") {
904
1628
  this.setContent(String(value ?? ""));
905
1629
  done = true;
1630
+ } else if (name === "mceinserttoc" || name === "mceupdatetoc") {
1631
+ const control = this.core.ui.registry.get(
1632
+ name === "mceinserttoc" ? "tableofcontents" : "tableofcontentsupdate"
1633
+ );
1634
+ if (control?.type === "button") {
1635
+ control.onAction(this.core);
1636
+ done = true;
1637
+ }
1638
+ } else if (ADVTABLE_COMMANDS[name] && this.core.hasPlugin("advtable")) {
1639
+ this.core.root.dispatchEvent(
1640
+ new CustomEvent("nova-advtable", { detail: ADVTABLE_COMMANDS[name](value) })
1641
+ );
1642
+ done = true;
1643
+ } else if (ACCORDION_COMMANDS.has(name)) {
1644
+ done = this.accordionCommand(name, value);
1645
+ } else if (name === "mceinserttemplate" && this.core.hasPlugin("template")) {
1646
+ this.core.root.dispatchEvent(
1647
+ new CustomEvent("nova-insert-template", { detail: String(value ?? "") })
1648
+ );
1649
+ done = true;
1650
+ } else if (SPELLCHECK_COMMANDS.has(name) && this.core.hasPlugin("spellchecker")) {
1651
+ done = this.spellcheckCommand(name);
1652
+ } else if (PLUGIN_COMMANDS[name] || name === "mcetogglestickyformatpainter") {
1653
+ done = this.pluginCommand(name);
1654
+ } else if (name === "codesample") {
1655
+ const button = this.core.ui.registry.get("codesample");
1656
+ if (button?.type === "button") {
1657
+ button.onAction(this.core);
1658
+ done = true;
1659
+ }
906
1660
  } else if (name === "selectall") {
907
1661
  const { state, dispatch } = this.core.view;
908
1662
  dispatch(state.tr.setSelection(new import_prosemirror_state.AllSelection(state.doc)));
@@ -919,19 +1673,97 @@ var CompatEditor = class {
919
1673
  if (done) this.fire("ExecCommand", { command, ui: _ui, value });
920
1674
  return done;
921
1675
  }
1676
+ /**
1677
+ * InsertAccordion / RemoveAccordion — like the accordion button (inside one, remove the frame;
1678
+ * otherwise insert); ToggleAccordion / ToggleAllAccordions — value true expands, false collapses,
1679
+ * no value toggles. Collapsing is a view, not an edit: it doesn't go into the undo history.
1680
+ */
1681
+ spellcheckCommand(name) {
1682
+ if (name === "mcespellcheckdialogclose") {
1683
+ this.core.ui.closeOverlays();
1684
+ return true;
1685
+ }
1686
+ if (name === "mcespellcheckupdate") return true;
1687
+ const toggle = this.core.ui.registry.get("spellchecker");
1688
+ if (!toggle) return false;
1689
+ const on = !!toggle.isActive?.(this.core);
1690
+ if (name === "mcespellcheckenable" !== on) toggle.onAction(this.core);
1691
+ return true;
1692
+ }
1693
+ accordionCommand(name, value) {
1694
+ const { view } = this.core;
1695
+ const { state } = view;
1696
+ const $from = state.selection.$from;
1697
+ let around = null;
1698
+ for (let depth = $from.depth; depth > 0 && !around; depth--) {
1699
+ const node = $from.node(depth);
1700
+ if (node.type.name === "details") {
1701
+ around = { pos: $from.before(depth), open: node.attrs.open !== false };
1702
+ }
1703
+ }
1704
+ if (name === "insertaccordion" || name === "removeaccordion") {
1705
+ if (name === "removeaccordion" !== !!around) return false;
1706
+ const button = this.core.ui.registry.get("accordion");
1707
+ if (button?.type !== "button") return false;
1708
+ button.onAction(this.core);
1709
+ return true;
1710
+ }
1711
+ const all = [];
1712
+ if (name === "toggleaccordion") {
1713
+ if (around) all.push(around);
1714
+ } else {
1715
+ state.doc.descendants((node, pos) => {
1716
+ if (node.type.name === "details") all.push({ pos, open: node.attrs.open !== false });
1717
+ return !node.isTextblock;
1718
+ });
1719
+ }
1720
+ if (!all.length) return false;
1721
+ const open = typeof value === "boolean" ? value : !all.every((d) => d.open);
1722
+ const tr = state.tr;
1723
+ for (const details of all) tr.setNodeAttribute(details.pos, "open", open);
1724
+ view.dispatch(tr.setMeta("addToHistory", false));
1725
+ return true;
1726
+ }
1727
+ /**
1728
+ * A command of casechange, formatpainter or permanentpen: like its menu item or button.
1729
+ * mceToggleStickyFormatPainter turns the painter on to stay (a double click on the button), or off.
1730
+ */
1731
+ pluginCommand(name) {
1732
+ const { registry } = this.core.ui;
1733
+ if (name === "mcetogglestickyformatpainter") {
1734
+ const painter = registry.get("formatpainter");
1735
+ const item2 = registry.getMenuItem("formatpainter");
1736
+ if (painter?.type !== "button" || !item2) return false;
1737
+ if (item2.isActive?.(this.core)) item2.onAction(this.core);
1738
+ else {
1739
+ painter.onAction(this.core);
1740
+ painter.onAction(this.core);
1741
+ }
1742
+ return true;
1743
+ }
1744
+ const item = registry.getMenuItem(PLUGIN_COMMANDS[name]);
1745
+ if (!item || name !== "mcesave" && item.isEnabled?.(this.core) === false) return false;
1746
+ item.onAction(this.core);
1747
+ return true;
1748
+ }
922
1749
  queryCommandState(command) {
923
- const name = COMMANDS[command.toLowerCase()];
924
- return name ? this.core.isActive(name) : false;
1750
+ const lower = command.toLowerCase();
1751
+ const name = COMMANDS[lower];
1752
+ if (name) return this.core.isActive(name);
1753
+ if (lower === "mcetoggleformatpainter" || lower === "mcetogglepermanentpen") {
1754
+ return !!this.core.ui.registry.getMenuItem(PLUGIN_COMMANDS[lower])?.isActive?.(this.core);
1755
+ }
1756
+ return false;
925
1757
  }
926
1758
  queryCommandSupported(command) {
927
1759
  const name = command.toLowerCase();
928
- return name in COMMANDS || ["formatblock", "mceinsertcontent", "mcesetcontent"].includes(name) || this.commands.has(name);
1760
+ return name in COMMANDS || ["formatblock", "mceinsertcontent", "mcesetcontent"].includes(name) || name in PLUGIN_COMMANDS && !!this.core.ui.registry.getMenuItem(PLUGIN_COMMANDS[name]) || name === "mcetogglestickyformatpainter" && this.core.ui.registry.has("formatpainter") || SPELLCHECK_COMMANDS.has(name) && this.core.hasPlugin("spellchecker") || (name === "mceaidialog" || name === "mceaidialogclose") && this.core.hasPlugin("ai") || this.commands.has(name);
929
1761
  }
930
1762
  commands = /* @__PURE__ */ new Map();
931
1763
  addCommand(name, callback) {
932
1764
  this.commands.set(name.toLowerCase(), callback);
933
1765
  }
934
- // ---------- события ----------
1766
+ // ---------- events ----------
935
1767
  on(names, handler, prepend = false) {
936
1768
  for (const name of names.toLowerCase().split(/\s+/).filter(Boolean)) {
937
1769
  const set = this.handlers.get(name) ?? /* @__PURE__ */ new Set();
@@ -969,7 +1801,7 @@ var CompatEditor = class {
969
1801
  }
970
1802
  return payload;
971
1803
  }
972
- /** DOM-событие текста (keydown, click…) — обработчикам передаётся само событие браузера. */
1804
+ /** A DOM event of the text (keydown, click…): handlers get the browser's event itself. */
973
1805
  fireNative(name, event) {
974
1806
  for (const handler of [...this.handlers.get(name) ?? []]) {
975
1807
  try {
@@ -979,18 +1811,18 @@ var CompatEditor = class {
979
1811
  }
980
1812
  }
981
1813
  }
982
- /** Иконка для кнопок по имени (tinymce.IconManager / editor.ui.registry.addIcon). */
1814
+ /** An icon for buttons by name (tinymce.IconManager / editor.ui.registry.addIcon). */
983
1815
  static registerIcon(name, svg) {
984
1816
  customIcons.set(name, svg);
985
1817
  }
986
- /** Новое имя fire в последних версиях API. */
1818
+ /** The newer name of fire in recent versions of the API. */
987
1819
  dispatch(name, event) {
988
1820
  return this.fire(name, event);
989
1821
  }
990
1822
  hasEventListeners(name) {
991
1823
  return (this.handlers.get(name.toLowerCase())?.size ?? 0) > 0;
992
1824
  }
993
- // ---------- состояние ----------
1825
+ // ---------- state ----------
994
1826
  isDirty() {
995
1827
  return this.dirty;
996
1828
  }
@@ -999,7 +1831,7 @@ var CompatEditor = class {
999
1831
  this.dirty = state;
1000
1832
  if (changed && state) this.fire("Dirty");
1001
1833
  }
1002
- /** Записать содержимое в исходный <textarea> (как при отправке формы). */
1834
+ /** Write the content into the original <textarea> (as on form submit). */
1003
1835
  save() {
1004
1836
  const content = this.getContent();
1005
1837
  const event = this.fire("SaveContent", { content });
@@ -1060,44 +1892,35 @@ var CompatEditor = class {
1060
1892
  },
1061
1893
  ignore: (callback) => callback()
1062
1894
  };
1895
+ /** TinyMCE's editor.selection, on top of the core's editor.selection. */
1063
1896
  selection = {
1064
- getContent: (args = {}) => {
1065
- const { state } = this.core.view;
1066
- const { from, to } = state.selection;
1067
- if (args.format === "text") return state.doc.textBetween(from, to, "\n");
1068
- return serializer.serializeFragment(state.selection.content().content);
1069
- },
1897
+ getContent: (args = {}) => args.format === "text" ? this.core.selection.getText() : this.core.selection.getHTML(),
1070
1898
  setContent: (content) => this.insertContent(content),
1071
- getNode: () => {
1072
- const { from } = this.core.view.state.selection;
1073
- const { node } = this.core.view.domAtPos(from);
1074
- return node instanceof Element ? node : node.parentElement;
1075
- },
1899
+ getNode: () => this.core.selection.getNode() ?? this.core.view.dom,
1076
1900
  getStart: () => this.selection.getNode(),
1077
1901
  getEnd: () => this.selection.getNode(),
1078
- isCollapsed: () => this.core.view.state.selection.empty,
1079
- collapse: (toStart = false) => {
1080
- const { state, dispatch } = this.core.view;
1081
- const pos = toStart ? state.selection.from : state.selection.to;
1082
- dispatch(state.tr.setSelection(import_prosemirror_state.TextSelection.near(state.doc.resolve(pos))));
1083
- },
1084
- /** Курсор в узел DOM редактора (по умолчанию — в начало). */
1902
+ isCollapsed: () => this.core.selection.isCollapsed(),
1903
+ collapse: (toStart = false) => this.core.selection.collapse(toStart),
1904
+ /** Put the cursor in a DOM node of the editor (at its start by default). */
1085
1905
  setCursorLocation: (node, offset = 0) => {
1086
- const { view } = this.core;
1087
- if (!node || !view.dom.contains(node)) return;
1088
- const pos = view.posAtDOM(node, offset);
1089
- view.dispatch(view.state.tr.setSelection(import_prosemirror_state.TextSelection.near(view.state.doc.resolve(pos))));
1906
+ if (node) this.core.selection.setCursorLocation(node, offset);
1090
1907
  },
1091
- /** Выделить элемент: content = true — только его содержимое. */
1092
- select: (node, content = false) => {
1908
+ /** Select an element: content = true — only its content. */
1909
+ select: (node, content = false) => this.core.selection.select(node, content),
1910
+ /** The selection as a DOM Range. */
1911
+ getRng: () => this.core.selection.getDOMRange(),
1912
+ /** Select a DOM Range of the editing area. */
1913
+ setRng: (range) => {
1093
1914
  const { view } = this.core;
1094
- if (!view.dom.contains(node)) return;
1095
- const from = view.posAtDOM(node, 0);
1096
- const to = view.posAtDOM(node, node.childNodes.length);
1097
- const { doc } = view.state;
1098
- const selection = !content && node instanceof HTMLImageElement ? import_prosemirror_state.NodeSelection.create(doc, Math.max(0, from - (doc.resolve(from).nodeAfter ? 0 : 1))) : import_prosemirror_state.TextSelection.between(doc.resolve(from), doc.resolve(to));
1099
- view.dispatch(view.state.tr.setSelection(selection));
1100
- }
1915
+ if (!range || !view.dom.contains(range.startContainer)) return;
1916
+ const from = view.posAtDOM(range.startContainer, range.startOffset);
1917
+ const to = view.dom.contains(range.endContainer) ? view.posAtDOM(range.endContainer, range.endOffset) : from;
1918
+ this.core.selection.setRange(from, to);
1919
+ },
1920
+ /** Remember the selection; moveToBookmark() puts it back, wherever later changes moved it. */
1921
+ getBookmark: () => this.core.selection.getBookmark(),
1922
+ moveToBookmark: (bookmark) => this.core.selection.moveToBookmark(bookmark),
1923
+ scrollIntoView: () => this.core.selection.scrollIntoView()
1101
1924
  };
1102
1925
  notificationManager = {
1103
1926
  open: (args) => this.core.ui.notify({
@@ -1134,9 +1957,9 @@ var CompatEditor = class {
1134
1957
  onClose: () => callback?.(confirmed)
1135
1958
  });
1136
1959
  },
1137
- open: (spec) => openSpecDialog(this.core, spec, (next) => this.windowManager.open(next))
1960
+ open: (spec) => openDialog(this.core, spec, (next) => this.windowManager.open(next))
1138
1961
  };
1139
- /** editor.ui.registry — кнопки и пункты меню в формате TinyMCE поверх реестра NovaProse. */
1962
+ /** editor.ui.registry — buttons and menu items in TinyMCE format on top of the NovaProse registry. */
1140
1963
  ui = {
1141
1964
  registry: {
1142
1965
  addIcon: (name, svg) => {
@@ -1172,8 +1995,8 @@ var CompatEditor = class {
1172
1995
  });
1173
1996
  },
1174
1997
  /**
1175
- * Контекстная панель: predicate(node) получает элемент под курсором, items — кнопки тулбара.
1176
- * position: 'node' (над элементом) или 'selection'/'line' (у выделения).
1998
+ * A context toolbar: predicate(node) gets the element at the cursor, items are toolbar buttons.
1999
+ * position: 'node' (above the element) or 'selection'/'line' (at the selection).
1177
2000
  */
1178
2001
  addContextToolbar: (name, spec) => {
1179
2002
  this.core.ui.registry.addContextToolbar(name, {
@@ -1187,8 +2010,8 @@ var CompatEditor = class {
1187
2010
  });
1188
2011
  },
1189
2012
  /**
1190
- * Боковая панель: onSetup(api) рисует содержимое в api.element() (один раз), onShow/onHide —
1191
- * при показе. Кнопка-переключатель с именем панели — для toolbar; ToggleSidebar — командой.
2013
+ * A sidebar: onSetup(api) draws the content into api.element() (once), onShow/onHide run when it
2014
+ * is shown or hidden. A toggle button named after the sidebar is for the toolbar; ToggleSidebar is the command.
1192
2015
  */
1193
2016
  addSidebar: (name, spec) => {
1194
2017
  let element = null;
@@ -1206,6 +2029,21 @@ var CompatEditor = class {
1206
2029
  onHide: () => spec.onHide?.(api)
1207
2030
  });
1208
2031
  },
2032
+ /**
2033
+ * A view in place of the editor: buttons at its top, onShow/onHide get api.getContainer(), where it
2034
+ * draws; ToggleView is the command.
2035
+ */
2036
+ addView: (name, spec) => {
2037
+ this.core.ui.registry.addView(name, {
2038
+ buttons: (Array.isArray(spec.buttons) ? spec.buttons : []).filter((button) => typeof button?.text === "string").map((button) => ({
2039
+ text: button.text,
2040
+ buttonType: button.buttonType === "primary" ? "primary" : "secondary",
2041
+ onAction: () => button.onAction?.()
2042
+ })),
2043
+ ...spec.onShow ? { onShow: spec.onShow } : {},
2044
+ ...spec.onHide ? { onHide: spec.onHide } : {}
2045
+ });
2046
+ },
1209
2047
  addContextForm: () => {
1210
2048
  console.warn("[nova] tinymce-compat: addContextForm is not supported yet");
1211
2049
  },
@@ -1234,9 +2072,9 @@ var CompatEditor = class {
1234
2072
  }
1235
2073
  }
1236
2074
  /**
1237
- * editor.dom — то, что имеет смысл поверх модели документа: поиск и чтение. Менять DOM текста
1238
- * напрямую нельзя (редактор перерисует его из модели) — для правок есть setContent/insertContent/
1239
- * formatter; такие вызовы пишут предупреждение.
2075
+ * editor.dom — what makes sense on top of a document model: finding and reading. The text's DOM
2076
+ * can't be changed directly (the editor redraws it from the model); use setContent, insertContent
2077
+ * or formatter for edits — such calls log a warning.
1240
2078
  */
1241
2079
  dom = {
1242
2080
  select: (selector, scope) => [
@@ -1272,7 +2110,7 @@ var CompatEditor = class {
1272
2110
  textarea.innerHTML = html;
1273
2111
  return textarea.value;
1274
2112
  },
1275
- /** Новый (не вставленный) элемент: атрибуты — через setAttribute, содержимое — текстом. */
2113
+ /** A new (not inserted) element: attributes via setAttribute, the content as text. */
1276
2114
  create: (tag, attrs = {}, text) => {
1277
2115
  const node = document.createElement(tag);
1278
2116
  for (const [name, value] of Object.entries(attrs)) {
@@ -1289,8 +2127,8 @@ var CompatEditor = class {
1289
2127
  remove: () => warnDom("remove")
1290
2128
  };
1291
2129
  /**
1292
- * editor.formatter — встроенные форматы TinyMCE: apply/remove/toggle/match.
1293
- * Свои форматы (register) пока не поддержаны.
2130
+ * editor.formatter — the built-in TinyMCE formats: apply/remove/toggle/match. Your own formats
2131
+ * (register) are not supported yet.
1294
2132
  */
1295
2133
  formatter = {
1296
2134
  apply: (name, vars = {}) => this.applyFormat(name, vars, "apply"),
@@ -1371,7 +2209,7 @@ var CompatEditor = class {
1371
2209
  }
1372
2210
  console.warn(`[nova] tinymce-compat: format "${name}" is not supported yet`);
1373
2211
  }
1374
- /** Убрать редактор и вернуть исходный элемент (как editor.remove()). */
2212
+ /** Remove the editor and restore the original element (like editor.remove()). */
1375
2213
  remove() {
1376
2214
  if (this.removed) return;
1377
2215
  this.fire("remove");
@@ -1431,15 +2269,76 @@ function createTinymce() {
1431
2269
  settings.__wrapper = host;
1432
2270
  }
1433
2271
  let compat;
2272
+ const tinyPattern = (raw) => {
2273
+ const p = raw;
2274
+ if (!p || typeof p.start !== "string") return null;
2275
+ if (typeof p.replacement === "string") return { start: p.start, replacement: p.replacement };
2276
+ const formats = (Array.isArray(p.format) ? p.format : [p.format]).filter(
2277
+ (f) => typeof f === "string"
2278
+ );
2279
+ const cmd = typeof p.cmd === "string" ? p.cmd : null;
2280
+ if (!cmd && !formats.length) return null;
2281
+ return {
2282
+ start: p.start,
2283
+ ...typeof p.end === "string" && p.end ? { end: p.end } : {},
2284
+ ...p.trigger === "enter" ? { trigger: "enter" } : {},
2285
+ value: p.value,
2286
+ command: (_editor, value) => {
2287
+ if (cmd) compat.execCommand(cmd, false, value);
2288
+ else for (const format of formats) compat.formatter.apply(format);
2289
+ }
2290
+ };
2291
+ };
2292
+ if (Array.isArray(config.text_patterns)) {
2293
+ options.textPatterns = config.text_patterns.map(tinyPattern);
2294
+ }
2295
+ const lookup = config.text_patterns_lookup;
2296
+ if (typeof lookup === "function") {
2297
+ options.textPatternsLookup = (context) => {
2298
+ const extra = lookup(context);
2299
+ return Array.isArray(extra) ? extra.map(tinyPattern) : [];
2300
+ };
2301
+ if (!options.textPatterns) options.textPatterns = [];
2302
+ }
2303
+ const onSave = config.save_onsavecallback;
2304
+ const onCancel = config.save_oncancelcallback;
2305
+ const save = {
2306
+ ...config.save_enablewhendirty !== void 0 ? { enableWhenDirty: config.save_enablewhendirty !== false } : {},
2307
+ ...typeof onSave === "function" ? {
2308
+ onSave: () => {
2309
+ compat.save();
2310
+ return onSave(compat);
2311
+ }
2312
+ } : {},
2313
+ ...typeof onCancel === "function" ? { onCancel: () => onCancel(compat) } : {}
2314
+ };
2315
+ const aiRequest = config.ai_request;
2316
+ const ai = typeof aiRequest === "function" ? {
2317
+ ...options.pluginOptions?.ai,
2318
+ async *request(request) {
2319
+ const { tinyAiRequest: tinyAiRequest2 } = await Promise.resolve().then(() => (init_ai(), ai_exports));
2320
+ yield* tinyAiRequest2(
2321
+ aiRequest,
2322
+ (name, event) => compat?.fire(name, event)
2323
+ )(request);
2324
+ }
2325
+ } : null;
2326
+ const pluginOptions = {
2327
+ ...options.pluginOptions,
2328
+ ...Object.keys(save).length ? { save } : {},
2329
+ ...ai ? { ai } : {}
2330
+ };
1434
2331
  const core = (0, import_core3.createEditor)({
1435
2332
  ...options,
2333
+ ...Object.keys(pluginOptions).length ? { pluginOptions } : {},
1436
2334
  element: host,
1437
2335
  content: initial,
1438
2336
  setup: (editor) => {
1439
2337
  compat = new CompatEditor(editor, target, id, settings);
1440
2338
  for (const name of custom) {
1441
2339
  try {
1442
- plugins.get(name)(compat, "");
2340
+ const api2 = plugins.get(name)(compat, "");
2341
+ compat.plugins[name] = api2 && typeof api2 === "object" ? api2 : {};
1443
2342
  } catch (error) {
1444
2343
  console.error(`[nova] tinymce-compat: plugin "${name}" failed`, error);
1445
2344
  }
@@ -1485,6 +2384,14 @@ function createTinymce() {
1485
2384
  ]) {
1486
2385
  core.view.dom.addEventListener(name, (event) => compat.fireNative(name, event));
1487
2386
  }
2387
+ core.root.addEventListener("nova-ai-dialogopen", () => compat.fire("AIDialogOpen"));
2388
+ core.root.addEventListener("nova-ai-dialogclose", () => compat.fire("AIDialogClose"));
2389
+ core.root.addEventListener("nova-autocorrect-toggle", (event) => {
2390
+ const { feature, on } = event.detail;
2391
+ compat.fire(
2392
+ (feature === "capitalize" ? "Capitalize" : "Autocorrect") + (on ? "Start" : "End")
2393
+ );
2394
+ });
1488
2395
  const form = isTextarea ? target.form : target.closest("form");
1489
2396
  form?.addEventListener("submit", () => compat.save());
1490
2397
  compat.on("remove", () => {
@@ -1496,9 +2403,22 @@ function createTinymce() {
1496
2403
  active ??= compat;
1497
2404
  await core.ready;
1498
2405
  if (compat.removed) return compat;
2406
+ for (const name of activePlugins(config, (plugin) => core.hasPlugin(plugin)))
2407
+ compat.plugins[name] ??= {};
2408
+ if (compat.plugins.inlinecss) {
2409
+ compat.plugins.inlinecss.getContent = async () => {
2410
+ compat.fire("InlineCSS");
2411
+ const { emailHTML } = await import("@novaprose/core/email");
2412
+ return { html: await emailHTML(core, { document: false }) };
2413
+ };
2414
+ }
1499
2415
  compat.initialized = true;
1500
2416
  compat.fire("init");
1501
2417
  config.init_instance_callback?.(compat);
2418
+ if (typeof config.view_show === "string" && config.view_show)
2419
+ core.ui.view.show(config.view_show);
2420
+ else if (typeof config.sidebar_show === "string" && config.sidebar_show)
2421
+ void core.ui.sidebar.show(config.sidebar_show);
1502
2422
  return compat;
1503
2423
  }
1504
2424
  const api = {
@@ -1517,6 +2437,12 @@ function createTinymce() {
1517
2437
  (resolve) => document.addEventListener("DOMContentLoaded", resolve, { once: true })
1518
2438
  );
1519
2439
  }
2440
+ if (typeof config.language === "string") {
2441
+ await (0, import_core3.loadLanguage)(config.language.replace("_", "-")).catch((error) => {
2442
+ console.warn("[nova] tinymce-compat: language pack failed to load", error);
2443
+ return false;
2444
+ });
2445
+ }
1520
2446
  const targets = config.target ? [config.target] : config.selector ? [...document.querySelectorAll(config.selector)] : [];
1521
2447
  if (!targets.length) warnOnce(`no elements match "${config.selector ?? ""}"`);
1522
2448
  const editors = [];