@ckeditor/ckeditor5-link 41.3.1 → 41.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (345) hide show
  1. package/build/link.js +2 -2
  2. package/build/translations/ar.js +1 -1
  3. package/build/translations/ast.js +1 -1
  4. package/build/translations/az.js +1 -1
  5. package/build/translations/bg.js +1 -1
  6. package/build/translations/bn.js +1 -1
  7. package/build/translations/ca.js +1 -1
  8. package/build/translations/cs.js +1 -1
  9. package/build/translations/da.js +1 -1
  10. package/build/translations/de-ch.js +1 -1
  11. package/build/translations/de.js +1 -1
  12. package/build/translations/el.js +1 -1
  13. package/build/translations/en-au.js +1 -1
  14. package/build/translations/en-gb.js +1 -1
  15. package/build/translations/eo.js +1 -1
  16. package/build/translations/es.js +1 -1
  17. package/build/translations/et.js +1 -1
  18. package/build/translations/eu.js +1 -1
  19. package/build/translations/fa.js +1 -1
  20. package/build/translations/fi.js +1 -1
  21. package/build/translations/fr.js +1 -1
  22. package/build/translations/gl.js +1 -1
  23. package/build/translations/he.js +1 -1
  24. package/build/translations/hi.js +1 -1
  25. package/build/translations/hr.js +1 -1
  26. package/build/translations/hu.js +1 -1
  27. package/build/translations/hy.js +1 -1
  28. package/build/translations/id.js +1 -1
  29. package/build/translations/it.js +1 -1
  30. package/build/translations/ja.js +1 -1
  31. package/build/translations/km.js +1 -1
  32. package/build/translations/kn.js +1 -1
  33. package/build/translations/ko.js +1 -1
  34. package/build/translations/ku.js +1 -1
  35. package/build/translations/lt.js +1 -1
  36. package/build/translations/lv.js +1 -1
  37. package/build/translations/ms.js +1 -1
  38. package/build/translations/nb.js +1 -1
  39. package/build/translations/ne.js +1 -1
  40. package/build/translations/nl.js +1 -1
  41. package/build/translations/no.js +1 -1
  42. package/build/translations/pl.js +1 -1
  43. package/build/translations/pt-br.js +1 -1
  44. package/build/translations/pt.js +1 -1
  45. package/build/translations/ro.js +1 -1
  46. package/build/translations/ru.js +1 -1
  47. package/build/translations/sk.js +1 -1
  48. package/build/translations/sq.js +1 -1
  49. package/build/translations/sr-latn.js +1 -1
  50. package/build/translations/sr.js +1 -1
  51. package/build/translations/sv.js +1 -1
  52. package/build/translations/th.js +1 -1
  53. package/build/translations/ti.js +1 -0
  54. package/build/translations/tk.js +1 -1
  55. package/build/translations/tr.js +1 -1
  56. package/build/translations/tt.js +1 -1
  57. package/build/translations/ug.js +1 -1
  58. package/build/translations/uk.js +1 -1
  59. package/build/translations/ur.js +1 -1
  60. package/build/translations/uz.js +1 -1
  61. package/build/translations/vi.js +1 -1
  62. package/build/translations/zh-cn.js +1 -1
  63. package/build/translations/zh.js +1 -1
  64. package/dist/index-content.css +4 -0
  65. package/dist/index-editor.css +44 -0
  66. package/dist/index.css +148 -0
  67. package/dist/index.css.map +1 -0
  68. package/dist/index.js +2422 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/translations/ar.d.ts +8 -0
  71. package/dist/translations/ar.js +5 -0
  72. package/dist/translations/ar.umd.js +11 -0
  73. package/dist/translations/ast.d.ts +8 -0
  74. package/dist/translations/ast.js +5 -0
  75. package/dist/translations/ast.umd.js +11 -0
  76. package/dist/translations/az.d.ts +8 -0
  77. package/dist/translations/az.js +5 -0
  78. package/dist/translations/az.umd.js +11 -0
  79. package/dist/translations/bg.d.ts +8 -0
  80. package/dist/translations/bg.js +5 -0
  81. package/dist/translations/bg.umd.js +11 -0
  82. package/dist/translations/bn.d.ts +8 -0
  83. package/dist/translations/bn.js +5 -0
  84. package/dist/translations/bn.umd.js +11 -0
  85. package/dist/translations/ca.d.ts +8 -0
  86. package/dist/translations/ca.js +5 -0
  87. package/dist/translations/ca.umd.js +11 -0
  88. package/dist/translations/cs.d.ts +8 -0
  89. package/dist/translations/cs.js +5 -0
  90. package/dist/translations/cs.umd.js +11 -0
  91. package/dist/translations/da.d.ts +8 -0
  92. package/dist/translations/da.js +5 -0
  93. package/dist/translations/da.umd.js +11 -0
  94. package/dist/translations/de-ch.d.ts +8 -0
  95. package/dist/translations/de-ch.js +5 -0
  96. package/dist/translations/de-ch.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-gb.d.ts +8 -0
  107. package/dist/translations/en-gb.js +5 -0
  108. package/dist/translations/en-gb.umd.js +11 -0
  109. package/dist/translations/en.d.ts +8 -0
  110. package/dist/translations/en.js +5 -0
  111. package/dist/translations/en.umd.js +11 -0
  112. package/dist/translations/eo.d.ts +8 -0
  113. package/dist/translations/eo.js +5 -0
  114. package/dist/translations/eo.umd.js +11 -0
  115. package/dist/translations/es.d.ts +8 -0
  116. package/dist/translations/es.js +5 -0
  117. package/dist/translations/es.umd.js +11 -0
  118. package/dist/translations/et.d.ts +8 -0
  119. package/dist/translations/et.js +5 -0
  120. package/dist/translations/et.umd.js +11 -0
  121. package/dist/translations/eu.d.ts +8 -0
  122. package/dist/translations/eu.js +5 -0
  123. package/dist/translations/eu.umd.js +11 -0
  124. package/dist/translations/fa.d.ts +8 -0
  125. package/dist/translations/fa.js +5 -0
  126. package/dist/translations/fa.umd.js +11 -0
  127. package/dist/translations/fi.d.ts +8 -0
  128. package/dist/translations/fi.js +5 -0
  129. package/dist/translations/fi.umd.js +11 -0
  130. package/dist/translations/fr.d.ts +8 -0
  131. package/dist/translations/fr.js +5 -0
  132. package/dist/translations/fr.umd.js +11 -0
  133. package/dist/translations/gl.d.ts +8 -0
  134. package/dist/translations/gl.js +5 -0
  135. package/dist/translations/gl.umd.js +11 -0
  136. package/dist/translations/he.d.ts +8 -0
  137. package/dist/translations/he.js +5 -0
  138. package/dist/translations/he.umd.js +11 -0
  139. package/dist/translations/hi.d.ts +8 -0
  140. package/dist/translations/hi.js +5 -0
  141. package/dist/translations/hi.umd.js +11 -0
  142. package/dist/translations/hr.d.ts +8 -0
  143. package/dist/translations/hr.js +5 -0
  144. package/dist/translations/hr.umd.js +11 -0
  145. package/dist/translations/hu.d.ts +8 -0
  146. package/dist/translations/hu.js +5 -0
  147. package/dist/translations/hu.umd.js +11 -0
  148. package/dist/translations/hy.d.ts +8 -0
  149. package/dist/translations/hy.js +5 -0
  150. package/dist/translations/hy.umd.js +11 -0
  151. package/dist/translations/id.d.ts +8 -0
  152. package/dist/translations/id.js +5 -0
  153. package/dist/translations/id.umd.js +11 -0
  154. package/dist/translations/it.d.ts +8 -0
  155. package/dist/translations/it.js +5 -0
  156. package/dist/translations/it.umd.js +11 -0
  157. package/dist/translations/ja.d.ts +8 -0
  158. package/dist/translations/ja.js +5 -0
  159. package/dist/translations/ja.umd.js +11 -0
  160. package/dist/translations/km.d.ts +8 -0
  161. package/dist/translations/km.js +5 -0
  162. package/dist/translations/km.umd.js +11 -0
  163. package/dist/translations/kn.d.ts +8 -0
  164. package/dist/translations/kn.js +5 -0
  165. package/dist/translations/kn.umd.js +11 -0
  166. package/dist/translations/ko.d.ts +8 -0
  167. package/dist/translations/ko.js +5 -0
  168. package/dist/translations/ko.umd.js +11 -0
  169. package/dist/translations/ku.d.ts +8 -0
  170. package/dist/translations/ku.js +5 -0
  171. package/dist/translations/ku.umd.js +11 -0
  172. package/dist/translations/lt.d.ts +8 -0
  173. package/dist/translations/lt.js +5 -0
  174. package/dist/translations/lt.umd.js +11 -0
  175. package/dist/translations/lv.d.ts +8 -0
  176. package/dist/translations/lv.js +5 -0
  177. package/dist/translations/lv.umd.js +11 -0
  178. package/dist/translations/ms.d.ts +8 -0
  179. package/dist/translations/ms.js +5 -0
  180. package/dist/translations/ms.umd.js +11 -0
  181. package/dist/translations/nb.d.ts +8 -0
  182. package/dist/translations/nb.js +5 -0
  183. package/dist/translations/nb.umd.js +11 -0
  184. package/dist/translations/ne.d.ts +8 -0
  185. package/dist/translations/ne.js +5 -0
  186. package/dist/translations/ne.umd.js +11 -0
  187. package/dist/translations/nl.d.ts +8 -0
  188. package/dist/translations/nl.js +5 -0
  189. package/dist/translations/nl.umd.js +11 -0
  190. package/dist/translations/no.d.ts +8 -0
  191. package/dist/translations/no.js +5 -0
  192. package/dist/translations/no.umd.js +11 -0
  193. package/dist/translations/pl.d.ts +8 -0
  194. package/dist/translations/pl.js +5 -0
  195. package/dist/translations/pl.umd.js +11 -0
  196. package/dist/translations/pt-br.d.ts +8 -0
  197. package/dist/translations/pt-br.js +5 -0
  198. package/dist/translations/pt-br.umd.js +11 -0
  199. package/dist/translations/pt.d.ts +8 -0
  200. package/dist/translations/pt.js +5 -0
  201. package/dist/translations/pt.umd.js +11 -0
  202. package/dist/translations/ro.d.ts +8 -0
  203. package/dist/translations/ro.js +5 -0
  204. package/dist/translations/ro.umd.js +11 -0
  205. package/dist/translations/ru.d.ts +8 -0
  206. package/dist/translations/ru.js +5 -0
  207. package/dist/translations/ru.umd.js +11 -0
  208. package/dist/translations/sk.d.ts +8 -0
  209. package/dist/translations/sk.js +5 -0
  210. package/dist/translations/sk.umd.js +11 -0
  211. package/dist/translations/sq.d.ts +8 -0
  212. package/dist/translations/sq.js +5 -0
  213. package/dist/translations/sq.umd.js +11 -0
  214. package/dist/translations/sr-latn.d.ts +8 -0
  215. package/dist/translations/sr-latn.js +5 -0
  216. package/dist/translations/sr-latn.umd.js +11 -0
  217. package/dist/translations/sr.d.ts +8 -0
  218. package/dist/translations/sr.js +5 -0
  219. package/dist/translations/sr.umd.js +11 -0
  220. package/dist/translations/sv.d.ts +8 -0
  221. package/dist/translations/sv.js +5 -0
  222. package/dist/translations/sv.umd.js +11 -0
  223. package/dist/translations/th.d.ts +8 -0
  224. package/dist/translations/th.js +5 -0
  225. package/dist/translations/th.umd.js +11 -0
  226. package/dist/translations/ti.d.ts +8 -0
  227. package/dist/translations/ti.js +5 -0
  228. package/dist/translations/ti.umd.js +11 -0
  229. package/dist/translations/tk.d.ts +8 -0
  230. package/dist/translations/tk.js +5 -0
  231. package/dist/translations/tk.umd.js +11 -0
  232. package/dist/translations/tr.d.ts +8 -0
  233. package/dist/translations/tr.js +5 -0
  234. package/dist/translations/tr.umd.js +11 -0
  235. package/dist/translations/tt.d.ts +8 -0
  236. package/dist/translations/tt.js +5 -0
  237. package/dist/translations/tt.umd.js +11 -0
  238. package/dist/translations/ug.d.ts +8 -0
  239. package/dist/translations/ug.js +5 -0
  240. package/dist/translations/ug.umd.js +11 -0
  241. package/dist/translations/uk.d.ts +8 -0
  242. package/dist/translations/uk.js +5 -0
  243. package/dist/translations/uk.umd.js +11 -0
  244. package/dist/translations/ur.d.ts +8 -0
  245. package/dist/translations/ur.js +5 -0
  246. package/dist/translations/ur.umd.js +11 -0
  247. package/dist/translations/uz.d.ts +8 -0
  248. package/dist/translations/uz.js +5 -0
  249. package/dist/translations/uz.umd.js +11 -0
  250. package/dist/translations/vi.d.ts +8 -0
  251. package/dist/translations/vi.js +5 -0
  252. package/dist/translations/vi.umd.js +11 -0
  253. package/dist/translations/zh-cn.d.ts +8 -0
  254. package/dist/translations/zh-cn.js +5 -0
  255. package/dist/translations/zh-cn.umd.js +11 -0
  256. package/dist/translations/zh.d.ts +8 -0
  257. package/dist/translations/zh.js +5 -0
  258. package/dist/translations/zh.umd.js +11 -0
  259. package/dist/types/augmentation.d.ts +34 -0
  260. package/dist/types/autolink.d.ts +79 -0
  261. package/dist/types/index.d.ts +22 -0
  262. package/dist/types/link.d.ts +31 -0
  263. package/dist/types/linkcommand.d.ts +136 -0
  264. package/dist/types/linkconfig.d.ts +294 -0
  265. package/dist/types/linkediting.d.ts +74 -0
  266. package/dist/types/linkimage.d.ts +31 -0
  267. package/dist/types/linkimageediting.d.ts +43 -0
  268. package/dist/types/linkimageui.d.ts +44 -0
  269. package/dist/types/linkui.d.ts +173 -0
  270. package/dist/types/ui/linkactionsview.d.ts +107 -0
  271. package/dist/types/ui/linkformview.d.ts +175 -0
  272. package/dist/types/unlinkcommand.d.ts +35 -0
  273. package/dist/types/utils/automaticdecorators.d.ts +49 -0
  274. package/dist/types/utils/manualdecorator.d.ts +76 -0
  275. package/dist/types/utils.d.ts +84 -0
  276. package/lang/contexts.json +1 -0
  277. package/lang/translations/ar.po +4 -0
  278. package/lang/translations/ast.po +4 -0
  279. package/lang/translations/az.po +4 -0
  280. package/lang/translations/bg.po +4 -0
  281. package/lang/translations/bn.po +4 -0
  282. package/lang/translations/ca.po +4 -0
  283. package/lang/translations/cs.po +4 -0
  284. package/lang/translations/da.po +4 -0
  285. package/lang/translations/de-ch.po +4 -0
  286. package/lang/translations/de.po +4 -0
  287. package/lang/translations/el.po +4 -0
  288. package/lang/translations/en-au.po +4 -0
  289. package/lang/translations/en-gb.po +4 -0
  290. package/lang/translations/en.po +4 -0
  291. package/lang/translations/eo.po +4 -0
  292. package/lang/translations/es.po +4 -0
  293. package/lang/translations/et.po +4 -0
  294. package/lang/translations/eu.po +4 -0
  295. package/lang/translations/fa.po +4 -0
  296. package/lang/translations/fi.po +4 -0
  297. package/lang/translations/fr.po +4 -0
  298. package/lang/translations/gl.po +4 -0
  299. package/lang/translations/he.po +4 -0
  300. package/lang/translations/hi.po +4 -0
  301. package/lang/translations/hr.po +4 -0
  302. package/lang/translations/hu.po +4 -0
  303. package/lang/translations/hy.po +4 -0
  304. package/lang/translations/id.po +4 -0
  305. package/lang/translations/it.po +4 -0
  306. package/lang/translations/ja.po +4 -0
  307. package/lang/translations/km.po +4 -0
  308. package/lang/translations/kn.po +4 -0
  309. package/lang/translations/ko.po +4 -0
  310. package/lang/translations/ku.po +4 -0
  311. package/lang/translations/lt.po +4 -0
  312. package/lang/translations/lv.po +4 -0
  313. package/lang/translations/ms.po +4 -0
  314. package/lang/translations/nb.po +4 -0
  315. package/lang/translations/ne.po +4 -0
  316. package/lang/translations/nl.po +4 -0
  317. package/lang/translations/no.po +4 -0
  318. package/lang/translations/pl.po +4 -0
  319. package/lang/translations/pt-br.po +4 -0
  320. package/lang/translations/pt.po +4 -0
  321. package/lang/translations/ro.po +4 -0
  322. package/lang/translations/ru.po +4 -0
  323. package/lang/translations/sk.po +4 -0
  324. package/lang/translations/sq.po +4 -0
  325. package/lang/translations/sr-latn.po +4 -0
  326. package/lang/translations/sr.po +4 -0
  327. package/lang/translations/sv.po +4 -0
  328. package/lang/translations/th.po +4 -0
  329. package/lang/translations/ti.po +66 -0
  330. package/lang/translations/tk.po +4 -0
  331. package/lang/translations/tr.po +4 -0
  332. package/lang/translations/tt.po +4 -0
  333. package/lang/translations/ug.po +4 -0
  334. package/lang/translations/uk.po +4 -0
  335. package/lang/translations/ur.po +4 -0
  336. package/lang/translations/uz.po +4 -0
  337. package/lang/translations/vi.po +4 -0
  338. package/lang/translations/zh-cn.po +4 -0
  339. package/lang/translations/zh.po +4 -0
  340. package/package.json +4 -3
  341. package/src/index.d.ts +1 -1
  342. package/src/linkui.js +30 -8
  343. package/src/ui/linkformview.d.ts +31 -1
  344. package/src/ui/linkformview.js +41 -1
  345. package/theme/linkform.css +1 -0
