@ckeditor/ckeditor5-core 0.0.0-internal-20241017.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 (417) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +24 -0
  4. package/dist/accessibility.d.ts +365 -0
  5. package/dist/augmentation.d.ts +14 -0
  6. package/dist/command.d.ts +193 -0
  7. package/dist/commandcollection.d.ts +87 -0
  8. package/dist/context.d.ts +241 -0
  9. package/dist/contextplugin.d.ts +73 -0
  10. package/dist/editingkeystrokehandler.d.ts +60 -0
  11. package/dist/editor/editor.d.ts +524 -0
  12. package/dist/editor/editorconfig.d.ts +992 -0
  13. package/dist/editor/utils/attachtoform.d.ts +19 -0
  14. package/dist/editor/utils/dataapimixin.d.ts +83 -0
  15. package/dist/editor/utils/editorusagedata.d.ts +62 -0
  16. package/dist/editor/utils/elementapimixin.d.ts +39 -0
  17. package/dist/editor/utils/securesourceelement.d.ts +21 -0
  18. package/dist/index-content.css +4 -0
  19. package/dist/index-editor.css +4 -0
  20. package/dist/index.css +4 -0
  21. package/dist/index.d.ts +94 -0
  22. package/dist/index.js +3027 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/multicommand.d.ts +70 -0
  25. package/dist/pendingactions.d.ts +126 -0
  26. package/dist/plugin.d.ts +294 -0
  27. package/dist/plugincollection.d.ts +121 -0
  28. package/dist/translations/af.d.ts +8 -0
  29. package/dist/translations/af.js +5 -0
  30. package/dist/translations/af.umd.js +11 -0
  31. package/dist/translations/ar.d.ts +8 -0
  32. package/dist/translations/ar.js +5 -0
  33. package/dist/translations/ar.umd.js +11 -0
  34. package/dist/translations/ast.d.ts +8 -0
  35. package/dist/translations/ast.js +5 -0
  36. package/dist/translations/ast.umd.js +11 -0
  37. package/dist/translations/az.d.ts +8 -0
  38. package/dist/translations/az.js +5 -0
  39. package/dist/translations/az.umd.js +11 -0
  40. package/dist/translations/bg.d.ts +8 -0
  41. package/dist/translations/bg.js +5 -0
  42. package/dist/translations/bg.umd.js +11 -0
  43. package/dist/translations/bn.d.ts +8 -0
  44. package/dist/translations/bn.js +5 -0
  45. package/dist/translations/bn.umd.js +11 -0
  46. package/dist/translations/bs.d.ts +8 -0
  47. package/dist/translations/bs.js +5 -0
  48. package/dist/translations/bs.umd.js +11 -0
  49. package/dist/translations/ca.d.ts +8 -0
  50. package/dist/translations/ca.js +5 -0
  51. package/dist/translations/ca.umd.js +11 -0
  52. package/dist/translations/cs.d.ts +8 -0
  53. package/dist/translations/cs.js +5 -0
  54. package/dist/translations/cs.umd.js +11 -0
  55. package/dist/translations/da.d.ts +8 -0
  56. package/dist/translations/da.js +5 -0
  57. package/dist/translations/da.umd.js +11 -0
  58. package/dist/translations/de-ch.d.ts +8 -0
  59. package/dist/translations/de-ch.js +5 -0
  60. package/dist/translations/de-ch.umd.js +11 -0
  61. package/dist/translations/de.d.ts +8 -0
  62. package/dist/translations/de.js +5 -0
  63. package/dist/translations/de.umd.js +11 -0
  64. package/dist/translations/el.d.ts +8 -0
  65. package/dist/translations/el.js +5 -0
  66. package/dist/translations/el.umd.js +11 -0
  67. package/dist/translations/en-au.d.ts +8 -0
  68. package/dist/translations/en-au.js +5 -0
  69. package/dist/translations/en-au.umd.js +11 -0
  70. package/dist/translations/en-gb.d.ts +8 -0
  71. package/dist/translations/en-gb.js +5 -0
  72. package/dist/translations/en-gb.umd.js +11 -0
  73. package/dist/translations/en.d.ts +8 -0
  74. package/dist/translations/en.js +5 -0
  75. package/dist/translations/en.umd.js +11 -0
  76. package/dist/translations/eo.d.ts +8 -0
  77. package/dist/translations/eo.js +5 -0
  78. package/dist/translations/eo.umd.js +11 -0
  79. package/dist/translations/es-co.d.ts +8 -0
  80. package/dist/translations/es-co.js +5 -0
  81. package/dist/translations/es-co.umd.js +11 -0
  82. package/dist/translations/es.d.ts +8 -0
  83. package/dist/translations/es.js +5 -0
  84. package/dist/translations/es.umd.js +11 -0
  85. package/dist/translations/et.d.ts +8 -0
  86. package/dist/translations/et.js +5 -0
  87. package/dist/translations/et.umd.js +11 -0
  88. package/dist/translations/eu.d.ts +8 -0
  89. package/dist/translations/eu.js +5 -0
  90. package/dist/translations/eu.umd.js +11 -0
  91. package/dist/translations/fa.d.ts +8 -0
  92. package/dist/translations/fa.js +5 -0
  93. package/dist/translations/fa.umd.js +11 -0
  94. package/dist/translations/fi.d.ts +8 -0
  95. package/dist/translations/fi.js +5 -0
  96. package/dist/translations/fi.umd.js +11 -0
  97. package/dist/translations/fr.d.ts +8 -0
  98. package/dist/translations/fr.js +5 -0
  99. package/dist/translations/fr.umd.js +11 -0
  100. package/dist/translations/gl.d.ts +8 -0
  101. package/dist/translations/gl.js +5 -0
  102. package/dist/translations/gl.umd.js +11 -0
  103. package/dist/translations/gu.d.ts +8 -0
  104. package/dist/translations/gu.js +5 -0
  105. package/dist/translations/gu.umd.js +11 -0
  106. package/dist/translations/he.d.ts +8 -0
  107. package/dist/translations/he.js +5 -0
  108. package/dist/translations/he.umd.js +11 -0
  109. package/dist/translations/hi.d.ts +8 -0
  110. package/dist/translations/hi.js +5 -0
  111. package/dist/translations/hi.umd.js +11 -0
  112. package/dist/translations/hr.d.ts +8 -0
  113. package/dist/translations/hr.js +5 -0
  114. package/dist/translations/hr.umd.js +11 -0
  115. package/dist/translations/hu.d.ts +8 -0
  116. package/dist/translations/hu.js +5 -0
  117. package/dist/translations/hu.umd.js +11 -0
  118. package/dist/translations/hy.d.ts +8 -0
  119. package/dist/translations/hy.js +5 -0
  120. package/dist/translations/hy.umd.js +11 -0
  121. package/dist/translations/id.d.ts +8 -0
  122. package/dist/translations/id.js +5 -0
  123. package/dist/translations/id.umd.js +11 -0
  124. package/dist/translations/it.d.ts +8 -0
  125. package/dist/translations/it.js +5 -0
  126. package/dist/translations/it.umd.js +11 -0
  127. package/dist/translations/ja.d.ts +8 -0
  128. package/dist/translations/ja.js +5 -0
  129. package/dist/translations/ja.umd.js +11 -0
  130. package/dist/translations/jv.d.ts +8 -0
  131. package/dist/translations/jv.js +5 -0
  132. package/dist/translations/jv.umd.js +11 -0
  133. package/dist/translations/km.d.ts +8 -0
  134. package/dist/translations/km.js +5 -0
  135. package/dist/translations/km.umd.js +11 -0
  136. package/dist/translations/kn.d.ts +8 -0
  137. package/dist/translations/kn.js +5 -0
  138. package/dist/translations/kn.umd.js +11 -0
  139. package/dist/translations/ko.d.ts +8 -0
  140. package/dist/translations/ko.js +5 -0
  141. package/dist/translations/ko.umd.js +11 -0
  142. package/dist/translations/ku.d.ts +8 -0
  143. package/dist/translations/ku.js +5 -0
  144. package/dist/translations/ku.umd.js +11 -0
  145. package/dist/translations/lt.d.ts +8 -0
  146. package/dist/translations/lt.js +5 -0
  147. package/dist/translations/lt.umd.js +11 -0
  148. package/dist/translations/lv.d.ts +8 -0
  149. package/dist/translations/lv.js +5 -0
  150. package/dist/translations/lv.umd.js +11 -0
  151. package/dist/translations/ms.d.ts +8 -0
  152. package/dist/translations/ms.js +5 -0
  153. package/dist/translations/ms.umd.js +11 -0
  154. package/dist/translations/nb.d.ts +8 -0
  155. package/dist/translations/nb.js +5 -0
  156. package/dist/translations/nb.umd.js +11 -0
  157. package/dist/translations/ne.d.ts +8 -0
  158. package/dist/translations/ne.js +5 -0
  159. package/dist/translations/ne.umd.js +11 -0
  160. package/dist/translations/nl.d.ts +8 -0
  161. package/dist/translations/nl.js +5 -0
  162. package/dist/translations/nl.umd.js +11 -0
  163. package/dist/translations/no.d.ts +8 -0
  164. package/dist/translations/no.js +5 -0
  165. package/dist/translations/no.umd.js +11 -0
  166. package/dist/translations/oc.d.ts +8 -0
  167. package/dist/translations/oc.js +5 -0
  168. package/dist/translations/oc.umd.js +11 -0
  169. package/dist/translations/pl.d.ts +8 -0
  170. package/dist/translations/pl.js +5 -0
  171. package/dist/translations/pl.umd.js +11 -0
  172. package/dist/translations/pt-br.d.ts +8 -0
  173. package/dist/translations/pt-br.js +5 -0
  174. package/dist/translations/pt-br.umd.js +11 -0
  175. package/dist/translations/pt.d.ts +8 -0
  176. package/dist/translations/pt.js +5 -0
  177. package/dist/translations/pt.umd.js +11 -0
  178. package/dist/translations/ro.d.ts +8 -0
  179. package/dist/translations/ro.js +5 -0
  180. package/dist/translations/ro.umd.js +11 -0
  181. package/dist/translations/ru.d.ts +8 -0
  182. package/dist/translations/ru.js +5 -0
  183. package/dist/translations/ru.umd.js +11 -0
  184. package/dist/translations/si.d.ts +8 -0
  185. package/dist/translations/si.js +5 -0
  186. package/dist/translations/si.umd.js +11 -0
  187. package/dist/translations/sk.d.ts +8 -0
  188. package/dist/translations/sk.js +5 -0
  189. package/dist/translations/sk.umd.js +11 -0
  190. package/dist/translations/sl.d.ts +8 -0
  191. package/dist/translations/sl.js +5 -0
  192. package/dist/translations/sl.umd.js +11 -0
  193. package/dist/translations/sq.d.ts +8 -0
  194. package/dist/translations/sq.js +5 -0
  195. package/dist/translations/sq.umd.js +11 -0
  196. package/dist/translations/sr-latn.d.ts +8 -0
  197. package/dist/translations/sr-latn.js +5 -0
  198. package/dist/translations/sr-latn.umd.js +11 -0
  199. package/dist/translations/sr.d.ts +8 -0
  200. package/dist/translations/sr.js +5 -0
  201. package/dist/translations/sr.umd.js +11 -0
  202. package/dist/translations/sv.d.ts +8 -0
  203. package/dist/translations/sv.js +5 -0
  204. package/dist/translations/sv.umd.js +11 -0
  205. package/dist/translations/th.d.ts +8 -0
  206. package/dist/translations/th.js +5 -0
  207. package/dist/translations/th.umd.js +11 -0
  208. package/dist/translations/ti.d.ts +8 -0
  209. package/dist/translations/ti.js +5 -0
  210. package/dist/translations/ti.umd.js +11 -0
  211. package/dist/translations/tk.d.ts +8 -0
  212. package/dist/translations/tk.js +5 -0
  213. package/dist/translations/tk.umd.js +11 -0
  214. package/dist/translations/tr.d.ts +8 -0
  215. package/dist/translations/tr.js +5 -0
  216. package/dist/translations/tr.umd.js +11 -0
  217. package/dist/translations/tt.d.ts +8 -0
  218. package/dist/translations/tt.js +5 -0
  219. package/dist/translations/tt.umd.js +11 -0
  220. package/dist/translations/ug.d.ts +8 -0
  221. package/dist/translations/ug.js +5 -0
  222. package/dist/translations/ug.umd.js +11 -0
  223. package/dist/translations/uk.d.ts +8 -0
  224. package/dist/translations/uk.js +5 -0
  225. package/dist/translations/uk.umd.js +11 -0
  226. package/dist/translations/ur.d.ts +8 -0
  227. package/dist/translations/ur.js +5 -0
  228. package/dist/translations/ur.umd.js +11 -0
  229. package/dist/translations/uz.d.ts +8 -0
  230. package/dist/translations/uz.js +5 -0
  231. package/dist/translations/uz.umd.js +11 -0
  232. package/dist/translations/vi.d.ts +8 -0
  233. package/dist/translations/vi.js +5 -0
  234. package/dist/translations/vi.umd.js +11 -0
  235. package/dist/translations/zh-cn.d.ts +8 -0
  236. package/dist/translations/zh-cn.js +5 -0
  237. package/dist/translations/zh-cn.umd.js +11 -0
  238. package/dist/translations/zh.d.ts +8 -0
  239. package/dist/translations/zh.js +5 -0
  240. package/dist/translations/zh.umd.js +11 -0
  241. package/dist/typings.d.ts +16 -0
  242. package/lang/contexts.json +31 -0
  243. package/lang/translations/af.po +134 -0
  244. package/lang/translations/ar.po +134 -0
  245. package/lang/translations/ast.po +134 -0
  246. package/lang/translations/az.po +134 -0
  247. package/lang/translations/bg.po +134 -0
  248. package/lang/translations/bn.po +134 -0
  249. package/lang/translations/bs.po +134 -0
  250. package/lang/translations/ca.po +134 -0
  251. package/lang/translations/cs.po +134 -0
  252. package/lang/translations/da.po +134 -0
  253. package/lang/translations/de-ch.po +134 -0
  254. package/lang/translations/de.po +134 -0
  255. package/lang/translations/el.po +134 -0
  256. package/lang/translations/en-au.po +134 -0
  257. package/lang/translations/en-gb.po +134 -0
  258. package/lang/translations/en.po +134 -0
  259. package/lang/translations/eo.po +134 -0
  260. package/lang/translations/es-co.po +134 -0
  261. package/lang/translations/es.po +134 -0
  262. package/lang/translations/et.po +134 -0
  263. package/lang/translations/eu.po +134 -0
  264. package/lang/translations/fa.po +134 -0
  265. package/lang/translations/fi.po +134 -0
  266. package/lang/translations/fr.po +134 -0
  267. package/lang/translations/gl.po +134 -0
  268. package/lang/translations/gu.po +134 -0
  269. package/lang/translations/he.po +134 -0
  270. package/lang/translations/hi.po +134 -0
  271. package/lang/translations/hr.po +134 -0
  272. package/lang/translations/hu.po +134 -0
  273. package/lang/translations/hy.po +134 -0
  274. package/lang/translations/id.po +134 -0
  275. package/lang/translations/it.po +134 -0
  276. package/lang/translations/ja.po +134 -0
  277. package/lang/translations/jv.po +134 -0
  278. package/lang/translations/km.po +134 -0
  279. package/lang/translations/kn.po +134 -0
  280. package/lang/translations/ko.po +134 -0
  281. package/lang/translations/ku.po +134 -0
  282. package/lang/translations/lt.po +134 -0
  283. package/lang/translations/lv.po +134 -0
  284. package/lang/translations/ms.po +134 -0
  285. package/lang/translations/nb.po +134 -0
  286. package/lang/translations/ne.po +134 -0
  287. package/lang/translations/nl.po +134 -0
  288. package/lang/translations/no.po +134 -0
  289. package/lang/translations/oc.po +134 -0
  290. package/lang/translations/pl.po +134 -0
  291. package/lang/translations/pt-br.po +134 -0
  292. package/lang/translations/pt.po +134 -0
  293. package/lang/translations/ro.po +134 -0
  294. package/lang/translations/ru.po +134 -0
  295. package/lang/translations/si.po +134 -0
  296. package/lang/translations/sk.po +134 -0
  297. package/lang/translations/sl.po +134 -0
  298. package/lang/translations/sq.po +134 -0
  299. package/lang/translations/sr-latn.po +134 -0
  300. package/lang/translations/sr.po +134 -0
  301. package/lang/translations/sv.po +134 -0
  302. package/lang/translations/th.po +134 -0
  303. package/lang/translations/ti.po +134 -0
  304. package/lang/translations/tk.po +134 -0
  305. package/lang/translations/tr.po +134 -0
  306. package/lang/translations/tt.po +134 -0
  307. package/lang/translations/ug.po +134 -0
  308. package/lang/translations/uk.po +134 -0
  309. package/lang/translations/ur.po +134 -0
  310. package/lang/translations/uz.po +134 -0
  311. package/lang/translations/vi.po +134 -0
  312. package/lang/translations/zh-cn.po +134 -0
  313. package/lang/translations/zh.po +134 -0
  314. package/package.json +51 -0
  315. package/src/accessibility.d.ts +361 -0
  316. package/src/accessibility.js +325 -0
  317. package/src/augmentation.d.ts +10 -0
  318. package/src/augmentation.js +5 -0
  319. package/src/command.d.ts +189 -0
  320. package/src/command.js +185 -0
  321. package/src/commandcollection.d.ts +83 -0
  322. package/src/commandcollection.js +83 -0
  323. package/src/context.d.ts +237 -0
  324. package/src/context.js +229 -0
  325. package/src/contextplugin.d.ts +69 -0
  326. package/src/contextplugin.js +55 -0
  327. package/src/editingkeystrokehandler.d.ts +56 -0
  328. package/src/editingkeystrokehandler.js +57 -0
  329. package/src/editor/editor.d.ts +520 -0
  330. package/src/editor/editor.js +701 -0
  331. package/src/editor/editorconfig.d.ts +988 -0
  332. package/src/editor/editorconfig.js +5 -0
  333. package/src/editor/utils/attachtoform.d.ts +15 -0
  334. package/src/editor/utils/attachtoform.js +57 -0
  335. package/src/editor/utils/dataapimixin.d.ts +79 -0
  336. package/src/editor/utils/dataapimixin.js +12 -0
  337. package/src/editor/utils/editorusagedata.d.ts +58 -0
  338. package/src/editor/utils/editorusagedata.js +120 -0
  339. package/src/editor/utils/elementapimixin.d.ts +35 -0
  340. package/src/editor/utils/elementapimixin.js +43 -0
  341. package/src/editor/utils/securesourceelement.d.ts +17 -0
  342. package/src/editor/utils/securesourceelement.js +35 -0
  343. package/src/index.d.ts +90 -0
  344. package/src/index.js +147 -0
  345. package/src/multicommand.d.ts +66 -0
  346. package/src/multicommand.js +82 -0
  347. package/src/pendingactions.d.ts +122 -0
  348. package/src/pendingactions.js +123 -0
  349. package/src/plugin.d.ts +290 -0
  350. package/src/plugin.js +118 -0
  351. package/src/plugincollection.d.ts +117 -0
  352. package/src/plugincollection.js +473 -0
  353. package/src/typings.d.ts +12 -0
  354. package/src/typings.js +5 -0
  355. package/theme/icons/align-bottom.svg +1 -0
  356. package/theme/icons/align-center.svg +1 -0
  357. package/theme/icons/align-justify.svg +1 -0
  358. package/theme/icons/align-left.svg +1 -0
  359. package/theme/icons/align-middle.svg +1 -0
  360. package/theme/icons/align-right.svg +1 -0
  361. package/theme/icons/align-top.svg +1 -0
  362. package/theme/icons/bold.svg +1 -0
  363. package/theme/icons/browse-files.svg +1 -0
  364. package/theme/icons/bulletedlist.svg +1 -0
  365. package/theme/icons/cancel.svg +1 -0
  366. package/theme/icons/caption.svg +1 -0
  367. package/theme/icons/check.svg +1 -0
  368. package/theme/icons/codeblock.svg +1 -0
  369. package/theme/icons/cog.svg +1 -0
  370. package/theme/icons/color-palette.svg +1 -0
  371. package/theme/icons/drag-indicator.svg +1 -0
  372. package/theme/icons/eraser.svg +1 -0
  373. package/theme/icons/heading1.svg +1 -0
  374. package/theme/icons/heading2.svg +1 -0
  375. package/theme/icons/heading3.svg +1 -0
  376. package/theme/icons/heading4.svg +1 -0
  377. package/theme/icons/heading5.svg +1 -0
  378. package/theme/icons/heading6.svg +1 -0
  379. package/theme/icons/history.svg +1 -0
  380. package/theme/icons/horizontalline.svg +1 -0
  381. package/theme/icons/html.svg +1 -0
  382. package/theme/icons/image-asset-manager.svg +1 -0
  383. package/theme/icons/image-upload.svg +1 -0
  384. package/theme/icons/image-url.svg +1 -0
  385. package/theme/icons/image.svg +1 -0
  386. package/theme/icons/importexport.svg +1 -0
  387. package/theme/icons/indent.svg +1 -0
  388. package/theme/icons/loupe.svg +1 -0
  389. package/theme/icons/low-vision.svg +1 -0
  390. package/theme/icons/next-arrow.svg +1 -0
  391. package/theme/icons/numberedlist.svg +1 -0
  392. package/theme/icons/object-center.svg +1 -0
  393. package/theme/icons/object-full-width.svg +1 -0
  394. package/theme/icons/object-inline-left.svg +1 -0
  395. package/theme/icons/object-inline-right.svg +1 -0
  396. package/theme/icons/object-inline.svg +1 -0
  397. package/theme/icons/object-left.svg +1 -0
  398. package/theme/icons/object-right.svg +1 -0
  399. package/theme/icons/object-size-custom.svg +1 -0
  400. package/theme/icons/object-size-full.svg +1 -0
  401. package/theme/icons/object-size-large.svg +1 -0
  402. package/theme/icons/object-size-medium.svg +1 -0
  403. package/theme/icons/object-size-small.svg +1 -0
  404. package/theme/icons/outdent.svg +1 -0
  405. package/theme/icons/paragraph.svg +1 -0
  406. package/theme/icons/pencil.svg +1 -0
  407. package/theme/icons/pilcrow.svg +1 -0
  408. package/theme/icons/plus.svg +1 -0
  409. package/theme/icons/previous-arrow.svg +1 -0
  410. package/theme/icons/quote.svg +1 -0
  411. package/theme/icons/redo.svg +1 -0
  412. package/theme/icons/table.svg +1 -0
  413. package/theme/icons/text-alternative.svg +1 -0
  414. package/theme/icons/text.svg +1 -0
  415. package/theme/icons/three-vertical-dots.svg +1 -0
  416. package/theme/icons/todolist.svg +1 -0
  417. package/theme/icons/undo.svg +1 -0
