@ckeditor/ckeditor5-html-support 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 (312) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +26 -0
  4. package/build/html-support.js +5 -0
  5. package/build/translations/ar.js +1 -0
  6. package/build/translations/bg.js +1 -0
  7. package/build/translations/bn.js +1 -0
  8. package/build/translations/ca.js +1 -0
  9. package/build/translations/cs.js +1 -0
  10. package/build/translations/da.js +1 -0
  11. package/build/translations/de.js +1 -0
  12. package/build/translations/el.js +1 -0
  13. package/build/translations/en-au.js +1 -0
  14. package/build/translations/es.js +1 -0
  15. package/build/translations/et.js +1 -0
  16. package/build/translations/fi.js +1 -0
  17. package/build/translations/fr.js +1 -0
  18. package/build/translations/gl.js +1 -0
  19. package/build/translations/he.js +1 -0
  20. package/build/translations/hi.js +1 -0
  21. package/build/translations/hr.js +1 -0
  22. package/build/translations/hu.js +1 -0
  23. package/build/translations/id.js +1 -0
  24. package/build/translations/it.js +1 -0
  25. package/build/translations/ja.js +1 -0
  26. package/build/translations/jv.js +1 -0
  27. package/build/translations/ko.js +1 -0
  28. package/build/translations/lt.js +1 -0
  29. package/build/translations/lv.js +1 -0
  30. package/build/translations/ms.js +1 -0
  31. package/build/translations/nl.js +1 -0
  32. package/build/translations/no.js +1 -0
  33. package/build/translations/pl.js +1 -0
  34. package/build/translations/pt-br.js +1 -0
  35. package/build/translations/pt.js +1 -0
  36. package/build/translations/ro.js +1 -0
  37. package/build/translations/ru.js +1 -0
  38. package/build/translations/sk.js +1 -0
  39. package/build/translations/sr-latn.js +1 -0
  40. package/build/translations/sr.js +1 -0
  41. package/build/translations/sv.js +1 -0
  42. package/build/translations/th.js +1 -0
  43. package/build/translations/tr.js +1 -0
  44. package/build/translations/ug.js +1 -0
  45. package/build/translations/uk.js +1 -0
  46. package/build/translations/ur.js +1 -0
  47. package/build/translations/vi.js +1 -0
  48. package/build/translations/zh-cn.js +1 -0
  49. package/build/translations/zh.js +1 -0
  50. package/ckeditor5-metadata.json +60 -0
  51. package/dist/augmentation.d.ts +37 -0
  52. package/dist/converters.d.ts +64 -0
  53. package/dist/datafilter.d.ts +312 -0
  54. package/dist/dataschema.d.ts +191 -0
  55. package/dist/fullpage.d.ts +29 -0
  56. package/dist/generalhtmlsupport.d.ts +106 -0
  57. package/dist/generalhtmlsupportconfig.d.ts +81 -0
  58. package/dist/htmlcomment.d.ts +79 -0
  59. package/dist/htmlpagedataprocessor.d.ts +26 -0
  60. package/dist/index-content.css +4 -0
  61. package/dist/index-editor.css +51 -0
  62. package/dist/index.css +63 -0
  63. package/dist/index.css.map +1 -0
  64. package/dist/index.d.ts +29 -0
  65. package/dist/index.js +4040 -0
  66. package/dist/index.js.map +1 -0
  67. package/dist/integrations/codeblock.d.ts +31 -0
  68. package/dist/integrations/customelement.d.ts +35 -0
  69. package/dist/integrations/dualcontent.d.ts +53 -0
  70. package/dist/integrations/heading.d.ts +39 -0
  71. package/dist/integrations/image.d.ts +34 -0
  72. package/dist/integrations/integrationutils.d.ts +19 -0
  73. package/dist/integrations/list.d.ts +35 -0
  74. package/dist/integrations/mediaembed.d.ts +34 -0
  75. package/dist/integrations/script.d.ts +34 -0
  76. package/dist/integrations/style.d.ts +34 -0
  77. package/dist/integrations/table.d.ts +31 -0
  78. package/dist/schemadefinitions.d.ts +17 -0
  79. package/dist/translations/ar.d.ts +8 -0
  80. package/dist/translations/ar.js +5 -0
  81. package/dist/translations/ar.umd.js +11 -0
  82. package/dist/translations/bg.d.ts +8 -0
  83. package/dist/translations/bg.js +5 -0
  84. package/dist/translations/bg.umd.js +11 -0
  85. package/dist/translations/bn.d.ts +8 -0
  86. package/dist/translations/bn.js +5 -0
  87. package/dist/translations/bn.umd.js +11 -0
  88. package/dist/translations/ca.d.ts +8 -0
  89. package/dist/translations/ca.js +5 -0
  90. package/dist/translations/ca.umd.js +11 -0
  91. package/dist/translations/cs.d.ts +8 -0
  92. package/dist/translations/cs.js +5 -0
  93. package/dist/translations/cs.umd.js +11 -0
  94. package/dist/translations/da.d.ts +8 -0
  95. package/dist/translations/da.js +5 -0
  96. package/dist/translations/da.umd.js +11 -0
  97. package/dist/translations/de.d.ts +8 -0
  98. package/dist/translations/de.js +5 -0
  99. package/dist/translations/de.umd.js +11 -0
  100. package/dist/translations/el.d.ts +8 -0
  101. package/dist/translations/el.js +5 -0
  102. package/dist/translations/el.umd.js +11 -0
  103. package/dist/translations/en-au.d.ts +8 -0
  104. package/dist/translations/en-au.js +5 -0
  105. package/dist/translations/en-au.umd.js +11 -0
  106. package/dist/translations/en.d.ts +8 -0
  107. package/dist/translations/en.js +5 -0
  108. package/dist/translations/en.umd.js +11 -0
  109. package/dist/translations/es.d.ts +8 -0
  110. package/dist/translations/es.js +5 -0
  111. package/dist/translations/es.umd.js +11 -0
  112. package/dist/translations/et.d.ts +8 -0
  113. package/dist/translations/et.js +5 -0
  114. package/dist/translations/et.umd.js +11 -0
  115. package/dist/translations/fi.d.ts +8 -0
  116. package/dist/translations/fi.js +5 -0
  117. package/dist/translations/fi.umd.js +11 -0
  118. package/dist/translations/fr.d.ts +8 -0
  119. package/dist/translations/fr.js +5 -0
  120. package/dist/translations/fr.umd.js +11 -0
  121. package/dist/translations/gl.d.ts +8 -0
  122. package/dist/translations/gl.js +5 -0
  123. package/dist/translations/gl.umd.js +11 -0
  124. package/dist/translations/he.d.ts +8 -0
  125. package/dist/translations/he.js +5 -0
  126. package/dist/translations/he.umd.js +11 -0
  127. package/dist/translations/hi.d.ts +8 -0
  128. package/dist/translations/hi.js +5 -0
  129. package/dist/translations/hi.umd.js +11 -0
  130. package/dist/translations/hr.d.ts +8 -0
  131. package/dist/translations/hr.js +5 -0
  132. package/dist/translations/hr.umd.js +11 -0
  133. package/dist/translations/hu.d.ts +8 -0
  134. package/dist/translations/hu.js +5 -0
  135. package/dist/translations/hu.umd.js +11 -0
  136. package/dist/translations/id.d.ts +8 -0
  137. package/dist/translations/id.js +5 -0
  138. package/dist/translations/id.umd.js +11 -0
  139. package/dist/translations/it.d.ts +8 -0
  140. package/dist/translations/it.js +5 -0
  141. package/dist/translations/it.umd.js +11 -0
  142. package/dist/translations/ja.d.ts +8 -0
  143. package/dist/translations/ja.js +5 -0
  144. package/dist/translations/ja.umd.js +11 -0
  145. package/dist/translations/jv.d.ts +8 -0
  146. package/dist/translations/jv.js +5 -0
  147. package/dist/translations/jv.umd.js +11 -0
  148. package/dist/translations/ko.d.ts +8 -0
  149. package/dist/translations/ko.js +5 -0
  150. package/dist/translations/ko.umd.js +11 -0
  151. package/dist/translations/lt.d.ts +8 -0
  152. package/dist/translations/lt.js +5 -0
  153. package/dist/translations/lt.umd.js +11 -0
  154. package/dist/translations/lv.d.ts +8 -0
  155. package/dist/translations/lv.js +5 -0
  156. package/dist/translations/lv.umd.js +11 -0
  157. package/dist/translations/ms.d.ts +8 -0
  158. package/dist/translations/ms.js +5 -0
  159. package/dist/translations/ms.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/pl.d.ts +8 -0
  167. package/dist/translations/pl.js +5 -0
  168. package/dist/translations/pl.umd.js +11 -0
  169. package/dist/translations/pt-br.d.ts +8 -0
  170. package/dist/translations/pt-br.js +5 -0
  171. package/dist/translations/pt-br.umd.js +11 -0
  172. package/dist/translations/pt.d.ts +8 -0
  173. package/dist/translations/pt.js +5 -0
  174. package/dist/translations/pt.umd.js +11 -0
  175. package/dist/translations/ro.d.ts +8 -0
  176. package/dist/translations/ro.js +5 -0
  177. package/dist/translations/ro.umd.js +11 -0
  178. package/dist/translations/ru.d.ts +8 -0
  179. package/dist/translations/ru.js +5 -0
  180. package/dist/translations/ru.umd.js +11 -0
  181. package/dist/translations/sk.d.ts +8 -0
  182. package/dist/translations/sk.js +5 -0
  183. package/dist/translations/sk.umd.js +11 -0
  184. package/dist/translations/sr-latn.d.ts +8 -0
  185. package/dist/translations/sr-latn.js +5 -0
  186. package/dist/translations/sr-latn.umd.js +11 -0
  187. package/dist/translations/sr.d.ts +8 -0
  188. package/dist/translations/sr.js +5 -0
  189. package/dist/translations/sr.umd.js +11 -0
  190. package/dist/translations/sv.d.ts +8 -0
  191. package/dist/translations/sv.js +5 -0
  192. package/dist/translations/sv.umd.js +11 -0
  193. package/dist/translations/th.d.ts +8 -0
  194. package/dist/translations/th.js +5 -0
  195. package/dist/translations/th.umd.js +11 -0
  196. package/dist/translations/tr.d.ts +8 -0
  197. package/dist/translations/tr.js +5 -0
  198. package/dist/translations/tr.umd.js +11 -0
  199. package/dist/translations/ug.d.ts +8 -0
  200. package/dist/translations/ug.js +5 -0
  201. package/dist/translations/ug.umd.js +11 -0
  202. package/dist/translations/uk.d.ts +8 -0
  203. package/dist/translations/uk.js +5 -0
  204. package/dist/translations/uk.umd.js +11 -0
  205. package/dist/translations/ur.d.ts +8 -0
  206. package/dist/translations/ur.js +5 -0
  207. package/dist/translations/ur.umd.js +11 -0
  208. package/dist/translations/vi.d.ts +8 -0
  209. package/dist/translations/vi.js +5 -0
  210. package/dist/translations/vi.umd.js +11 -0
  211. package/dist/translations/zh-cn.d.ts +8 -0
  212. package/dist/translations/zh-cn.js +5 -0
  213. package/dist/translations/zh-cn.umd.js +11 -0
  214. package/dist/translations/zh.d.ts +8 -0
  215. package/dist/translations/zh.js +5 -0
  216. package/dist/translations/zh.umd.js +11 -0
  217. package/dist/utils.d.ts +76 -0
  218. package/lang/contexts.json +3 -0
  219. package/lang/translations/ar.po +22 -0
  220. package/lang/translations/bg.po +22 -0
  221. package/lang/translations/bn.po +22 -0
  222. package/lang/translations/ca.po +22 -0
  223. package/lang/translations/cs.po +22 -0
  224. package/lang/translations/da.po +22 -0
  225. package/lang/translations/de.po +22 -0
  226. package/lang/translations/el.po +22 -0
  227. package/lang/translations/en-au.po +22 -0
  228. package/lang/translations/en.po +22 -0
  229. package/lang/translations/es.po +22 -0
  230. package/lang/translations/et.po +22 -0
  231. package/lang/translations/fi.po +22 -0
  232. package/lang/translations/fr.po +22 -0
  233. package/lang/translations/gl.po +22 -0
  234. package/lang/translations/he.po +22 -0
  235. package/lang/translations/hi.po +22 -0
  236. package/lang/translations/hr.po +22 -0
  237. package/lang/translations/hu.po +22 -0
  238. package/lang/translations/id.po +22 -0
  239. package/lang/translations/it.po +22 -0
  240. package/lang/translations/ja.po +22 -0
  241. package/lang/translations/jv.po +22 -0
  242. package/lang/translations/ko.po +22 -0
  243. package/lang/translations/lt.po +22 -0
  244. package/lang/translations/lv.po +22 -0
  245. package/lang/translations/ms.po +22 -0
  246. package/lang/translations/nl.po +22 -0
  247. package/lang/translations/no.po +22 -0
  248. package/lang/translations/pl.po +22 -0
  249. package/lang/translations/pt-br.po +22 -0
  250. package/lang/translations/pt.po +22 -0
  251. package/lang/translations/ro.po +22 -0
  252. package/lang/translations/ru.po +22 -0
  253. package/lang/translations/sk.po +22 -0
  254. package/lang/translations/sr-latn.po +22 -0
  255. package/lang/translations/sr.po +22 -0
  256. package/lang/translations/sv.po +22 -0
  257. package/lang/translations/th.po +22 -0
  258. package/lang/translations/tr.po +22 -0
  259. package/lang/translations/ug.po +22 -0
  260. package/lang/translations/uk.po +22 -0
  261. package/lang/translations/ur.po +22 -0
  262. package/lang/translations/vi.po +22 -0
  263. package/lang/translations/zh-cn.po +22 -0
  264. package/lang/translations/zh.po +22 -0
  265. package/package.json +48 -0
  266. package/src/augmentation.d.ts +33 -0
  267. package/src/augmentation.js +5 -0
  268. package/src/converters.d.ts +60 -0
  269. package/src/converters.js +180 -0
  270. package/src/datafilter.d.ts +308 -0
  271. package/src/datafilter.js +755 -0
  272. package/src/dataschema.d.ts +187 -0
  273. package/src/dataschema.js +202 -0
  274. package/src/fullpage.d.ts +25 -0
  275. package/src/fullpage.js +86 -0
  276. package/src/generalhtmlsupport.d.ts +102 -0
  277. package/src/generalhtmlsupport.js +246 -0
  278. package/src/generalhtmlsupportconfig.d.ts +77 -0
  279. package/src/generalhtmlsupportconfig.js +5 -0
  280. package/src/htmlcomment.d.ts +75 -0
  281. package/src/htmlcomment.js +224 -0
  282. package/src/htmlpagedataprocessor.d.ts +22 -0
  283. package/src/htmlpagedataprocessor.js +67 -0
  284. package/src/index.d.ts +25 -0
  285. package/src/index.js +14 -0
  286. package/src/integrations/codeblock.d.ts +27 -0
  287. package/src/integrations/codeblock.js +107 -0
  288. package/src/integrations/customelement.d.ts +31 -0
  289. package/src/integrations/customelement.js +162 -0
  290. package/src/integrations/dualcontent.d.ts +49 -0
  291. package/src/integrations/dualcontent.js +125 -0
  292. package/src/integrations/heading.d.ts +35 -0
  293. package/src/integrations/heading.js +72 -0
  294. package/src/integrations/image.d.ts +30 -0
  295. package/src/integrations/image.js +195 -0
  296. package/src/integrations/integrationutils.d.ts +15 -0
  297. package/src/integrations/integrationutils.js +21 -0
  298. package/src/integrations/list.d.ts +31 -0
  299. package/src/integrations/list.js +185 -0
  300. package/src/integrations/mediaembed.d.ts +30 -0
  301. package/src/integrations/mediaembed.js +125 -0
  302. package/src/integrations/script.d.ts +30 -0
  303. package/src/integrations/script.js +65 -0
  304. package/src/integrations/style.d.ts +30 -0
  305. package/src/integrations/style.js +65 -0
  306. package/src/integrations/table.d.ts +27 -0
  307. package/src/integrations/table.js +169 -0
  308. package/src/schemadefinitions.d.ts +13 -0
  309. package/src/schemadefinitions.js +964 -0
  310. package/src/utils.d.ts +72 -0
  311. package/src/utils.js +139 -0
  312. package/theme/datafilter.css +56 -0