@@ -29,6 +29,10 @@ msgctxt "Label for the URL input in the Link URL editing balloon."
29
29
  msgid "Link URL"
30
30
  msgstr "Đường dẫn liên kết"
31
31
 
32
+ msgctxt "An error text displayed when user attempted to enter an empty URL."
33
+ msgid "Link URL must not be empty."
34
+ msgstr "Không được để trống URL đường liên kết."
35
+
32
36
  msgctxt "Label for the image link button."
33
37
  msgid "Link image"
34
38
  msgstr "Liên kết của ảnh"
@@ -29,6 +29,10 @@ msgctxt "Label for the URL input in the Link URL editing balloon."
29
29
  msgid "Link URL"
30
30
  msgstr "链接网址"
31
31
 
32
+ msgctxt "An error text displayed when user attempted to enter an empty URL."
33
+ msgid "Link URL must not be empty."
34
+ msgstr "链接 URL 不能为空。"
35
+
32
36
  msgctxt "Label for the image link button."
33
37
  msgid "Link image"
34
38
  msgstr "链接图片"
@@ -29,6 +29,10 @@ msgctxt "Label for the URL input in the Link URL editing balloon."
29
29
  msgid "Link URL"
30
30
  msgstr "連結˙ URL"
31
31
 
32
+ msgctxt "An error text displayed when user attempted to enter an empty URL."
33
+ msgid "Link URL must not be empty."
34
+ msgstr "連結 URL 不得為空白。"
35
+
32
36
  msgctxt "Label for the image link button."