package/src/command.js ADDED
@@ -0,0 +1,185 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module core/command
7
+ */
8
+ import { ObservableMixin } from '@ckeditor/ckeditor5-utils';
9
+ /**
10
+ * Base class for the CKEditor commands.
11
+ *
12
+ * Commands are the main way to manipulate the editor contents and state. They are mostly used by UI elements (or by other
13
+ * commands) to make changes in the model. Commands are available in every part of the code that has access to
14
+ * the {@link module:core/editor/editor~Editor editor} instance.
15
+ *
16
+ * Instances of registered commands can be retrieved from {@link module:core/editor/editor~Editor#commands `editor.commands`}.
17
+ * The easiest way to execute a command is through {@link module:core/editor/editor~Editor#execute `editor.execute()`}.
18
+ *
19
+ * By default, commands are disabled when the editor is in the {@link module:core/editor/editor~Editor#isReadOnly read-only} mode
20
+ * but commands with the {@link module:core/command~Command#affectsData `affectsData`} flag set to `false` will not be disabled.
21
+ */
22
+ export default class Command extends /* #__PURE__ */ ObservableMixin() {
23
+ /**
24
+ * Creates a new `Command` instance.
25
+ *
26
+ * @param editor The editor on which this command will be used.
27
+ */
28
+ constructor(editor) {
29
+ super();
30
+ this.editor = editor;
31
+ this.set('value', undefined);
32
+ this.set('isEnabled', false);
33
+ this._affectsData = true;
34
+ this._isEnabledBasedOnSelection = true;
35
+ this._disableStack = new Set();
36
+ this.decorate('execute');
37
+ // By default, every command is refreshed when changes are applied to the model.
38
+ this.listenTo(this.editor.model.document, 'change', () => {
39
+ this.refresh();
40
+ });
41
+ this.listenTo(editor, 'change:isReadOnly', () => {
42
+ this.refresh();
43
+ });
44
+ // By default, commands are disabled if the selection is in non-editable place or editor is in read-only mode.
45
+ this.on('set:isEnabled', evt => {
46
+ if (!this.affectsData) {
47
+ return;
48
+ }
49
+ const selection = editor.model.document.selection;
50
+ const selectionInGraveyard = selection.getFirstPosition().root.rootName == '$graveyard';
51
+ const canEditAtSelection = !selectionInGraveyard && editor.model.canEditAt(selection);
52
+ // Disable if editor is read only, or when selection is in a place which cannot be edited.
53
+ //
54
+ // Checking `editor.isReadOnly` is needed for all commands that have `_isEnabledBasedOnSelection == false`.
55
+ // E.g. undo does not base on selection, but affects data and should be disabled when the editor is in read-only mode.
56
+ if (editor.isReadOnly || this._isEnabledBasedOnSelection && !canEditAtSelection) {
57
+ evt.return = false;
58
+ evt.stop();
59
+ }
60
+ }, { priority: 'highest' });
61
+ this.on('execute', evt => {
62
+ if (!this.isEnabled) {
63
+ evt.stop();
64
+ }
65
+ }, { priority: 'high' });
66
+ }
67
+ /**
68
+ * A flag indicating whether a command execution changes the editor data or not.
69
+ *
70
+ * Commands with `affectsData` set to `false` will not be automatically disabled in
71
+ * the {@link module:core/editor/editor~Editor#isReadOnly read-only mode} and
72
+ * {@glink features/read-only#related-features other editor modes} with restricted user write permissions.
73
+ *
74
+ * **Note:** You do not have to set it for your every command. It is `true` by default.
75
+ *
76
+ * @default true
77
+ */
78
+ get affectsData() {
79
+ return this._affectsData;
80
+ }
81
+ set affectsData(affectsData) {
82
+ this._affectsData = affectsData;
83
+ }
84
+ /**
85
+ * Refreshes the command. The command should update its {@link #isEnabled} and {@link #value} properties
86
+ * in this method.
87
+ *
88
+ * This method is automatically called when
89
+ * {@link module:engine/model/document~Document#event:change any changes are applied to the document}.
90
+ */
91
+ refresh() {
92
+ this.isEnabled = true;
93
+ }
94
+ /**
95
+ * Disables the command.
96
+ *
97
+ * Command may be disabled by multiple features or algorithms (at once). When disabling a command, unique id should be passed
98
+ * (e.g. the feature name). The same identifier should be used when {@link #clearForceDisabled enabling back} the command.
99
+ * The command becomes enabled only after all features {@link #clearForceDisabled enabled it back}.
100
+ *
101
+ * Disabling and enabling a command:
102
+ *
103
+ * ```ts
104
+ * command.isEnabled; // -> true
105
+ * command.forceDisabled( 'MyFeature' );
106
+ * command.isEnabled; // -> false
107
+ * command.clearForceDisabled( 'MyFeature' );
108
+ * command.isEnabled; // -> true
109
+ * ```
110
+ *
111
+ * Command disabled by multiple features:
112
+ *
113
+ * ```ts
114
+ * command.forceDisabled( 'MyFeature' );
115
+ * command.forceDisabled( 'OtherFeature' );
116
+ * command.clearForceDisabled( 'MyFeature' );
117
+ * command.isEnabled; // -> false
118
+ * command.clearForceDisabled( 'OtherFeature' );
119
+ * command.isEnabled; // -> true
120
+ * ```
121
+ *
122
+ * Multiple disabling with the same identifier is redundant:
123
+ *
124
+ * ```ts
125
+ * command.forceDisabled( 'MyFeature' );
126
+ * command.forceDisabled( 'MyFeature' );
127
+ * command.clearForceDisabled( 'MyFeature' );
128
+ * command.isEnabled; // -> true
129
+ * ```
130
+ *
131
+ * **Note:** some commands or algorithms may have more complex logic when it comes to enabling or disabling certain commands,
132
+ * so the command might be still disabled after {@link #clearForceDisabled} was used.
133
+ *
134
+ * @param id Unique identifier for disabling. Use the same id when {@link #clearForceDisabled enabling back} the command.
135
+ */
136
+ forceDisabled(id) {
137
+ this._disableStack.add(id);
138
+ if (this._disableStack.size == 1) {
139
+ this.on('set:isEnabled', forceDisable, { priority: 'highest' });
140
+ this.isEnabled = false;
141
+ }
142
+ }
143
+ /**
144
+ * Clears forced disable previously set through {@link #forceDisabled}. See {@link #forceDisabled}.
145
+ *
146
+ * @param id Unique identifier, equal to the one passed in {@link #forceDisabled} call.
147
+ */
148
+ clearForceDisabled(id) {
149
+ this._disableStack.delete(id);
150
+ if (this._disableStack.size == 0) {
151
+ this.off('set:isEnabled', forceDisable);
152
+ this.refresh();
153
+ }
154
+ }
155
+ /**
156
+ * Executes the command.
157
+ *
158
+ * A command may accept parameters. They will be passed from {@link module:core/editor/editor~Editor#execute `editor.execute()`}
159
+ * to the command.
160
+ *
161
+ * The `execute()` method will automatically abort when the command is disabled ({@link #isEnabled} is `false`).
162
+ * This behavior is implemented by a high priority listener to the {@link #event:execute} event.
163
+ *
164
+ * In order to see how to disable a command from "outside" see the {@link #isEnabled} documentation.
165
+ *
166
+ * This method may return a value, which would be forwarded all the way down to the
167
+ * {@link module:core/editor/editor~Editor#execute `editor.execute()`}.
168
+ *
169
+ * @fires execute
170
+ */
171
+ execute(...args) { return undefined; } // eslint-disable-line @typescript-eslint/no-unused-vars
172
+ /**
173
+ * Destroys the command.
174
+ */
175
+ destroy() {
176
+ this.stopListening();
177
+ }
178
+ }
179
+ /**
180
+ * Helper function that forces command to be disabled.
181
+ */
182
+ function forceDisable(evt) {
183
+ evt.return = false;
184
+ evt.stop();
185
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ import type Command from './command.js';
6
+ /**
7
+ * Collection of commands. Its instance is available in {@link module:core/editor/editor~Editor#commands `editor.commands`}.
8
+ */
9
+ export default class CommandCollection implements Iterable<[string, Command]> {
10
+ /**
11
+ * Command map.
12
+ */
13
+ private _commands;
14
+ /**
15
+ * Creates collection instance.
16
+ */
17
+ constructor();
18
+ /**
19
+ * Registers a new command.
20
+ *
21
+ * @param commandName The name of the command.
22
+ */
23
+ add<TName extends string>(commandName: TName, command: CommandsMap[TName]): void;
24
+ /**
25
+ * Retrieves a command from the collection.
26
+ *
27
+ * @param commandName The name of the command.
28
+ */
29
+ get<TName extends string>(commandName: TName): CommandsMap[TName] | undefined;
30
+ /**
31
+ * Executes a command.
32
+ *
33
+ * @param commandName The name of the command.
34
+ * @param commandParams Command parameters.
35
+ * @returns The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
36
+ */
37
+ execute<TName extends string>(commandName: TName, ...commandParams: Parameters<CommandsMap[TName]['execute']>): ReturnType<CommandsMap[TName]['execute']>;
38
+ /**
39
+ * Returns iterator of command names.
40
+ */
41
+ names(): IterableIterator<string>;
42
+ /**
43
+ * Returns iterator of command instances.
44
+ */
45
+ commands(): IterableIterator<Command>;
46
+ /**
47
+ * Iterable interface.
48
+ *
49
+ * Returns `[ commandName, commandInstance ]` pairs.
50
+ */
51
+ [Symbol.iterator](): Iterator<[string, Command]>;
52
+ /**
53
+ * Destroys all collection commands.
54
+ */
55
+ destroy(): void;
56
+ }
57
+ /**
58
+ * Helper type that maps command names to their types.
59
+ * It is meant to be extended with module augmentation.
60
+ *
61
+ * ```ts
62
+ * class MyCommand extends Command {
63
+ * public execute( parameter: A ): B {
64
+ * // ...
65
+ * }
66
+ * }
67
+ *
68
+ * declare module '@ckeditor/ckeditor5-core' {
69
+ * interface CommandsMap {
70
+ * myCommand: MyCommand;
71
+ * }
72
+ * }
73
+ *
74
+ * // Returns `MyCommand | undefined`.
75
+ * const myCommand = editor.commands.get( 'myCommand' );
76
+ *
77
+ * // Expects `A` type as parameter and returns `B`.
78
+ * const value = editor.commands.execute( 'myCommand', new A() );
79
+ * ```
80
+ */
81
+ export interface CommandsMap {
82
+ [name: string]: Command;
83
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module core/commandcollection
7
+ */
8
+ import { CKEditorError } from '@ckeditor/ckeditor5-utils';
9
+ /**
10
+ * Collection of commands. Its instance is available in {@link module:core/editor/editor~Editor#commands `editor.commands`}.
11
+ */
12
+ export default class CommandCollection {
13
+ /**
14
+ * Creates collection instance.
15
+ */
16
+ constructor() {
17
+ this._commands = new Map();
18
+ }
19
+ /**
20
+ * Registers a new command.
21
+ *
22
+ * @param commandName The name of the command.
23
+ */
24
+ add(commandName, command) {
25
+ this._commands.set(commandName, command);
26
+ }
27
+ /**
28
+ * Retrieves a command from the collection.
29
+ *
30
+ * @param commandName The name of the command.
31
+ */
32
+ get(commandName) {
33
+ return this._commands.get(commandName);
34
+ }
35
+ /**
36
+ * Executes a command.
37
+ *
38
+ * @param commandName The name of the command.
39
+ * @param commandParams Command parameters.
40
+ * @returns The value returned by the {@link module:core/command~Command#execute `command.execute()`}.
41
+ */
42
+ execute(commandName, ...commandParams) {
43
+ const command = this.get(commandName);
44
+ if (!command) {
45
+ /**
46
+ * Command does not exist.
47
+ *
48
+ * @error commandcollection-command-not-found
49
+ * @param commandName Name of the command.
50
+ */
51
+ throw new CKEditorError('commandcollection-command-not-found', this, { commandName });
52
+ }
53
+ return command.execute(...commandParams);
54
+ }
55
+ /**
56
+ * Returns iterator of command names.
57
+ */
58
+ *names() {
59
+ yield* this._commands.keys();
60
+ }
61
+ /**
62
+ * Returns iterator of command instances.
63
+ */
64
+ *commands() {
65
+ yield* this._commands.values();
66
+ }
67
+ /**
68
+ * Iterable interface.
69
+ *
70
+ * Returns `[ commandName, commandInstance ]` pairs.
71
+ */
72
+ [Symbol.iterator]() {
73
+ return this._commands[Symbol.iterator]();
74
+ }
75
+ /**
76
+ * Destroys all collection commands.
77
+ */
78
+ destroy() {
79
+ for (const command of this.commands()) {
80
+ command.destroy();
81
+ }
82
+ }
83
+ }
@@ -0,0 +1,237 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @module core/context
7
+ */
8
+ import { Config, Collection, Locale, type LocaleTranslate } from '@ckeditor/ckeditor5-utils';
9
+ import PluginCollection from './plugincollection.js';
10
+ import type Editor from './editor/editor.js';
11
+ import type { LoadedPlugins, PluginConstructor } from './plugin.js';
12
+ import type { EditorConfig } from './editor/editorconfig.js';
13
+ /**
14
+ * Provides a common, higher-level environment for solutions that use multiple {@link module:core/editor/editor~Editor editors}
15
+ * or plugins that work outside the editor. Use it instead of {@link module:core/editor/editor~Editor.create `Editor.create()`}
16
+ * in advanced application integrations.
17
+ *
18
+ * All configuration options passed to a context will be used as default options for the editor instances initialized in that context.
19
+ *
20
+ * {@link module:core/contextplugin~ContextPlugin Context plugins} passed to a context instance will be shared among all
21
+ * editor instances initialized in this context. These will be the same plugin instances for all the editors.
22
+ *
23
+ * **Note:** The context can only be initialized with {@link module:core/contextplugin~ContextPlugin context plugins}
24
+ * (e.g. [comments](https://ckeditor.com/collaboration/comments/)). Regular {@link module:core/plugin~Plugin plugins} require an
25
+ * editor instance to work and cannot be added to a context.
26
+ *
27
+ * **Note:** You can add a context plugin to an editor instance, though.
28
+ *
29
+ * If you are using multiple editor instances on one page and use any context plugins, create a context to share the configuration and
30
+ * plugins among these editors. Some plugins will use the information about all existing editors to better integrate between them.
31
+ *
32
+ * If you are using plugins that do not require an editor to work (e.g. [comments](https://ckeditor.com/collaboration/comments/)),
33
+ * enable and configure them using the context.
34
+ *
35
+ * If you are using only a single editor on each page, use {@link module:core/editor/editor~Editor.create `Editor.create()`} instead.
36
+ * In such a case, a context instance will be created by the editor instance in a transparent way.
37
+ *
38
+ * See {@link ~Context.create `Context.create()`} for usage examples.
39
+ */
40
+ export default class Context {
41
+ /**
42
+ * Stores all the configurations specific to this context instance.
43
+ */
44
+ readonly config: Config<ContextConfig>;
45
+ /**
46
+ * The plugins loaded and in use by this context instance.
47
+ */
48
+ readonly plugins: PluginCollection<Context | Editor>;
49
+ readonly locale: Locale;
50
+ /**
51
+ * Shorthand for {@link module:utils/locale~Locale#t}.
52
+ */
53
+ readonly t: LocaleTranslate;
54
+ /**
55
+ * A list of editors that this context instance is injected to.
56
+ */
57
+ readonly editors: Collection<Editor>;
58
+ /**
59
+ * The default configuration which is built into the `Context` class.
60
+ *
61
+ * It is used in CKEditor 5 builds featuring `Context` to provide the default configuration options which are later used during the
62
+ * context initialization.
63
+ *
64
+ * ```ts
65
+ * Context.defaultConfig = {
66
+ * foo: 1,
67
+ * bar: 2
68
+ * };
69
+ *
70
+ * Context
71
+ * .create()
72
+ * .then( context => {
73
+ * context.config.get( 'foo' ); // -> 1
74
+ * context.config.get( 'bar' ); // -> 2
75
+ * } );
76
+ *
77
+ * // The default options can be overridden by the configuration passed to create().
78
+ * Context
79
+ * .create( { bar: 3 } )
80
+ * .then( context => {
81
+ * context.config.get( 'foo' ); // -> 1
82
+ * context.config.get( 'bar' ); // -> 3
83
+ * } );
84
+ * ```
85
+ *
86
+ * See also {@link module:core/context~Context.builtinPlugins `Context.builtinPlugins`}
87
+ * and {@link module:core/editor/editor~Editor.defaultConfig `Editor.defaultConfig`}.
88
+ */
89
+ static defaultConfig: ContextConfig;
90
+ /**
91
+ * An array of plugins built into the `Context` class.
92
+ *
93
+ * It is used in CKEditor 5 builds featuring `Context` to provide a list of context plugins which are later automatically initialized
94
+ * during the context initialization.
95
+ *
96
+ * They will be automatically initialized by `Context` unless `config.plugins` is passed.
97
+ *
98
+ * ```ts
99
+ * // Build some context plugins into the Context class first.
100
+ * Context.builtinPlugins = [ FooPlugin, BarPlugin ];
101
+ *
102
+ * // Normally, you need to define config.plugins, but since Context.builtinPlugins was
103
+ * // defined, now you can call create() without any configuration.
104
+ * Context
105
+ * .create()
106
+ * .then( context => {
107
+ * context.plugins.get( FooPlugin ); // -> An instance of the Foo plugin.
108
+ * context.plugins.get( BarPlugin ); // -> An instance of the Bar plugin.
109
+ * } );
110
+ * ```
111
+ *
112
+ * See also {@link module:core/context~Context.defaultConfig `Context.defaultConfig`}
113
+ * and {@link module:core/editor/editor~Editor.builtinPlugins `Editor.builtinPlugins`}.
114
+ */
115
+ static builtinPlugins: Array<PluginConstructor<Context | Editor>>;
116
+ /**
117
+ * Reference to the editor which created the context.
118
+ * Null when the context was created outside of the editor.
119
+ *
120
+ * It is used to destroy the context when removing the editor that has created the context.
121
+ */
122
+ private _contextOwner;
123
+ /**
124
+ * Creates a context instance with a given configuration.
125
+ *
126
+ * Usually not to be used directly. See the static {@link module:core/context~Context.create `create()`} method.
127
+ *
128
+ * @param config The context configuration.
129
+ */
130
+ constructor(config?: ContextConfig);
131
+ /**
132
+ * Loads and initializes plugins specified in the configuration.
133
+ *
134
+ * @returns A promise which resolves once the initialization is completed, providing an array of loaded plugins.
135
+ */
136
+ initPlugins(): Promise<LoadedPlugins>;
137
+ /**
138
+ * Destroys the context instance and all editors used with the context,
139
+ * releasing all resources used by the context.
140
+ *
141
+ * @returns A promise that resolves once the context instance is fully destroyed.
142
+ */
143
+ destroy(): Promise<unknown>;
144
+ /**
145
+ * Adds a reference to the editor which is used with this context.
146
+ *
147
+ * When the given editor has created the context, the reference to this editor will be stored
148
+ * as a {@link ~Context#_contextOwner}.
149
+ *
150
+ * This method should only be used by the editor.
151
+ *
152
+ * @internal
153
+ * @param isContextOwner Stores the given editor as a context owner.
154
+ */
155
+ _addEditor(editor: Editor, isContextOwner: boolean): void;
156
+ /**
157
+ * Removes a reference to the editor which was used with this context.
158
+ * When the context was created by the given editor, the context will be destroyed.
159
+ *
160
+ * This method should only be used by the editor.
161
+ *
162
+ * @internal
163
+ * @return A promise that resolves once the editor is removed from the context or when the context was destroyed.
164
+ */
165
+ _removeEditor(editor: Editor): Promise<unknown>;
166
+ /**
167
+ * Returns the context configuration which will be copied to the editors created using this context.
168
+ *
169
+ * The configuration returned by this method has the plugins configuration removed &ndash; plugins are shared with all editors
170
+ * through another mechanism.
171
+ *
172
+ * This method should only be used by the editor.
173
+ *
174
+ * @internal
175
+ * @returns Configuration as a plain object.
176
+ */
177
+ _getEditorConfig(): Partial<EditorConfig>;
178
+ /**
179
+ * Creates and initializes a new context instance.
180
+ *
181
+ * ```ts
182
+ * const commonConfig = { ... }; // Configuration for all the plugins and editors.
183
+ * const editorPlugins = [ ... ]; // Regular plugins here.
184
+ *
185
+ * Context
186
+ * .create( {
187
+ * // Only context plugins here.
188
+ * plugins: [ ... ],
189
+ *
190
+ * // Configure the language for all the editors (it cannot be overwritten).
191
+ * language: { ... },
192
+ *
193
+ * // Configuration for context plugins.
194
+ * comments: { ... },
195
+ * ...
196
+ *
197
+ * // Default configuration for editor plugins.
198
+ * toolbar: { ... },
199
+ * image: { ... },
200
+ * ...
201
+ * } )
202
+ * .then( context => {
203
+ * const promises = [];
204
+ *
205
+ * promises.push( ClassicEditor.create(
206
+ * document.getElementById( 'editor1' ),
207
+ * {
208
+ * editorPlugins,
209
+ * context
210
+ * }
211
+ * ) );
212
+ *
213
+ * promises.push( ClassicEditor.create(
214
+ * document.getElementById( 'editor2' ),
215
+ * {
216
+ * editorPlugins,
217
+ * context,
218
+ * toolbar: { ... } // You can overwrite the configuration of the context.
219
+ * }
220
+ * ) );
221
+ *
222
+ * return Promise.all( promises );
223
+ * } );
224
+ * ```
225
+ *
226
+ * @param config The context configuration.
227
+ * @returns A promise resolved once the context is ready. The promise resolves with the created context instance.
228
+ */
229
+ static create(config?: ContextConfig): Promise<Context>;
230
+ }
231
+ /**
232
+ * The context configuration.
233
+ */
234
+ export type ContextConfig = {
235
+ plugins?: Array<PluginConstructor<Context | Editor>>;
236
+ substitutePlugins?: Array<PluginConstructor<Context | Editor>>;
237
+ } & Omit<EditorConfig, 'plugins' | 'substitutePlugins' | 'removePlugins' | 'extraPlugins'>;