@@ -0,0 +1,312 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module html-support/datafilter
11
+ */
12
+ import { Plugin, type Editor } from 'ckeditor5/src/core.js';
13
+ import { type MatcherPattern, type UpcastConversionApi, type ViewElement, type MatcherObjectPattern } from 'ckeditor5/src/engine.js';
14
+ import { Widget } from 'ckeditor5/src/widget.js';
15
+ import { default as DataSchema, type DataSchemaDefinition } from './dataschema.js';
16
+ import { type GHSViewAttributes } from './utils.js';
17
+ import '../theme/datafilter.css';
18
+ /**
19
+ * Allows to validate elements and element attributes registered by {@link module:html-support/dataschema~DataSchema}.
20
+ *
21
+ * To enable registered element in the editor, use {@link module:html-support/datafilter~DataFilter#allowElement} method:
22
+ *
23
+ * ```ts
24
+ * dataFilter.allowElement( 'section' );
25
+ * ```
26
+ *
27
+ * You can also allow or disallow specific element attributes:
28
+ *
29
+ * ```ts
30
+ * // Allow `data-foo` attribute on `section` element.
31
+ * dataFilter.allowAttributes( {
32
+ * name: 'section',
33
+ * attributes: {
34
+ * 'data-foo': true
35
+ * }
36
+ * } );
37
+ *
38
+ * // Disallow `color` style attribute on 'section' element.
39
+ * dataFilter.disallowAttributes( {
40
+ * name: 'section',
41
+ * styles: {
42
+ * color: /[\s\S]+/
43
+ * }
44
+ * } );
45
+ * ```
46
+ *
47
+ * To apply the information about allowed and disallowed attributes in custom integration plugin,
48
+ * use the {@link module:html-support/datafilter~DataFilter#processViewAttributes `processViewAttributes()`} method.
49
+ */
50
+ export default class DataFilter extends Plugin {
51
+ /**
52
+ * An instance of the {@link module:html-support/dataschema~DataSchema}.
53
+ */
54
+ private readonly _dataSchema;
55
+ /**
56
+ * {@link module:engine/view/matcher~Matcher Matcher} instance describing rules upon which
57
+ * content attributes should be allowed.
58
+ */
59
+ private readonly _allowedAttributes;
60
+ /**
61
+ * {@link module:engine/view/matcher~Matcher Matcher} instance describing rules upon which
62
+ * content attributes should be disallowed.
63
+ */
64
+ private readonly _disallowedAttributes;
65
+ /**
66
+ * Allowed element definitions by {@link module:html-support/datafilter~DataFilter#allowElement} method.
67
+ */
68
+ private readonly _allowedElements;
69
+ /**
70
+ * Disallowed element names by {@link module:html-support/datafilter~DataFilter#disallowElement} method.
71
+ */
72
+ private readonly _disallowedElements;
73
+ /**
74
+ * Indicates if {@link module:engine/controller/datacontroller~DataController editor's data controller}
75
+ * data has been already initialized.
76
+ */
77
+ private _dataInitialized;
78
+ /**
79
+ * Cached map of coupled attributes. Keys are the feature attributes names
80
+ * and values are arrays with coupled GHS attributes names.
81
+ */
82
+ private _coupledAttributes;
83
+ constructor(editor: Editor);
84
+ /**
85
+ * @inheritDoc
86
+ */
87
+ static get pluginName(): "DataFilter";
88
+ /**
89
+ * @inheritDoc
90
+ */
91
+ static get isOfficialPlugin(): true;
92
+ /**
93
+ * @inheritDoc
94
+ */
95
+ static get requires(): readonly [typeof DataSchema, typeof Widget];
96
+ /**
97
+ * Load a configuration of one or many elements, where their attributes should be allowed.
98
+ *
99
+ * **Note**: Rules will be applied just before next data pipeline data init or set.
100
+ *
101
+ * @param config Configuration of elements that should have their attributes accepted in the editor.
102
+ */
103
+ loadAllowedConfig(config: Array<MatcherObjectPattern>): void;
104
+ /**
105
+ * Load a configuration of one or many elements, where their attributes should be disallowed.
106
+ *
107
+ * **Note**: Rules will be applied just before next data pipeline data init or set.
108
+ *
109
+ * @param config Configuration of elements that should have their attributes rejected from the editor.
110
+ */
111
+ loadDisallowedConfig(config: Array<MatcherObjectPattern>): void;
112
+ /**
113
+ * Load a configuration of one or many elements, where when empty should be allowed.
114
+ *
115
+ * **Note**: It modifies DataSchema so must be loaded before registering filtering rules.
116
+ *
117
+ * @param config Configuration of elements that should be preserved even if empty.
118
+ */
119
+ loadAllowedEmptyElementsConfig(config: Array<string>): void;
120
+ /**
121
+ * Allow the given element in the editor context.
122
+ *
123
+ * This method will only allow elements described by the {@link module:html-support/dataschema~DataSchema} used
124
+ * to create data filter.
125
+ *
126
+ * **Note**: Rules will be applied just before next data pipeline data init or set.
127
+ *
128
+ * @param viewName String or regular expression matching view name.
129
+ */
130
+ allowElement(viewName: string | RegExp): void;
131
+ /**
132
+ * Disallow the given element in the editor context.
133
+ *
134
+ * This method will only disallow elements described by the {@link module:html-support/dataschema~DataSchema} used
135
+ * to create data filter.
136
+ *
137
+ * @param viewName String or regular expression matching view name.
138
+ */
139
+ disallowElement(viewName: string | RegExp): void;
140
+ /**
141
+ * Allow the given empty element in the editor context.
142
+ *
143
+ * This method will only allow elements described by the {@link module:html-support/dataschema~DataSchema} used
144
+ * to create data filter.
145
+ *
146
+ * **Note**: It modifies DataSchema so must be called before registering filtering rules.
147
+ *
148
+ * @param viewName String or regular expression matching view name.
149
+ */
150
+ allowEmptyElement(viewName: string): void;
151
+ /**
152
+ * Allow the given attributes for view element allowed by {@link #allowElement} method.
153
+ *
154
+ * @param config Pattern matching all attributes which should be allowed.
155
+ */
156
+ allowAttributes(config: MatcherPattern): void;
157
+ /**
158
+ * Disallow the given attributes for view element allowed by {@link #allowElement} method.
159
+ *
160
+ * @param config Pattern matching all attributes which should be disallowed.
161
+ */
162
+ disallowAttributes(config: MatcherPattern): void;
163
+ /**
164
+ * Processes all allowed and disallowed attributes on the view element by consuming them and returning the allowed ones.
165
+ *
166
+ * This method applies the configuration set up by {@link #allowAttributes `allowAttributes()`}
167
+ * and {@link #disallowAttributes `disallowAttributes()`} over the given view element by consuming relevant attributes.
168
+ * It returns the allowed attributes that were found on the given view element for further processing by integration code.
169
+ *
170
+ * ```ts
171
+ * dispatcher.on( 'element:myElement', ( evt, data, conversionApi ) => {
172
+ * // Get rid of disallowed and extract all allowed attributes from a viewElement.
173
+ * const viewAttributes = dataFilter.processViewAttributes( data.viewItem, conversionApi );
174
+ * // Do something with them, i.e. store inside a model as a dictionary.
175
+ * if ( viewAttributes ) {
176
+ * conversionApi.writer.setAttribute( 'htmlAttributesOfMyElement', viewAttributes, data.modelRange );
177
+ * }
178
+ * } );
179
+ * ```
180
+ *
181
+ * @see module:engine/conversion/viewconsumable~ViewConsumable#consume
182
+ *
183
+ * @returns Object with following properties:
184
+ * - attributes Set with matched attribute names.
185
+ * - styles Set with matched style names.
186
+ * - classes Set with matched class names.
187
+ */
188
+ processViewAttributes(viewElement: ViewElement, conversionApi: UpcastConversionApi): GHSViewAttributes | null;
189
+ /**
190
+ * Adds allowed element definition and fires registration event.
191
+ */
192
+ private _addAllowedElement;
193
+ /**
194
+ * Registers elements allowed by {@link module:html-support/datafilter~DataFilter#allowElement} method
195
+ * once {@link module:engine/controller/datacontroller~DataController editor's data controller} is initialized.
196
+ */
197
+ private _registerElementsAfterInit;
198
+ /**
199
+ * Registers default element handlers.
200
+ */
201
+ private _registerElementHandlers;
202
+ /**
203
+ * Registers a model post-fixer that is removing coupled GHS attributes of inline elements. Those attributes
204
+ * are removed if a coupled feature attribute is removed.
205
+ *
206
+ * For example, consider following HTML:
207
+ *
208
+ * ```html
209
+ * <a href="foo.html" id="myId">bar</a>
210
+ * ```
211
+ *
212
+ * Which would be upcasted to following text node in the model:
213
+ *
214
+ * ```html
215
+ * <$text linkHref="foo.html" htmlA="{ attributes: { id: 'myId' } }">bar</$text>
216
+ * ```
217
+ *
218
+ * When the user removes the link from that text (using UI), only `linkHref` attribute would be removed:
219
+ *
220
+ * ```html
221
+ * <$text htmlA="{ attributes: { id: 'myId' } }">bar</$text>
222
+ * ```
223
+ *
224
+ * The `htmlA` attribute would stay in the model and would cause GHS to generate an `<a>` element.
225
+ * This is incorrect from UX point of view, as the user wanted to remove the whole link (not only `href`).
226
+ */
227
+ private _registerCoupledAttributesPostFixer;
228
+ /**
229
+ * Removes `html*Attributes` attributes from incompatible elements.
230
+ *
231
+ * For example, consider the following HTML:
232
+ *
233
+ * ```html
234
+ * <heading2 htmlH2Attributes="...">foobar[]</heading2>
235
+ * ```
236
+ *
237
+ * Pressing `enter` creates a new `paragraph` element that inherits
238
+ * the `htmlH2Attributes` attribute from `heading2`.
239
+ *
240
+ * ```html
241
+ * <heading2 htmlH2Attributes="...">foobar</heading2>
242
+ * <paragraph htmlH2Attributes="...">[]</paragraph>
243
+ * ```
244
+ *
245
+ * This postfixer ensures that this doesn't happen, and that elements can
246
+ * only have `html*Attributes` associated with them,
247
+ * e.g.: `htmlPAttributes` for `<p>`, `htmlDivAttributes` for `<div>`, etc.
248
+ *
249
+ * With it enabled, pressing `enter` at the end of `<heading2>` will create
250
+ * a new paragraph without the `htmlH2Attributes` attribute.
251
+ *
252
+ * ```html
253
+ * <heading2 htmlH2Attributes="...">foobar</heading2>
254
+ * <paragraph>[]</paragraph>
255
+ * ```
256
+ */
257
+ private _registerAssociatedHtmlAttributesPostFixer;
258
+ /**
259
+ * Collects the map of coupled attributes. The returned map is keyed by the feature attribute name
260
+ * and coupled GHS attribute names are stored in the value array.
261
+ */
262
+ private _getCoupledAttributesMap;
263
+ /**
264
+ * Fires `register` event for the given element definition.
265
+ */
266
+ private _fireRegisterEvent;
267
+ /**
268
+ * Registers object element and attribute converters for the given data schema definition.
269
+ */
270
+ private _registerObjectElement;
271
+ /**
272
+ * Registers block element and attribute converters for the given data schema definition.
273
+ */
274
+ private _registerBlockElement;
275
+ /**
276
+ * Registers inline element and attribute converters for the given data schema definition.
277
+ *
278
+ * Extends `$text` model schema to allow the given definition model attribute and its properties.
279
+ */
280
+ private _registerInlineElement;
281
+ }
282
+ /**
283
+ * Fired when {@link module:html-support/datafilter~DataFilter} is registering element and attribute
284
+ * converters for the {@link module:html-support/dataschema~DataSchemaDefinition element definition}.
285
+ *
286
+ * The event also accepts {@link module:html-support/dataschema~DataSchemaDefinition#view} value
287
+ * as an event namespace, e.g. `register:span`.
288
+ *
289
+ * ```ts
290
+ * dataFilter.on( 'register', ( evt, definition ) => {
291
+ * editor.model.schema.register( definition.model, definition.modelSchema );
292
+ * editor.conversion.elementToElement( { model: definition.model, view: definition.view } );
293
+ *
294
+ * evt.stop();
295
+ * } );
296
+ *
297
+ * dataFilter.on( 'register:span', ( evt, definition ) => {
298
+ * editor.model.schema.extend( '$text', { allowAttributes: 'htmlSpan' } );
299
+ *
300
+ * editor.conversion.for( 'upcast' ).elementToAttribute( { view: 'span', model: 'htmlSpan' } );
301
+ * editor.conversion.for( 'downcast' ).attributeToElement( { view: 'span', model: 'htmlSpan' } );
302
+ *
303
+ * evt.stop();
304
+ * }, { priority: 'high' } )
305
+ * ```
306
+ *
307
+ * @eventName ~DataFilter#register
308
+ */
309
+ export interface DataFilterRegisterEvent {
310
+ name: 'register' | `register:${string}`;
311
+ args: [data: DataSchemaDefinition];
312
+ }
@@ -0,0 +1,191 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module html-support/dataschema
11
+ */
12
+ import { Plugin } from 'ckeditor5/src/core.js';
13
+ import type { AttributeProperties, SchemaItemDefinition } from 'ckeditor5/src/engine.js';
14
+ /**
15
+ * Holds representation of the extended HTML document type definitions to be used by the
16
+ * editor in HTML support.
17
+ *
18
+ * Data schema is represented by data schema definitions.
19
+ *
20
+ * To add new definition for block element,
21
+ * use {@link module:html-support/dataschema~DataSchema#registerBlockElement} method:
22
+ *
23
+ * ```ts
24
+ * dataSchema.registerBlockElement( {
25
+ * view: 'section',
26
+ * model: 'my-section',
27
+ * modelSchema: {
28
+ * inheritAllFrom: '$block'
29
+ * }
30
+ * } );
31
+ * ```
32
+ *
33
+ * To add new definition for inline element,
34
+ * use {@link module:html-support/dataschema~DataSchema#registerInlineElement} method:
35
+ *
36
+ * ```
37
+ * dataSchema.registerInlineElement( {
38
+ * view: 'span',
39
+ * model: 'my-span',
40
+ * attributeProperties: {
41
+ * copyOnEnter: true
42
+ * }
43
+ * } );
44
+ * ```
45
+ */
46
+ export default class DataSchema extends Plugin {
47
+ /**
48
+ * A map of registered data schema definitions.
49
+ */
50
+ private readonly _definitions;
51
+ /**
52
+ * @inheritDoc
53
+ */
54
+ static get pluginName(): "DataSchema";
55
+ /**
56
+ * @inheritDoc
57
+ */
58
+ static get isOfficialPlugin(): true;
59
+ /**
60
+ * @inheritDoc
61
+ */
62
+ init(): void;
63
+ /**
64
+ * Add new data schema definition describing block element.
65
+ */
66
+ registerBlockElement(definition: DataSchemaBlockElementDefinition): void;
67
+ /**
68
+ * Add new data schema definition describing inline element.
69
+ */
70
+ registerInlineElement(definition: DataSchemaInlineElementDefinition): void;
71
+ /**
72
+ * Updates schema definition describing block element with new properties.
73
+ *
74
+ * Creates new scheme if it doesn't exist.
75
+ * Array properties are concatenated with original values.
76
+ *
77
+ * @param definition Definition update.
78
+ */
79
+ extendBlockElement(definition: DataSchemaBlockElementDefinition): void;
80
+ /**
81
+ * Updates schema definition describing inline element with new properties.
82
+ *
83
+ * Creates new scheme if it doesn't exist.
84
+ * Array properties are concatenated with original values.
85
+ *
86
+ * @param definition Definition update.
87
+ */
88
+ extendInlineElement(definition: DataSchemaInlineElementDefinition): void;
89
+ /**
90
+ * Returns all definitions matching the given view name.
91
+ *
92
+ * @param includeReferences Indicates if this method should also include definitions of referenced models.
93
+ */
94
+ getDefinitionsForView(viewName: string | RegExp, includeReferences?: boolean): Set<DataSchemaDefinition>;
95
+ /**
96
+ * Returns definitions matching the given model name.
97
+ */
98
+ getDefinitionsForModel(modelName: string): Array<DataSchemaDefinition>;
99
+ /**
100
+ * Returns definitions matching the given view name.
101
+ */
102
+ private _getMatchingViewDefinitions;
103
+ /**
104
+ * Resolves all definition references registered for the given data schema definition.
105
+ *
106
+ * @param modelName Data schema model name.
107
+ */
108
+ private _getReferences;
109
+ /**
110
+ * Updates schema definition with new properties.
111
+ *
112
+ * Creates new scheme if it doesn't exist.
113
+ * Array properties are concatenated with original values.
114
+ *
115
+ * @param definition Definition update.
116
+ */
117
+ private _extendDefinition;
118
+ }
119
+ /**
120
+ * A base definition of {@link module:html-support/dataschema~DataSchema data schema}.
121
+ */
122
+ export interface DataSchemaDefinition {
123
+ /**
124
+ * Name of the model.
125
+ */
126
+ model: string;
127
+ /**
128
+ * Name of the view element.
129
+ */
130
+ view?: string;
131
+ /**
132
+ * Indicates that the definition describes object element.
133
+ */
134
+ isObject?: boolean;
135
+ /**
136
+ * The model schema item definition describing registered model.
137
+ */
138
+ modelSchema?: SchemaItemDefinition;
139
+ /**
140
+ * Indicates that the definition describes block element.
141
+ * Set by {@link module:html-support/dataschema~DataSchema#registerBlockElement} method.
142
+ */
143
+ isBlock?: boolean;
144
+ /**
145
+ * Indicates that the definition describes inline element.
146
+ */
147
+ isInline?: boolean;
148
+ }
149
+ /**
150
+ * A definition of {@link module:html-support/dataschema~DataSchema data schema} for block elements.
151
+ */
152
+ export interface DataSchemaBlockElementDefinition extends DataSchemaDefinition {
153
+ /**
154
+ * Should be used when an element can behave both as a sectioning element (e.g. article) and
155
+ * element accepting only inline content (e.g. paragraph).
156
+ * If an element contains only inline content, this option will be used as a model name.
157
+ */
158
+ paragraphLikeModel?: string;
159
+ }
160
+ /**
161
+ * A definition of {@link module:html-support/dataschema~DataSchema data schema} for inline elements.
162
+ */
163
+ export interface DataSchemaInlineElementDefinition extends DataSchemaDefinition {
164
+ /**
165
+ * Additional metadata describing the model attribute.
166
+ */
167
+ attributeProperties?: AttributeProperties;
168
+ /**
169
+ * Element priority. Decides in what order elements are wrapped by
170
+ * {@link module:engine/view/downcastwriter~DowncastWriter}.
171
+ * Set by {@link module:html-support/dataschema~DataSchema#registerInlineElement} method.
172
+ */
173
+ priority?: number;
174
+ /**
175
+ * The name of the model attribute that generates the same view element. GHS inline attribute
176
+ * will be removed from the model tree as soon as the coupled attribute is removed. See
177
+ * {@link module:html-support/datafilter~DataFilter#_registerCoupledAttributesPostFixer GHS post-fixer} for more details.
178
+ */
179
+ coupledAttribute?: string;
180
+ /**
181
+ * Indicates that element should not be converted as a model text attribute.
182
+ * It is used to map view elements that do not have a separate model element but their data is stored in a model attribute.
183
+ * For example `<tbody>` element does not have a dedicated model element and GHS stores attributes of `<tbody>`
184
+ * in the `htmlTbodyAttributes` model attribute of the `table` model element.
185
+ */
186
+ appliesToBlock?: boolean | string;
187
+ /**
188
+ * Indicates that an element should be preserved even if it has no content.
189
+ */
190
+ allowEmpty?: boolean;
191
+ }
@@ -0,0 +1,29 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module html-support/fullpage
11
+ */
12
+ import { Plugin } from 'ckeditor5/src/core.js';
13
+ /**
14
+ * The full page editing feature. It preserves the whole HTML page in the editor data.
15
+ */
16
+ export default class FullPage extends Plugin {
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ static get pluginName(): "FullPage";
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get isOfficialPlugin(): true;
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ init(): void;
29
+ }
@@ -0,0 +1,106 @@
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
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module html-support/generalhtmlsupport
11
+ */
12
+ import { Plugin } from 'ckeditor5/src/core.js';
13
+ import { type ArrayOrItem } from 'ckeditor5/src/utils.js';
14
+ import DataFilter from './datafilter.js';
15
+ import CodeBlockElementSupport from './integrations/codeblock.js';
16
+ import DualContentModelElementSupport from './integrations/dualcontent.js';
17
+ import HeadingElementSupport from './integrations/heading.js';
18
+ import ImageElementSupport from './integrations/image.js';
19
+ import MediaEmbedElementSupport from './integrations/mediaembed.js';
20
+ import ScriptElementSupport from './integrations/script.js';
21
+ import TableElementSupport from './integrations/table.js';
22
+ import StyleElementSupport from './integrations/style.js';
23
+ import ListElementSupport from './integrations/list.js';
24
+ import CustomElementSupport from './integrations/customelement.js';
25
+ import type { Selectable } from 'ckeditor5/src/engine.js';
26
+ /**
27
+ * The General HTML Support feature.
28
+ *
29
+ * This is a "glue" plugin which initializes the {@link module:html-support/datafilter~DataFilter data filter} configuration
30
+ * and features integration with the General HTML Support.
31
+ */
32
+ export default class GeneralHtmlSupport extends Plugin {
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ static get pluginName(): "GeneralHtmlSupport";
37
+ /**
38
+ * @inheritDoc
39
+ */
40
+ static get isOfficialPlugin(): true;
41
+ /**
42
+ * @inheritDoc
43
+ */
44
+ static get requires(): readonly [typeof DataFilter, typeof CodeBlockElementSupport, typeof DualContentModelElementSupport, typeof HeadingElementSupport, typeof ImageElementSupport, typeof MediaEmbedElementSupport, typeof ScriptElementSupport, typeof TableElementSupport, typeof StyleElementSupport, typeof ListElementSupport, typeof CustomElementSupport];
45
+ /**
46
+ * @inheritDoc
47
+ */
48
+ init(): void;
49
+ /**
50
+ * Returns a GHS model attribute name related to a given view element name.
51
+ *
52
+ * @internal
53
+ * @param viewElementName A view element name.
54
+ */
55
+ getGhsAttributeNameForElement(viewElementName: string): string;
56
+ /**
57
+ * Updates GHS model attribute for a specified view element name, so it includes the given class name.
58
+ *
59
+ * @internal
60
+ * @param viewElementName A view element name.
61
+ * @param className The css class to add.
62
+ * @param selectable The selection or element to update.
63
+ */
64
+ addModelHtmlClass(viewElementName: string, className: ArrayOrItem<string>, selectable: Selectable): void;
65
+ /**
66
+ * Updates GHS model attribute for a specified view element name, so it does not include the given class name.
67
+ *
68
+ * @internal
69
+ * @param viewElementName A view element name.
70
+ * @param className The css class to remove.
71
+ * @param selectable The selection or element to update.
72
+ */
73
+ removeModelHtmlClass(viewElementName: string, className: ArrayOrItem<string>, selectable: Selectable): void;
74
+ /**
75
+ * Updates GHS model attribute for a specified view element name, so it includes the given attribute.
76
+ *
77
+ * @param viewElementName A view element name.
78
+ * @param attributes The object with attributes to set.
79
+ * @param selectable The selection or element to update.
80
+ */
81
+ private setModelHtmlAttributes;
82
+ /**
83
+ * Updates GHS model attribute for a specified view element name, so it does not include the given attribute.
84
+ *
85
+ * @param viewElementName A view element name.
86
+ * @param attributeName The attribute name (or names) to remove.
87
+ * @param selectable The selection or element to update.
88
+ */
89
+ private removeModelHtmlAttributes;
90
+ /**
91
+ * Updates GHS model attribute for a specified view element name, so it includes a given style.
92
+ *
93
+ * @param viewElementName A view element name.
94
+ * @param styles The object with styles to set.
95
+ * @param selectable The selection or element to update.
96
+ */
97
+ private setModelHtmlStyles;
98
+ /**
99
+ * Updates GHS model attribute for a specified view element name, so it does not include a given style.
100
+ *
101
+ * @param viewElementName A view element name.
102
+ * @param properties The style (or styles list) to remove.
103
+ * @param selectable The selection or element to update.
104
+ */
105
+ private removeModelHtmlStyles;
106
+ }