33
37
  msgid "Link image"
34
38
  msgstr "圖片連結"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ckeditor/ckeditor5-link",
3
- "version": "41.3.1",
3
+ "version": "41.4.0",
4
4
  "description": "Link feature for CKEditor 5.",
5
5
  "keywords": [
6
6
  "ckeditor",
@@ -13,8 +13,8 @@
13
13
  "type": "module",
14
14
  "main": "src/index.js",
15
15
  "dependencies": {
16
- "@ckeditor/ckeditor5-ui": "41.3.1",
17
- "ckeditor5": "41.3.1",
16
+ "@ckeditor/ckeditor5-ui": "41.4.0",
17
+ "ckeditor5": "41.4.0",
18
18
  "lodash-es": "4.17.21"
19
19
  },
20
20
  "author": "CKSource (http://cksource.com/)",
@@ -27,6 +27,7 @@
27
27
  "directory": "packages/ckeditor5-link"
28
28
  },
29
29
  "files": [
30
+ "dist",
30
31
  "lang",
31
32
  "src/**/*.js",
32
33
  "src/**/*.d.ts",
package/src/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export { default as LinkImage } from './linkimage.js';
12
12
  export { default as LinkImageEditing } from './linkimageediting.js';
13
13
  export { default as LinkImageUI } from './linkimageui.js';
14
14
  export { default as AutoLink } from './autolink.js';
15
- export { LinkConfig, type LinkDecoratorDefinition } from './linkconfig.js';
15
+ export type { LinkConfig, LinkDecoratorDefinition } from './linkconfig.js';
16
16
  export { default as LinkCommand } from './linkcommand.js';
17
17
  export { default as UnlinkCommand } from './unlinkcommand.js';
18
18
  import './augmentation.js';
package/src/linkui.js CHANGED
@@ -148,19 +148,24 @@ export default class LinkUI extends Plugin {
148
148
  const editor = this.editor;
149
149
  const linkCommand = editor.commands.get('link');
150
150
  const defaultProtocol = editor.config.get('link.defaultProtocol');
151
- const allowCreatingEmptyLinks = editor.config.get('link.allowCreatingEmptyLinks');
152
- const formView = new (CssTransitionDisablerMixin(LinkFormView))(editor.locale, linkCommand);
151
+ const formView = new (CssTransitionDisablerMixin(LinkFormView))(editor.locale, linkCommand, getFormValidators(editor));
153
152
  formView.urlInputView.fieldView.bind('value').to(linkCommand, 'value');
154
153
  // Form elements should be read-only when corresponding commands are disabled.
155
154
  formView.urlInputView.bind('isEnabled').to(linkCommand, 'isEnabled');
156
- // Disable the "save" button if the command is disabled or the input is empty despite being required.
157
- formView.saveButtonView.bind('isEnabled').to(linkCommand, 'isEnabled', formView.urlInputView, 'isEmpty', (isCommandEnabled, isInputEmpty) => isCommandEnabled && (allowCreatingEmptyLinks || !isInputEmpty));
155
+ // Disable the "save" button if the command is disabled.
156
+ formView.saveButtonView.bind('isEnabled').to(linkCommand, 'isEnabled');
158
157
  // Execute link command after clicking the "Save" button.
159
158
  this.listenTo(formView, 'submit', () => {
160
- const { value } = formView.urlInputView.fieldView.element;
161
- const parsedUrl = addLinkProtocolIfApplicable(value, defaultProtocol);
162
- editor.execute('link', parsedUrl, formView.getDecoratorSwitchesState());
163
- this._closeFormView();
159
+ if (formView.isValid()) {
160
+ const { value } = formView.urlInputView.fieldView.element;
161
+ const parsedUrl = addLinkProtocolIfApplicable(value, defaultProtocol);
162
+ editor.execute('link', parsedUrl, formView.getDecoratorSwitchesState());
163
+ this._closeFormView();
164
+ }
165
+ });
166
+ // Update balloon position when form error changes.
167
+ this.listenTo(formView.urlInputView, 'change:errorText', () => {
168
+ editor.ui.update();
164
169
  });
165
170
  // Hide the panel after clicking the "Cancel" button.
166
171
  this.listenTo(formView, 'cancel', () => {
@@ -299,6 +304,7 @@ export default class LinkUI extends Plugin {
299
304
  const editor = this.editor;
300
305
  const linkCommand = editor.commands.get('link');
301
306
  this.formView.disableCssTransitions();
307
+ this.formView.resetFormStatus();
302
308
  this._balloon.add({
303
309
  view: this.formView,
304
310
  position: this._getBalloonPositionData()
@@ -615,3 +621,19 @@ export default class LinkUI extends Plugin {
615
621
  function findLinkElementAncestor(position) {
616
622
  return position.getAncestors().find((ancestor) => isLinkElement(ancestor)) || null;
617
623
  }
624
+ /**
625
+ * Returns link form validation callbacks.
626
+ *
627
+ * @param editor Editor instance.
628
+ */
629
+ function getFormValidators(editor) {
630
+ const t = editor.t;
631
+ const allowCreatingEmptyLinks = editor.config.get('link.allowCreatingEmptyLinks');
632
+ return [
633
+ form => {
634
+ if (!allowCreatingEmptyLinks && !form.url.length) {
635
+ return t('Link URL must not be empty.');
636
+ }
637
+ }
638
+ ];
639
+ }
@@ -46,6 +46,10 @@ export default class LinkFormView extends View {
46
46
  * A collection of child views in the form.
47
47
  */
48
48
  readonly children: ViewCollection;
49
+ /**
50
+ * An array of form validators used by {@link #isValid}.
51
+ */
52
+ private readonly _validators;
49
53
  /**
50
54
  * A collection of views that can be focused in the form.
51
55
  */
@@ -61,8 +65,9 @@ export default class LinkFormView extends View {
61
65
  *
62
66
  * @param locale The localization services instance.
63
67
  * @param linkCommand Reference to {@link module:link/linkcommand~LinkCommand}.
68
+ * @param validators Form validators used by {@link #isValid}.
64
69
  */
65
- constructor(locale: Locale, linkCommand: LinkCommand);
70
+ constructor(locale: Locale, linkCommand: LinkCommand, validators: Array<LinkFormValidatorCallback>);
66
71
  /**
67
72
  * Obtains the state of the {@link module:ui/button/switchbuttonview~SwitchButtonView switch buttons} representing
68
73
  * {@link module:link/linkcommand~LinkCommand#manualDecorators manual link decorators}
@@ -83,6 +88,17 @@ export default class LinkFormView extends View {
83
88
  * Focuses the fist {@link #_focusables} in the form.
84
89
  */
85
90
  focus(): void;
91
+ /**
92
+ * Validates the form and returns `false` when some fields are invalid.
93
+ */
94
+ isValid(): boolean;
95
+ /**
96
+ * Cleans up the supplementary error and information text of the {@link #urlInputView}
97
+ * bringing them back to the state when the form has been displayed for the first time.
98
+ *
99
+ * See {@link #isValid}.
100
+ */
101
+ resetFormStatus(): void;
86
102
  /**
87
103
  * Creates a labeled input view.
88
104
  *
@@ -119,7 +135,21 @@ export default class LinkFormView extends View {
119
135
  * @returns The children of link form view.
120
136
  */
121
137
  private _createFormChildren;
138
+ /**
139
+ * The native DOM `value` of the {@link #urlInputView} element.
140
+ *
141
+ * **Note**: Do not confuse it with the {@link module:ui/inputtext/inputtextview~InputTextView#value}
142
+ * which works one way only and may not represent the actual state of the component in the DOM.
143
+ */
144
+ get url(): string | null;
122
145
  }
146
+ /**
147
+ * Callback used by {@link ~LinkFormView} to check if passed form value is valid.
148
+ *
149
+ * * If `undefined` is returned, it is assumed that the form value is correct and there is no error.
150
+ * * If string is returned, it is assumed that the form value is incorrect and the returned string is displayed in the error label
151
+ */
152
+ export type LinkFormValidatorCallback = (form: LinkFormView) => string | undefined;
123
153
  /**
124
154
  * Fired when the form view is submitted (when one of the children triggered the submit event),
125
155
  * for example with a click on {@link ~LinkFormView#saveButtonView}.
@@ -25,8 +25,9 @@ export default class LinkFormView extends View {
25
25
  *
26
26
  * @param locale The localization services instance.
27
27
  * @param linkCommand Reference to {@link module:link/linkcommand~LinkCommand}.
28
+ * @param validators Form validators used by {@link #isValid}.
28
29
  */
29
- constructor(locale, linkCommand) {
30
+ constructor(locale, linkCommand, validators) {
30
31
  super(locale);
31
32
  /**
32
33
  * Tracks information about DOM focus in the form.
@@ -41,6 +42,7 @@ export default class LinkFormView extends View {
41
42
  */
42
43
  this._focusables = new ViewCollection();
43
44
  const t = locale.t;
45
+ this._validators = validators;
44
46
  this.urlInputView = this._createUrlInput();
45
47
  this.saveButtonView = this._createButton(t('Save'), icons.check, 'ck-button-save');
46
48
  this.saveButtonView.type = 'submit';
@@ -124,6 +126,31 @@ export default class LinkFormView extends View {
124
126
  focus() {
125
127
  this._focusCycler.focusFirst();
126
128
  }
129
+ /**
130
+ * Validates the form and returns `false` when some fields are invalid.
131
+ */
132
+ isValid() {
133
+ this.resetFormStatus();
134
+ for (const validator of this._validators) {
135
+ const errorText = validator(this);
136
+ // One error per field is enough.
137
+ if (errorText) {
138
+ // Apply updated error.
139
+ this.urlInputView.errorText = errorText;
140
+ return false;
141
+ }
142
+ }
143
+ return true;
144
+ }
145
+ /**
146
+ * Cleans up the supplementary error and information text of the {@link #urlInputView}
147
+ * bringing them back to the state when the form has been displayed for the first time.
148
+ *
149
+ * See {@link #isValid}.
150
+ */
151
+ resetFormStatus() {
152
+ this.urlInputView.errorText = null;
153
+ }
127
154
  /**
128
155
  * Creates a labeled input view.
129
156
  *
@@ -229,4 +256,17 @@ export default class LinkFormView extends View {
229
256
  children.add(this.cancelButtonView);
230
257
  return children;
231
258
  }
259
+ /**
260
+ * The native DOM `value` of the {@link #urlInputView} element.
261
+ *
262
+ * **Note**: Do not confuse it with the {@link module:ui/inputtext/inputtextview~InputTextView#value}
263
+ * which works one way only and may not represent the actual state of the component in the DOM.
264
+ */
265
+ get url() {
266
+ const { element } = this.urlInputView.fieldView;
267
+ if (!element) {
268
+ return null;
269
+ }
270
+ return element.value.trim();
271
+ }
232
272
  }
@@ -7,6 +7,7 @@
7
7
 
8
8
  .ck.ck-link-form {
9
9
  display: flex;
10
+ align-items: flex-start;
10
11
 
11
12
  & .ck-label {
12
13
  display: none;