suneditor 2.46.1 → 3.0.0-alpha.1

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 (290) hide show
  1. package/.eslintignore +7 -0
  2. package/.eslintrc.json +64 -0
  3. package/CONTRIBUTING.md +36 -0
  4. package/LICENSE.txt +1 -1
  5. package/README.md +174 -805
  6. package/dist/suneditor.min.css +1 -0
  7. package/dist/suneditor.min.js +1 -2
  8. package/package.json +96 -70
  9. package/src/assets/icons/_default.js +194 -0
  10. package/src/assets/suneditor-content.css +646 -0
  11. package/src/assets/suneditor.css +3378 -0
  12. package/src/core/base/eventHandlers/handler_toolbar.js +114 -0
  13. package/src/core/base/eventHandlers/handler_ww_clipboard.js +31 -0
  14. package/src/core/base/eventHandlers/handler_ww_dragDrop.js +69 -0
  15. package/src/core/base/eventHandlers/handler_ww_key_input.js +975 -0
  16. package/src/core/base/eventHandlers/handler_ww_mouse.js +118 -0
  17. package/src/core/base/eventManager.js +1115 -0
  18. package/src/core/base/events.js +320 -0
  19. package/src/core/base/history.js +301 -0
  20. package/src/core/class/char.js +146 -0
  21. package/src/core/class/component.js +627 -0
  22. package/src/core/class/format.js +3255 -0
  23. package/src/core/class/html.js +1621 -0
  24. package/src/core/class/menu.js +260 -0
  25. package/src/core/class/nodeTransform.js +379 -0
  26. package/src/core/class/notice.js +42 -0
  27. package/src/core/class/offset.js +578 -0
  28. package/src/core/class/selection.js +508 -0
  29. package/src/core/class/shortcuts.js +38 -0
  30. package/src/core/class/toolbar.js +440 -0
  31. package/src/core/class/viewer.js +646 -0
  32. package/src/core/editor.js +1593 -0
  33. package/src/core/section/actives.js +107 -0
  34. package/src/core/section/constructor.js +1237 -0
  35. package/src/core/section/context.js +97 -0
  36. package/src/editorInjector/_classes.js +22 -0
  37. package/src/editorInjector/_core.js +28 -0
  38. package/src/editorInjector/index.js +13 -0
  39. package/src/helper/converter.js +313 -0
  40. package/src/helper/domUtils.js +1177 -0
  41. package/src/helper/env.js +250 -0
  42. package/src/helper/index.js +19 -0
  43. package/src/helper/numbers.js +68 -0
  44. package/src/helper/unicode.js +43 -0
  45. package/src/langs/ckb.js +161 -0
  46. package/src/langs/cs.js +161 -0
  47. package/src/langs/da.js +161 -0
  48. package/src/langs/de.js +162 -0
  49. package/src/langs/en.js +199 -0
  50. package/src/langs/es.js +162 -0
  51. package/src/langs/fa.js +159 -0
  52. package/src/langs/fr.js +161 -0
  53. package/src/langs/he.js +162 -0
  54. package/src/{lang → langs}/index.js +0 -2
  55. package/src/langs/it.js +162 -0
  56. package/src/langs/ja.js +162 -0
  57. package/src/langs/ko.js +162 -0
  58. package/src/langs/lv.js +162 -0
  59. package/src/langs/nl.js +162 -0
  60. package/src/langs/pl.js +162 -0
  61. package/src/langs/pt_br.js +162 -0
  62. package/src/langs/ro.js +162 -0
  63. package/src/langs/ru.js +162 -0
  64. package/src/langs/se.js +162 -0
  65. package/src/langs/tr.js +159 -0
  66. package/src/langs/ua.js +162 -0
  67. package/src/langs/ur.js +162 -0
  68. package/src/langs/zh_cn.js +162 -0
  69. package/src/modules/ApiManager.js +168 -0
  70. package/src/modules/ColorPicker.js +302 -0
  71. package/src/modules/Controller.js +315 -0
  72. package/src/modules/Figure.js +1160 -0
  73. package/src/modules/FileBrowser.js +271 -0
  74. package/src/modules/FileManager.js +290 -0
  75. package/src/modules/HueSlider.js +513 -0
  76. package/src/modules/Modal.js +177 -0
  77. package/src/modules/ModalAnchorEditor.js +494 -0
  78. package/src/modules/SelectMenu.js +447 -0
  79. package/src/modules/_DragHandle.js +16 -0
  80. package/src/modules/index.js +14 -0
  81. package/src/plugins/command/blockquote.js +47 -47
  82. package/src/plugins/command/exportPdf.js +168 -0
  83. package/src/plugins/command/fileUpload.js +389 -0
  84. package/src/plugins/command/list_bulleted.js +112 -0
  85. package/src/plugins/command/list_numbered.js +115 -0
  86. package/src/plugins/dropdown/align.js +143 -0
  87. package/src/plugins/dropdown/backgroundColor.js +73 -0
  88. package/src/plugins/dropdown/font.js +113 -0
  89. package/src/plugins/dropdown/fontColor.js +73 -0
  90. package/src/plugins/dropdown/formatBlock.js +141 -0
  91. package/src/plugins/dropdown/hr.js +111 -0
  92. package/src/plugins/dropdown/layout.js +72 -0
  93. package/src/plugins/dropdown/lineHeight.js +114 -0
  94. package/src/plugins/dropdown/list.js +107 -0
  95. package/src/plugins/dropdown/paragraphStyle.js +117 -0
  96. package/src/plugins/dropdown/table.js +2810 -0
  97. package/src/plugins/dropdown/template.js +71 -0
  98. package/src/plugins/dropdown/textStyle.js +137 -0
  99. package/src/plugins/field/mention.js +172 -0
  100. package/src/plugins/fileBrowser/imageGallery.js +76 -59
  101. package/src/plugins/index.js +86 -24
  102. package/src/plugins/input/fontSize.js +357 -0
  103. package/src/plugins/modal/audio.js +510 -0
  104. package/src/plugins/modal/image.js +1062 -0
  105. package/src/plugins/modal/link.js +211 -0
  106. package/src/plugins/modal/math.js +347 -0
  107. package/src/plugins/modal/video.js +870 -0
  108. package/src/suneditor.js +62 -67
  109. package/src/themes/test.css +61 -0
  110. package/typings/CommandPlugin.d.ts +8 -0
  111. package/typings/DialogPlugin.d.ts +20 -0
  112. package/typings/FileBrowserPlugin.d.ts +30 -0
  113. package/typings/Lang.d.ts +124 -0
  114. package/typings/Module.d.ts +15 -0
  115. package/typings/Plugin.d.ts +42 -0
  116. package/typings/SubmenuPlugin.d.ts +8 -0
  117. package/typings/_classes.d.ts +17 -0
  118. package/typings/_colorPicker.d.ts +60 -0
  119. package/typings/_core.d.ts +55 -0
  120. package/typings/align.d.ts +5 -0
  121. package/{src/plugins/dialog → typings}/audio.d.ts +1 -1
  122. package/typings/backgroundColor.d.ts +5 -0
  123. package/{src/plugins/command → typings}/blockquote.d.ts +1 -1
  124. package/typings/char.d.ts +39 -0
  125. package/typings/component.d.ts +38 -0
  126. package/typings/context.d.ts +39 -0
  127. package/typings/converter.d.ts +33 -0
  128. package/typings/dialog.d.ts +28 -0
  129. package/typings/domUtils.d.ts +361 -0
  130. package/typings/editor.d.ts +7 -0
  131. package/typings/editor.ts +542 -0
  132. package/typings/env.d.ts +70 -0
  133. package/typings/eventManager.d.ts +37 -0
  134. package/typings/events.d.ts +262 -0
  135. package/typings/fileBrowser.d.ts +42 -0
  136. package/typings/fileManager.d.ts +67 -0
  137. package/typings/font.d.ts +5 -0
  138. package/typings/fontColor.d.ts +5 -0
  139. package/typings/fontSize.d.ts +5 -0
  140. package/typings/format.d.ts +191 -0
  141. package/typings/formatBlock.d.ts +5 -0
  142. package/typings/history.d.ts +48 -0
  143. package/typings/horizontalRule.d.ts +5 -0
  144. package/{src/plugins/dialog → typings}/image.d.ts +1 -1
  145. package/{src/plugins/fileBrowser → typings}/imageGallery.d.ts +1 -1
  146. package/typings/index.d.ts +21 -0
  147. package/{src/plugins/modules/index.d.ts → typings/index.modules.d.ts} +3 -3
  148. package/typings/index.plugins.d.ts +58 -0
  149. package/typings/lineHeight.d.ts +5 -0
  150. package/{src/plugins/dialog → typings}/link.d.ts +1 -1
  151. package/typings/list.d.ts +5 -0
  152. package/{src/plugins/dialog → typings}/math.d.ts +1 -1
  153. package/typings/mediaContainer.d.ts +25 -0
  154. package/typings/node.d.ts +57 -0
  155. package/typings/notice.d.ts +16 -0
  156. package/typings/numbers.d.ts +29 -0
  157. package/typings/offset.d.ts +24 -0
  158. package/typings/options.d.ts +589 -0
  159. package/typings/paragraphStyle.d.ts +5 -0
  160. package/typings/resizing.d.ts +141 -0
  161. package/typings/selection.d.ts +94 -0
  162. package/typings/shortcuts.d.ts +13 -0
  163. package/typings/suneditor.d.ts +9 -0
  164. package/typings/table.d.ts +5 -0
  165. package/typings/template.d.ts +5 -0
  166. package/typings/textStyle.d.ts +5 -0
  167. package/typings/toolbar.d.ts +32 -0
  168. package/typings/unicode.d.ts +25 -0
  169. package/{src/plugins/dialog → typings}/video.d.ts +1 -1
  170. package/dist/css/suneditor.min.css +0 -1
  171. package/src/assets/css/suneditor-contents.css +0 -562
  172. package/src/assets/css/suneditor.css +0 -566
  173. package/src/assets/defaultIcons.js +0 -103
  174. package/src/lang/Lang.d.ts +0 -144
  175. package/src/lang/ckb.d.ts +0 -5
  176. package/src/lang/ckb.js +0 -188
  177. package/src/lang/cs.d.ts +0 -5
  178. package/src/lang/cs.js +0 -188
  179. package/src/lang/da.d.ts +0 -5
  180. package/src/lang/da.js +0 -191
  181. package/src/lang/de.d.ts +0 -5
  182. package/src/lang/de.js +0 -188
  183. package/src/lang/en.d.ts +0 -5
  184. package/src/lang/en.js +0 -188
  185. package/src/lang/es.d.ts +0 -5
  186. package/src/lang/es.js +0 -188
  187. package/src/lang/fa.d.ts +0 -5
  188. package/src/lang/fa.js +0 -188
  189. package/src/lang/fr.d.ts +0 -5
  190. package/src/lang/fr.js +0 -188
  191. package/src/lang/he.d.ts +0 -5
  192. package/src/lang/he.js +0 -188
  193. package/src/lang/index.d.ts +0 -23
  194. package/src/lang/it.d.ts +0 -5
  195. package/src/lang/it.js +0 -188
  196. package/src/lang/ja.d.ts +0 -5
  197. package/src/lang/ja.js +0 -188
  198. package/src/lang/ko.d.ts +0 -5
  199. package/src/lang/ko.js +0 -188
  200. package/src/lang/lv.d.ts +0 -5
  201. package/src/lang/lv.js +0 -188
  202. package/src/lang/nl.d.ts +0 -5
  203. package/src/lang/nl.js +0 -188
  204. package/src/lang/pl.d.ts +0 -5
  205. package/src/lang/pl.js +0 -188
  206. package/src/lang/pt_br.d.ts +0 -5
  207. package/src/lang/pt_br.js +0 -189
  208. package/src/lang/ro.d.ts +0 -5
  209. package/src/lang/ro.js +0 -188
  210. package/src/lang/ru.d.ts +0 -5
  211. package/src/lang/ru.js +0 -188
  212. package/src/lang/se.d.ts +0 -5
  213. package/src/lang/se.js +0 -191
  214. package/src/lang/tr.d.ts +0 -5
  215. package/src/lang/tr.js +0 -191
  216. package/src/lang/ua.d.ts +0 -5
  217. package/src/lang/ua.js +0 -188
  218. package/src/lang/ur.d.ts +0 -5
  219. package/src/lang/ur.js +0 -188
  220. package/src/lang/zh_cn.d.ts +0 -5
  221. package/src/lang/zh_cn.js +0 -187
  222. package/src/lib/constructor.js +0 -954
  223. package/src/lib/context.d.ts +0 -42
  224. package/src/lib/context.js +0 -71
  225. package/src/lib/core.d.ts +0 -1135
  226. package/src/lib/core.js +0 -9395
  227. package/src/lib/history.d.ts +0 -48
  228. package/src/lib/history.js +0 -219
  229. package/src/lib/util.d.ts +0 -678
  230. package/src/lib/util.js +0 -2131
  231. package/src/options.d.ts +0 -608
  232. package/src/plugins/CommandPlugin.d.ts +0 -8
  233. package/src/plugins/DialogPlugin.d.ts +0 -20
  234. package/src/plugins/FileBrowserPlugin.d.ts +0 -30
  235. package/src/plugins/Module.d.ts +0 -15
  236. package/src/plugins/Plugin.d.ts +0 -42
  237. package/src/plugins/SubmenuPlugin.d.ts +0 -8
  238. package/src/plugins/dialog/audio.js +0 -559
  239. package/src/plugins/dialog/image.js +0 -1126
  240. package/src/plugins/dialog/link.js +0 -223
  241. package/src/plugins/dialog/math.js +0 -295
  242. package/src/plugins/dialog/mention.js +0 -242
  243. package/src/plugins/dialog/video.js +0 -979
  244. package/src/plugins/index.d.ts +0 -79
  245. package/src/plugins/modules/_anchor.js +0 -461
  246. package/src/plugins/modules/_colorPicker.d.ts +0 -60
  247. package/src/plugins/modules/_colorPicker.js +0 -201
  248. package/src/plugins/modules/_notice.d.ts +0 -21
  249. package/src/plugins/modules/_notice.js +0 -72
  250. package/src/plugins/modules/_selectMenu.js +0 -119
  251. package/src/plugins/modules/component.d.ts +0 -25
  252. package/src/plugins/modules/component.js +0 -81
  253. package/src/plugins/modules/dialog.d.ts +0 -28
  254. package/src/plugins/modules/dialog.js +0 -175
  255. package/src/plugins/modules/fileBrowser.d.ts +0 -42
  256. package/src/plugins/modules/fileBrowser.js +0 -374
  257. package/src/plugins/modules/fileManager.d.ts +0 -67
  258. package/src/plugins/modules/fileManager.js +0 -326
  259. package/src/plugins/modules/index.js +0 -9
  260. package/src/plugins/modules/resizing.d.ts +0 -154
  261. package/src/plugins/modules/resizing.js +0 -903
  262. package/src/plugins/submenu/align.d.ts +0 -5
  263. package/src/plugins/submenu/align.js +0 -160
  264. package/src/plugins/submenu/font.d.ts +0 -5
  265. package/src/plugins/submenu/font.js +0 -123
  266. package/src/plugins/submenu/fontColor.d.ts +0 -5
  267. package/src/plugins/submenu/fontColor.js +0 -101
  268. package/src/plugins/submenu/fontSize.d.ts +0 -5
  269. package/src/plugins/submenu/fontSize.js +0 -112
  270. package/src/plugins/submenu/formatBlock.d.ts +0 -5
  271. package/src/plugins/submenu/formatBlock.js +0 -273
  272. package/src/plugins/submenu/hiliteColor.d.ts +0 -5
  273. package/src/plugins/submenu/hiliteColor.js +0 -102
  274. package/src/plugins/submenu/horizontalRule.d.ts +0 -5
  275. package/src/plugins/submenu/horizontalRule.js +0 -98
  276. package/src/plugins/submenu/lineHeight.d.ts +0 -5
  277. package/src/plugins/submenu/lineHeight.js +0 -104
  278. package/src/plugins/submenu/list.d.ts +0 -5
  279. package/src/plugins/submenu/list.js +0 -456
  280. package/src/plugins/submenu/paragraphStyle.d.ts +0 -5
  281. package/src/plugins/submenu/paragraphStyle.js +0 -135
  282. package/src/plugins/submenu/table.d.ts +0 -5
  283. package/src/plugins/submenu/table.js +0 -1431
  284. package/src/plugins/submenu/template.d.ts +0 -5
  285. package/src/plugins/submenu/template.js +0 -72
  286. package/src/plugins/submenu/textStyle.d.ts +0 -5
  287. package/src/plugins/submenu/textStyle.js +0 -167
  288. package/src/suneditor.d.ts +0 -9
  289. package/src/suneditor_build.js +0 -18
  290. /package/{src/plugins/dialog → typings}/mention.d.ts +0 -0
@@ -0,0 +1,870 @@
1
+ import EditorInjector from '../../editorInjector';
2
+ import { Modal, Figure, FileManager } from '../../modules';
3
+ import { domUtils, numbers, env } from '../../helper';
4
+ const { NO_EVENT } = env;
5
+
6
+ const Video = function (editor, pluginOptions) {
7
+ // plugin bisic properties
8
+ EditorInjector.call(this, editor);
9
+ this.title = this.lang.video;
10
+ this.icon = 'video';
11
+
12
+ // define plugin options
13
+ this.pluginOptions = {
14
+ canResize: pluginOptions.canResize === undefined ? true : pluginOptions.canResize,
15
+ showHeightInput: pluginOptions.showHeightInput === undefined ? true : !!pluginOptions.showHeightInput,
16
+ defaultWidth: !pluginOptions.defaultWidth || !numbers.get(pluginOptions.defaultWidth, 0) ? '' : numbers.is(pluginOptions.defaultWidth) ? pluginOptions.defaultWidth + 'px' : pluginOptions.defaultWidth,
17
+ defaultHeight: !pluginOptions.defaultHeight || !numbers.get(pluginOptions.defaultHeight, 0) ? '' : numbers.is(pluginOptions.defaultHeight) ? pluginOptions.defaultHeight + 'px' : pluginOptions.defaultHeight,
18
+ percentageOnlySize: !!pluginOptions.percentageOnlySize,
19
+ createFileInput: !!pluginOptions.createFileInput,
20
+ createUrlInput: pluginOptions.createUrlInput === undefined || !pluginOptions.createFileInput ? true : pluginOptions.createUrlInput,
21
+ uploadUrl: typeof pluginOptions.uploadUrl === 'string' ? pluginOptions.uploadUrl : null,
22
+ uploadHeaders: pluginOptions.uploadHeaders || null,
23
+ uploadSizeLimit: /\d+/.test(pluginOptions.uploadSizeLimit) ? numbers.get(pluginOptions.uploadSizeLimit, 0) : null,
24
+ uploadSingleSizeLimit: /\d+/.test(pluginOptions.uploadSingleSizeLimit) ? numbers.get(pluginOptions.uploadSingleSizeLimit, 0) : null,
25
+ allowMultiple: !!pluginOptions.allowMultiple,
26
+ acceptedFormats: typeof pluginOptions.acceptedFormats !== 'string' || pluginOptions.acceptedFormats.trim() === '*' ? 'video/*' : pluginOptions.acceptedFormats.trim() || 'video/*',
27
+ defaultRatio: numbers.get(pluginOptions.defaultRatio, 4) || 0.5625,
28
+ showRatioOption: pluginOptions.showRatioOption === undefined ? true : !!pluginOptions.showRatioOption,
29
+ ratioOptions: !pluginOptions.ratioOptions ? null : pluginOptions.ratioOptions,
30
+ videoTagAttributes: pluginOptions.videoTagAttributes || null,
31
+ iframeTagAttributes: pluginOptions.iframeTagAttributes || null
32
+ };
33
+
34
+ // create HTML
35
+ const sizeUnit = this.pluginOptions.percentageOnlySize ? '%' : 'px';
36
+ const modalEl = CreateHTML_modal(editor, this.pluginOptions);
37
+ const figureControls =
38
+ pluginOptions.controls || !this.pluginOptions.canResize
39
+ ? [['mirror_h', 'mirror_v', 'align', 'revert', 'edit', 'remove']]
40
+ : [
41
+ ['resize_auto,75,50', 'rotate_l', 'rotate_r', 'mirror_h', 'mirror_v'],
42
+ ['edit', 'align', 'revert', 'remove']
43
+ ];
44
+
45
+ // show align
46
+ if (!figureControls.some((subArray) => subArray.includes('align'))) modalEl.querySelector('.se-figure-align').style.display = 'none';
47
+
48
+ // modules
49
+ const defaultRatio = this.pluginOptions.defaultRatio * 100 + '%';
50
+ this.modal = new Modal(this, modalEl);
51
+ this.figure = new Figure(this, figureControls, { sizeUnit: sizeUnit, autoRatio: { current: defaultRatio, default: defaultRatio } });
52
+ this.fileManager = new FileManager(this, {
53
+ query: 'iframe, video',
54
+ loadHandler: this.events.onVideoLoad,
55
+ eventHandler: this.events.onVideoAction
56
+ });
57
+
58
+ // members
59
+ this.fileModalWrapper = modalEl.querySelector('.se-flex-input-wrapper');
60
+ this.videoInputFile = modalEl.querySelector('.__se__file_input');
61
+ this.videoUrlFile = modalEl.querySelector('.se-input-url');
62
+ this.focusElement = this.videoUrlFile || this.videoInputFile;
63
+ this.previewSrc = modalEl.querySelector('.se-link-preview');
64
+ this._linkValue = '';
65
+ this._align = 'none';
66
+ this._videoRatio = defaultRatio;
67
+ this._defaultRatio = defaultRatio;
68
+ this._defaultSizeX = '100%';
69
+ this._defaultSizeY = this.pluginOptions.defaultRatio * 100 + '%';
70
+ this.sizeUnit = sizeUnit;
71
+ this.proportion = {};
72
+ this.videoRatioOption = {};
73
+ this.inputX = {};
74
+ this.inputY = {};
75
+ this._element = null;
76
+ this._cover = null;
77
+ this._container = null;
78
+ this._ratio = { w: 1, h: 1 };
79
+ this._origin_w = this.pluginOptions.defaultWidth === '100%' ? '' : this.pluginOptions.defaultWidth;
80
+ this._origin_h = this.pluginOptions.defaultHeight === defaultRatio ? '' : this.pluginOptions.defaultHeight;
81
+ this._resizing = this.pluginOptions.canResize;
82
+ this._onlyPercentage = this.pluginOptions.percentageOnlySize;
83
+ this._nonResizing = !this._resizing || !this.pluginOptions.showHeightInput || this._onlyPercentage;
84
+ this.query = {
85
+ youtube: {
86
+ pattern: /youtu\.?be/i,
87
+ action: this.convertUrlYoutube.bind(this),
88
+ tag: 'iframe'
89
+ },
90
+ vimeo: {
91
+ pattern: /vimeo\.com/i,
92
+ action: this.convertUrlVimeo.bind(this),
93
+ tag: 'iframe'
94
+ },
95
+ ...pluginOptions.embedQuery
96
+ };
97
+
98
+ // init
99
+ if (this.videoInputFile) modalEl.querySelector('.se-file-remove').addEventListener('click', RemoveSelectedFiles.bind(this));
100
+ if (this.videoUrlFile) this.videoUrlFile.addEventListener('input', OnLinkPreview.bind(this));
101
+ if (this.videoInputFile && this.videoUrlFile) this.videoInputFile.addEventListener('change', OnfileInputChange.bind(this));
102
+
103
+ if (this._resizing) {
104
+ this.proportion = modalEl.querySelector('._se_video_check_proportion');
105
+ this.videoRatioOption = modalEl.querySelector('.se-video-ratio');
106
+ this.inputX = modalEl.querySelector('._se_video_size_x');
107
+ this.inputY = modalEl.querySelector('._se_video_size_y');
108
+ this.inputX.value = this.pluginOptions.defaultWidth;
109
+ this.inputY.value = this.pluginOptions.defaultHeight;
110
+
111
+ const ratioChange = OnChangeRatio.bind(this);
112
+ this.inputX.addEventListener('keyup', OnInputSize.bind(this, 'x'));
113
+ this.inputY.addEventListener('keyup', OnInputSize.bind(this, 'y'));
114
+ this.inputX.addEventListener('change', ratioChange);
115
+ this.inputY.addEventListener('change', ratioChange);
116
+ this.proportion.addEventListener('change', ratioChange);
117
+ this.videoRatioOption.addEventListener('change', SetVideoRatio.bind(this));
118
+ modalEl.querySelector('.se-modal-btn-revert').addEventListener('click', OnClickRevert.bind(this));
119
+ }
120
+ };
121
+
122
+ Video.key = 'video';
123
+ Video.type = 'modal';
124
+ Video.className = '';
125
+ Video.component = function (node) {
126
+ if (/^(VIDEO)$/i.test(node?.nodeName)) {
127
+ return node;
128
+ } else if (/^(IFRAME)$/i.test(node?.nodeName)) {
129
+ return this.findProcessUrl(node.src) ? node : null;
130
+ }
131
+ return null;
132
+ };
133
+ Video.prototype = {
134
+ /**
135
+ * @override type = "modal"
136
+ */
137
+ open() {
138
+ this.modal.open();
139
+ },
140
+
141
+ /**
142
+ * @override Figure
143
+ */
144
+ edit() {
145
+ this.modal.open();
146
+ },
147
+
148
+ /**
149
+ * @override modal
150
+ * @param {boolean} isUpdate open state is update
151
+ */
152
+ on(isUpdate) {
153
+ if (!isUpdate) {
154
+ this.inputX.value = this._origin_w = this.pluginOptions.defaultWidth === this._defaultSizeX ? '' : this.pluginOptions.defaultWidth;
155
+ this.inputY.value = this._origin_h = this.pluginOptions.defaultHeight === this._defaultSizeY ? '' : this.pluginOptions.defaultHeight;
156
+ this.proportion.disabled = true;
157
+ if (this.videoInputFile && this.pluginOptions.allowMultiple) this.videoInputFile.setAttribute('multiple', 'multiple');
158
+ } else {
159
+ if (this.videoInputFile && this.pluginOptions.allowMultiple) this.videoInputFile.removeAttribute('multiple');
160
+ }
161
+
162
+ if (this._resizing) {
163
+ this._setVideoRatioSelect(this._origin_h || this._defaultRatio);
164
+ }
165
+ },
166
+
167
+ /**
168
+ * @description On paste or drop
169
+ * @param {*} params { frameContext, event, file }
170
+ */
171
+ onPastAndDrop({ file }) {
172
+ if (!/^video/.test(file.type)) return;
173
+
174
+ this._submitFile([file]);
175
+ this.editor.focus();
176
+
177
+ return false;
178
+ },
179
+
180
+ /**
181
+ * @override modal
182
+ * @returns {boolean | undefined}
183
+ */
184
+ async modalAction() {
185
+ this._align = this.modal.form.querySelector('input[name="suneditor_video_radio"]:checked').value;
186
+
187
+ let result = false;
188
+ if (this.videoInputFile && this.videoInputFile.files.length > 0) {
189
+ result = await this._submitFile(this.videoInputFile.files);
190
+ } else if (this.videoUrlFile && this._linkValue.length > 0) {
191
+ result = await this._submitURL(this._linkValue);
192
+ }
193
+
194
+ if (result) this._w.setTimeout(this.component.select.bind(this.component, this._element, 'video'), 0);
195
+
196
+ return result;
197
+ },
198
+
199
+ /**
200
+ * @override core
201
+ */
202
+ retainFormat() {
203
+ return {
204
+ query: 'iframe, video',
205
+ method: (element) => {
206
+ const figureInfo = Figure.GetContainer(element);
207
+ if (figureInfo && figureInfo.container && figureInfo.cover) return;
208
+
209
+ this.ready(element);
210
+ const line = this.format.getLine(element);
211
+ if (line) this._align = line.style.textAlign || line.style.float;
212
+
213
+ this._update(element);
214
+ }
215
+ };
216
+ },
217
+
218
+ /**
219
+ * @override modal
220
+ */
221
+ init() {
222
+ Modal.OnChangeFile(this.fileModalWrapper, []);
223
+ if (this.videoInputFile) this.videoInputFile.value = '';
224
+ if (this.videoUrlFile) this._linkValue = this.previewSrc.textContent = this.videoUrlFile.value = '';
225
+ if (this.videoInputFile && this.videoUrlFile) {
226
+ this.videoUrlFile.removeAttribute('disabled');
227
+ this.previewSrc.style.textDecoration = '';
228
+ }
229
+
230
+ this.modal.form.querySelector('input[name="suneditor_video_radio"][value="none"]').checked = true;
231
+ this._ratio = { w: 1, h: 1 };
232
+ this._nonResizing = false;
233
+
234
+ if (this._resizing) {
235
+ this.inputX.value = this.pluginOptions.defaultWidth === this._defaultSizeX ? '' : this.pluginOptions.defaultWidth;
236
+ this.inputY.value = this.pluginOptions.defaultHeight === this._defaultSizeY ? '' : this.pluginOptions.defaultHeight;
237
+ this.proportion.checked = false;
238
+ this.proportion.disabled = true;
239
+ this._setVideoRatioSelect(this._defaultRatio);
240
+ }
241
+ },
242
+
243
+ /**
244
+ * @override component, fileManager
245
+ * @description Called when a container is selected.
246
+ * @param {Element} element Target element
247
+ */
248
+ select(element) {
249
+ this.ready(element);
250
+ },
251
+
252
+ /**
253
+ * @override fileManager, figure
254
+ * @param {Element} target Target element
255
+ */
256
+ ready(target) {
257
+ if (!target) return;
258
+ const figureInfo = this.figure.open(target, { nonResizing: this._nonResizing, nonSizeInfo: false, nonBorder: false, figureTarget: false, __fileManagerInfo: false });
259
+
260
+ this._element = target;
261
+ this._cover = figureInfo.cover;
262
+ this._container = figureInfo.container;
263
+ this._align = figureInfo.align;
264
+ target.style.float = '';
265
+
266
+ this._origin_w = figureInfo.width || figureInfo.originWidth || figureInfo.w || '';
267
+ this._origin_h = figureInfo.height || figureInfo.originHeight || figureInfo.h || '';
268
+
269
+ let w = figureInfo.width || figureInfo.w || this._origin_w || '';
270
+ const h = figureInfo.height || figureInfo.h || this._origin_h || '';
271
+
272
+ if (this.videoUrlFile) this._linkValue = this.previewSrc.textContent = this.videoUrlFile.value = this._element.src || (this._element.querySelector('source') || '').src || '';
273
+ (this.modal.form.querySelector('input[name="suneditor_video_radio"][value="' + this._align + '"]') || this.modal.form.querySelector('input[name="suneditor_video_radio"][value="none"]')).checked = true;
274
+
275
+ if (!this._resizing) return;
276
+
277
+ const percentageRotation = this._onlyPercentage && this.figure.isVertical;
278
+ if (this._onlyPercentage) {
279
+ w = numbers.get(w, 2);
280
+ if (w > 100) w = 100;
281
+ }
282
+ this.inputX.value = w === 'auto' ? '' : w;
283
+
284
+ if (!this._onlyPercentage) {
285
+ const infoH = percentageRotation ? '' : figureInfo.height;
286
+ this.inputY.value = infoH === 'auto' ? '' : infoH;
287
+ }
288
+
289
+ if (!this._setVideoRatioSelect(h)) this.inputY.value = this._onlyPercentage ? numbers.get(h, 2) : h;
290
+
291
+ this.proportion.checked = true;
292
+ this.inputX.disabled = percentageRotation ? true : false;
293
+ this.inputY.disabled = percentageRotation ? true : false;
294
+ this.proportion.disabled = percentageRotation ? true : false;
295
+
296
+ this._ratio = this.proportion.checked ? figureInfo.ratio : { w: 1, h: 1 };
297
+ },
298
+
299
+ /**
300
+ * @override fileManager
301
+ */
302
+ async destroy(element) {
303
+ const targetEl = element || this._element;
304
+ const container = domUtils.getParentElement(targetEl, Figure.__is) || targetEl;
305
+ const focusEl = container.previousElementSibling || container.nextElementSibling;
306
+ const emptyDiv = container.parentNode;
307
+
308
+ const message = await this.triggerEvent('onVideoDeleteBefore', { target: targetEl, container, align: this._align, url: this._linkValue });
309
+ if (message === false) return;
310
+
311
+ domUtils.removeItem(container);
312
+ this.init();
313
+
314
+ if (emptyDiv !== this.editor.frameContext.get('wysiwyg')) {
315
+ this.nodeTransform.removeAllParents(
316
+ emptyDiv,
317
+ function (current) {
318
+ return current.childNodes.length === 0;
319
+ },
320
+ null
321
+ );
322
+ }
323
+
324
+ // focus
325
+ this.editor.focusEdge(focusEl);
326
+ this.history.push(false);
327
+ },
328
+
329
+ findProcessUrl(url) {
330
+ const query = this.query;
331
+ for (const key in query) {
332
+ const service = query[key];
333
+ if (service.pattern.test(url)) {
334
+ return {
335
+ origin: url,
336
+ url: service.action(url),
337
+ tag: service.tag
338
+ };
339
+ }
340
+ }
341
+
342
+ return null;
343
+ },
344
+
345
+ convertUrlYoutube(url) {
346
+ if (!/^http/.test(url)) url = 'https://' + url;
347
+ url = url.replace('watch?v=', '');
348
+ if (!/^\/\/.+\/embed\//.test(url)) {
349
+ url = url.replace(url.match(/\/\/.+\//)[0], '//www.youtube.com/embed/').replace('&', '?&');
350
+ }
351
+ return url;
352
+ },
353
+
354
+ convertUrlVimeo(url) {
355
+ if (url.endsWith('/')) {
356
+ url = url.slice(0, -1);
357
+ }
358
+ url = 'https://player.vimeo.com/video/' + url.slice(url.lastIndexOf('/') + 1);
359
+ return url;
360
+ },
361
+
362
+ applySize(w, h) {
363
+ if (!w) w = this.inputX.value || this.pluginOptions.defaultWidth;
364
+ if (!h) h = this.inputY.value || this.pluginOptions.defaultHeight;
365
+ if (this._onlyPercentage) {
366
+ if (!w) w = '100%';
367
+ else if (/%$/.test(w)) w += '%';
368
+ }
369
+ this.figure.setSize(w, h);
370
+ },
371
+
372
+ create(oFrame, src, width, height, align, isUpdate, file) {
373
+ let cover = null;
374
+ let container = null;
375
+
376
+ /** update */
377
+ if (isUpdate) {
378
+ oFrame = this._element;
379
+ if (oFrame.src !== src) {
380
+ const processUrl = this.findProcessUrl(src);
381
+ if (/^iframe$/i.test(processUrl?.tag) && !/^iframe$/i.test(oFrame.nodeName)) {
382
+ const newTag = this.createIframeTag();
383
+ newTag.src = src;
384
+ oFrame.parentNode.replaceChild(newTag, oFrame);
385
+ this._element = oFrame = newTag;
386
+ } else if (/^video$/i.test(processUrl?.tag) && !/^video$/i.test(oFrame.nodeName)) {
387
+ const newTag = this.createVideoTag();
388
+ newTag.src = src;
389
+ oFrame.parentNode.replaceChild(newTag, oFrame);
390
+ this._element = oFrame = newTag;
391
+ } else {
392
+ oFrame.src = src;
393
+ }
394
+ }
395
+ container = this._container;
396
+ cover = domUtils.getParentElement(oFrame, 'FIGURE');
397
+ } else {
398
+ /** create */
399
+ oFrame.src = src;
400
+ this._element = oFrame;
401
+ const figure = Figure.CreateContainer(oFrame, 'se-video-container');
402
+ cover = figure.cover;
403
+ container = figure.container;
404
+ }
405
+
406
+ /** rendering */
407
+ this._element = oFrame;
408
+ this._cover = cover;
409
+ this._container = container;
410
+ this.figure.open(oFrame, { nonResizing: this._nonResizing, nonSizeInfo: false, nonBorder: false, figureTarget: false, __fileManagerInfo: true });
411
+
412
+ width = width || this._defaultSizeX;
413
+ height = height || this._videoRatio;
414
+ const size = this.figure.getSize(oFrame);
415
+ const inputUpdate = size.w !== width || size.h !== height;
416
+ const changeSize = !isUpdate || inputUpdate;
417
+
418
+ // set size
419
+ if (changeSize) {
420
+ this.applySize(width, height);
421
+ }
422
+
423
+ // align
424
+ this.figure.setAlign(oFrame, align);
425
+
426
+ // select figure
427
+ // oFrame.onload = OnloadVideo.bind(this, oFrame);
428
+
429
+ this.fileManager.setFileData(oFrame, file);
430
+
431
+ if (!isUpdate) {
432
+ this.component.insert(container, false, true);
433
+ if (!this.options.get('mediaAutoSelect')) {
434
+ const line = this.format.addLine(container, null);
435
+ if (line) this.selection.setRange(line, 0, line, 0);
436
+ }
437
+ return;
438
+ }
439
+
440
+ if (this._resizing && changeSize && this.figure.isVertical) this.figure.setTransform(oFrame, width, height, 0);
441
+ this.history.push(false);
442
+ },
443
+
444
+ createIframeTag() {
445
+ const iframeTag = domUtils.createElement('IFRAME');
446
+ this._setIframeAttrs(iframeTag);
447
+ return iframeTag;
448
+ },
449
+
450
+ createVideoTag: function () {
451
+ const videoTag = domUtils.createElement('VIDEO');
452
+ this._setTagAttrs(videoTag);
453
+ return videoTag;
454
+ },
455
+
456
+ _getInfo() {
457
+ return {
458
+ inputWidth: this.inputX.value,
459
+ inputHeight: this.inputY.value,
460
+ align: this._align,
461
+ isUpdate: this.modal.isUpdate,
462
+ element: this._element
463
+ };
464
+ },
465
+
466
+ async _submitFile(fileList) {
467
+ if (fileList.length === 0) return;
468
+
469
+ let fileSize = 0;
470
+ const files = [];
471
+ const slngleSizeLimit = this.uploadSingleSizeLimit;
472
+ for (let i = 0, len = fileList.length, f, s; i < len; i++) {
473
+ f = fileList[i];
474
+ if (!/video/i.test(f.type)) continue;
475
+
476
+ s = f.size;
477
+ if (slngleSizeLimit && slngleSizeLimit > s) {
478
+ const err = '[SUNEDITOR.videoUpload.fail] Size of uploadable single file: ' + slngleSizeLimit / 1000 + 'KB';
479
+ const message = await this.triggerEvent('onVideoUploadError', {
480
+ error: err,
481
+ limitSize: slngleSizeLimit,
482
+ uploadSize: s,
483
+ file: f
484
+ });
485
+
486
+ this.notice.open(message === NO_EVENT ? err : message || err);
487
+
488
+ return false;
489
+ }
490
+
491
+ files.push(f);
492
+ fileSize += s;
493
+ }
494
+
495
+ const limitSize = this.pluginOptions.uploadSizeLimit;
496
+ const currentSize = this.fileManager.getSize();
497
+ if (limitSize > 0 && fileSize + currentSize > limitSize) {
498
+ const err = '[SUNEDITOR.videoUpload.fail] Size of uploadable total videos: ' + limitSize / 1000 + 'KB';
499
+ const message = await this.triggerEvent('onVideoUploadError', { error: err, limitSize, currentSize, uploadSize: fileSize });
500
+
501
+ this.notice.open(message === NO_EVENT ? err : message || err);
502
+
503
+ return false;
504
+ }
505
+
506
+ const videoInfo = {
507
+ url: null,
508
+ files,
509
+ ...this._getInfo()
510
+ };
511
+
512
+ const handler = function (infos, newInfos) {
513
+ infos = newInfos || infos;
514
+ this._serverUpload(infos, infos.files);
515
+ }.bind(this, videoInfo);
516
+
517
+ const result = await this.triggerEvent('onVideoUploadBefore', {
518
+ ...videoInfo,
519
+ handler
520
+ });
521
+
522
+ if (result === undefined) return true;
523
+ if (result === false) return false;
524
+ if (result !== null && typeof result === 'object') handler(result);
525
+
526
+ if (result === true || result === NO_EVENT) handler(null);
527
+ },
528
+
529
+ async _submitURL(url) {
530
+ if (!url) url = this._linkValue;
531
+ if (!url) return false;
532
+
533
+ /** iframe source */
534
+ if (/^<iframe.*\/iframe>$/.test(url)) {
535
+ const oIframe = new DOMParser().parseFromString(url, 'text/html').querySelector('iframe');
536
+ url = oIframe.src;
537
+ if (url.length === 0) return false;
538
+ }
539
+
540
+ const processUrl = this.findProcessUrl(url);
541
+ if (processUrl) {
542
+ url = processUrl.url;
543
+ }
544
+
545
+ const file = { name: url.split('/').pop(), size: 0 };
546
+ const videoInfo = { url, files: file, ...this._getInfo(), process: processUrl };
547
+
548
+ const handler = function (infos, newInfos) {
549
+ infos = newInfos || infos;
550
+ this.create(this[/^iframe$/i.test(infos.process?.tag) ? 'createIframeTag' : 'createVideoTag'](), infos.url, infos.inputWidth, infos.inputHeight, infos.align, infos.isUpdate, infos.files);
551
+ }.bind(this, videoInfo);
552
+
553
+ const result = await this.triggerEvent('onVideoUploadBefore', {
554
+ ...videoInfo,
555
+ handler
556
+ });
557
+
558
+ if (result === undefined) return true;
559
+ if (result === false) return false;
560
+ if (result !== null && typeof result === 'object') handler(result);
561
+
562
+ if (result === true || result === NO_EVENT) handler(null);
563
+
564
+ return true;
565
+ },
566
+
567
+ _update(oFrame) {
568
+ if (!oFrame) return;
569
+
570
+ if (/^video$/i.test(oFrame.nodeName)) {
571
+ this._setTagAttrs(oFrame);
572
+ } else if (/^iframe$/i.test(oFrame.nodeName)) {
573
+ this._setIframeAttrs(oFrame);
574
+ }
575
+
576
+ let existElement = this.format.isBlock(oFrame.parentNode) || domUtils.isWysiwygFrame(oFrame.parentNode) ? oFrame : this.format.getLine(oFrame) || oFrame;
577
+
578
+ const prevFrame = oFrame;
579
+ oFrame = oFrame.cloneNode(true);
580
+ const figure = Figure.CreateContainer(oFrame, 'se-video-container');
581
+ const container = figure.container;
582
+
583
+ const figcaption = existElement.querySelector('figcaption');
584
+ let caption = null;
585
+ if (figcaption) {
586
+ caption = domUtils.createElement('DIV');
587
+ caption.innerHTML = figcaption.innerHTML;
588
+ domUtils.removeItem(figcaption);
589
+ }
590
+
591
+ // size
592
+ this.figure.open(oFrame, { nonResizing: this._nonResizing, nonSizeInfo: false, nonBorder: false, figureTarget: false, __fileManagerInfo: true });
593
+ const size = (oFrame.getAttribute('data-se-size') || ',').split(',');
594
+ this.applySize(size[0] || prevFrame.style.width || prevFrame.width || '', size[1] || prevFrame.style.height || prevFrame.height || '');
595
+
596
+ // align
597
+ const format = this.format.getLine(prevFrame);
598
+ if (format) this._align = format.style.textAlign || format.style.float;
599
+ this.figure.setAlign(oFrame, this._align);
600
+
601
+ if (domUtils.getParentElement(prevFrame, domUtils.isExcludeFormat)) {
602
+ prevFrame.parentNode.replaceChild(container, prevFrame);
603
+ } else if (domUtils.isListCell(existElement)) {
604
+ const refer = domUtils.getParentElement(prevFrame, (current) => current.parentNode === existElement);
605
+ existElement.insertBefore(container, refer);
606
+ domUtils.removeItem(prevFrame);
607
+ this.nodeTransform.removeEmptyNode(refer, null, true);
608
+ } else if (this.format.isLineOnly(existElement)) {
609
+ const refer = domUtils.getParentElement(prevFrame, (current) => current.parentNode === existElement);
610
+ existElement = this.nodeTransform.split(existElement, refer);
611
+ existElement.parentNode.insertBefore(container, existElement);
612
+ domUtils.removeItem(prevFrame);
613
+ this.nodeTransform.removeEmptyNode(existElement, null, true);
614
+ } else {
615
+ existElement.parentNode.replaceChild(container, existElement);
616
+ }
617
+
618
+ if (caption) existElement.parentNode.insertBefore(caption, container.nextElementSibling);
619
+
620
+ return oFrame;
621
+ },
622
+
623
+ _register(info, response) {
624
+ const fileList = response.result;
625
+ const videoTag = this.createVideoTag();
626
+
627
+ for (let i = 0, len = fileList.length; i < len; i++) {
628
+ this.create(info.isUpdate ? info.element : videoTag.cloneNode(false), fileList[i].url, info.inputWidth, info.inputHeight, info.align, info.isUpdate, {
629
+ name: fileList[i].name,
630
+ size: fileList[i].size
631
+ });
632
+ }
633
+ },
634
+
635
+ _serverUpload(info, files) {
636
+ if (!files) return;
637
+
638
+ const videoUploadUrl = this.pluginOptions.uploadUrl;
639
+ if (typeof videoUploadUrl === 'string' && videoUploadUrl.length > 0) {
640
+ this.fileManager.upload(videoUploadUrl, this.pluginOptions.uploadHeaders, files, UploadCallBack.bind(this, info), this._error.bind(this));
641
+ }
642
+ },
643
+
644
+ _setTagAttrs(element) {
645
+ element.setAttribute('controls', true);
646
+
647
+ const attrs = this.pluginOptions.videoTagAttributes;
648
+ if (!attrs) return;
649
+
650
+ for (const key in attrs) {
651
+ element.setAttribute(key, attrs[key]);
652
+ }
653
+ },
654
+
655
+ _setIframeAttrs(element) {
656
+ element.frameBorder = '0';
657
+ element.allowFullscreen = true;
658
+
659
+ const attrs = this.pluginOptions.iframeTagAttributes;
660
+ if (!attrs) return;
661
+
662
+ for (const key in attrs) {
663
+ element.setAttribute(key, attrs[key]);
664
+ }
665
+ },
666
+
667
+ _setVideoRatioSelect(value) {
668
+ let ratioSelected = false;
669
+ const ratioOption = this.videoRatioOption.options;
670
+
671
+ if (/%$/.test(value) || this._onlyPercentage) value = numbers.get(value, 2) / 100 + '';
672
+ else if (!numbers.is(value) || value * 1 >= 1) value = '';
673
+
674
+ this.inputY.placeholder = '';
675
+ for (let i = 0, len = ratioOption.length; i < len; i++) {
676
+ if (ratioOption[i].value === value) {
677
+ ratioSelected = ratioOption[i].selected = true;
678
+ this.inputY.placeholder = !value ? '' : value * 100 + '%';
679
+ } else ratioOption[i].selected = false;
680
+ }
681
+
682
+ return ratioSelected;
683
+ },
684
+
685
+ async _error(response) {
686
+ const message = await this.triggerEvent('onVideoUploadError', { error: response });
687
+ const err = message === NO_EVENT ? response.errorMessage : message || response.errorMessage;
688
+ this.notice.open(err);
689
+ console.error('[SUNEDITOR.plugin.video.error]', message);
690
+ },
691
+
692
+ constructor: Video
693
+ };
694
+
695
+ async function UploadCallBack(info, xmlHttp) {
696
+ if ((await this.triggerEvent('videoUploadHandler', { xmlHttp, info })) === NO_EVENT) {
697
+ const response = JSON.parse(xmlHttp.responseText);
698
+ if (response.errorMessage) {
699
+ this._error(response);
700
+ } else {
701
+ this._register(info, response);
702
+ }
703
+ }
704
+ }
705
+
706
+ function RemoveSelectedFiles() {
707
+ this.videoInputFile.value = '';
708
+ if (this.videoUrlFile) {
709
+ this.videoUrlFile.removeAttribute('disabled');
710
+ this.previewSrc.style.textDecoration = '';
711
+ }
712
+
713
+ // inputFile check
714
+ Modal.OnChangeFile(this.fileModalWrapper, []);
715
+ }
716
+
717
+ function OnLinkPreview(e) {
718
+ const value = e.target.value.trim();
719
+ if (/^<iframe.*\/iframe>$/.test(value)) {
720
+ this._linkValue = value;
721
+ this.previewSrc.textContent = '<IFrame :src=".."></IFrame>';
722
+ } else {
723
+ this._linkValue = this.previewSrc.textContent = !value
724
+ ? ''
725
+ : this.options.get('defaultUrlProtocol') && !value.includes('://') && value.indexOf('#') !== 0
726
+ ? this.options.get('defaultUrlProtocol') + value
727
+ : !value.includes('://')
728
+ ? '/' + value
729
+ : value;
730
+ }
731
+ }
732
+
733
+ function OnfileInputChange({ target }) {
734
+ if (!this.videoInputFile.value) {
735
+ this.videoUrlFile.removeAttribute('disabled');
736
+ this.previewSrc.style.textDecoration = '';
737
+ } else {
738
+ this.videoUrlFile.setAttribute('disabled', true);
739
+ this.previewSrc.style.textDecoration = 'line-through';
740
+ }
741
+
742
+ // inputFile check
743
+ Modal.OnChangeFile(this.fileModalWrapper, target.files);
744
+ }
745
+
746
+ function OnClickRevert() {
747
+ if (this._onlyPercentage) {
748
+ this.inputX.value = this._origin_w > 100 ? 100 : this._origin_w;
749
+ } else {
750
+ this.inputX.value = this._origin_w;
751
+ this.inputY.value = this._origin_h;
752
+ }
753
+ }
754
+
755
+ function SetVideoRatio(e) {
756
+ const value = e.target.options[e.target.selectedIndex].value;
757
+ this._defaultSizeY = this.figure.autoRatio.current = this._videoRatio = !value ? this._defaultSizeY : value * 100 + '%';
758
+ this.inputY.placeholder = !value ? '' : value * 100 + '%';
759
+ this.inputY.value = '';
760
+ }
761
+
762
+ function OnChangeRatio() {
763
+ this._ratio = this.proportion.checked ? Figure.GetRatio(this.inputX.value, this.inputY.value, this.sizeUnit) : { w: 1, h: 1 };
764
+ }
765
+
766
+ function OnInputSize(xy, e) {
767
+ if (e.keyCode === 32) {
768
+ e.preventDefault();
769
+ return;
770
+ }
771
+
772
+ if (xy === 'x' && this._onlyPercentage && e.target.value > 100) {
773
+ e.target.value = 100;
774
+ } else if (this.proportion.checked) {
775
+ const ratioSize = Figure.CalcRatio(this.inputX.value, this.inputY.value, this.sizeUnit, this._ratio);
776
+ if (xy === 'x') {
777
+ this.inputY.value = ratioSize.h;
778
+ } else {
779
+ this.inputX.value = ratioSize.w;
780
+ }
781
+ }
782
+
783
+ if (xy === 'y') {
784
+ this._setVideoRatioSelect(e.target.value || this._defaultRatio);
785
+ }
786
+ }
787
+
788
+ function CreateHTML_modal({ lang, icons }, pluginOptions) {
789
+ let html = /*html*/ `
790
+ <form method="post" enctype="multipart/form-data">
791
+ <div class="se-modal-header">
792
+ <button type="button" data-command="close" class="se-btn se-close-btn" title="${lang.close}" aria-label="${lang.close}">
793
+ ${icons.cancel}
794
+ </button>
795
+ <span class="se-modal-title">${lang.video_modal_title}</span>
796
+ </div>
797
+ <div class="se-modal-body">`;
798
+
799
+ if (pluginOptions.createFileInput) {
800
+ html += /*html*/ `
801
+ <div class="se-modal-form">
802
+ <label>${lang.video_modal_file}</label>
803
+ ${Modal.CreateFileInput({ lang, icons }, pluginOptions)}
804
+ </div>`;
805
+ }
806
+
807
+ if (pluginOptions.createUrlInput) {
808
+ html += /*html*/ `
809
+ <div class="se-modal-form">
810
+ <label>${lang.video_modal_url}</label>
811
+ <input class="se-input-form se-input-url" type="text" data-focus />
812
+ <pre class="se-link-preview"></pre>
813
+ </div>`;
814
+ }
815
+
816
+ if (pluginOptions.canResize) {
817
+ const ratioList = pluginOptions.ratioOptions || [
818
+ { name: '16:9', value: 0.5625 },
819
+ { name: '4:3', value: 0.75 },
820
+ { name: '21:9', value: 0.4285 }
821
+ ];
822
+ const ratio = pluginOptions.defaultRatio;
823
+ const onlyPercentage = pluginOptions.percentageOnlySize;
824
+ const onlyPercentDisplay = onlyPercentage ? ' style="display: none !important;"' : '';
825
+ const heightDisplay = !pluginOptions.showHeightInput ? ' style="display: none !important;"' : '';
826
+ const ratioDisplay = !pluginOptions.showRatioOption ? ' style="display: none !important;"' : '';
827
+ const onlyWidthDisplay = !onlyPercentage && !pluginOptions.showHeightInput && !pluginOptions.showRatioOption ? ' style="display: none !important;"' : '';
828
+ html += /*html*/ `
829
+ <div class="se-modal-form">
830
+ <div class="se-modal-size-text">
831
+ <label class="size-w">${lang.width}</label>
832
+ <label class="se-modal-size-x">&nbsp;</label>
833
+ <label class="size-h"${heightDisplay}>${lang.height}</label>
834
+ <label class="size-h"${ratioDisplay}>(${lang.ratio})</label>
835
+ </div>
836
+ <input class="se-input-control _se_video_size_x" placeholder="100%"${onlyPercentage ? ' type="number" min="1"' : 'type="text"'}${onlyPercentage ? ' max="100"' : ''}/>
837
+ <label class="se-modal-size-x"${onlyWidthDisplay}>${onlyPercentage ? '%' : 'x'}</label>
838
+ <input class="se-input-control _se_video_size_y" placeholder="${pluginOptions.defaultRatio * 100}%"
839
+ ${onlyPercentage ? ' type="number" min="1"' : 'type="text"'}${onlyPercentage ? ' max="100"' : ''}${heightDisplay}/>
840
+ <select class="se-input-select se-video-ratio" title="${lang.ratio}" aria-label="${lang.ratio}"${ratioDisplay}>
841
+ ${!heightDisplay ? '<option value=""> - </option>' : ''}
842
+ ${ratioList.map((ratioOption) => `<option value="${ratioOption.value}"${ratio.toString() === ratioOption.value.toString() ? ' selected' : ''}>${ratioOption.name}</option>`).join('')}
843
+ </select>
844
+ <button type="button" title="${lang.revert}" aria-label="${lang.revert}" class="se-btn se-modal-btn-revert">${icons.revert}</button>
845
+ </div>
846
+ <div class="se-modal-form se-modal-form-footer"${onlyPercentDisplay}${onlyWidthDisplay}>
847
+ <label>
848
+ <input type="checkbox" class="se-modal-btn-check _se_video_check_proportion" />&nbsp;
849
+ <span>${lang.proportion}</span>
850
+ </label>
851
+ </div>`;
852
+ }
853
+
854
+ html += /*html*/ `
855
+ </div>
856
+ <div class="se-modal-footer">
857
+ <div class="se-figure-align">
858
+ <label><input type="radio" name="suneditor_video_radio" class="se-modal-btn-radio" value="none" checked>${lang.basic}</label>
859
+ <label><input type="radio" name="suneditor_video_radio" class="se-modal-btn-radio" value="left">${lang.left}</label>
860
+ <label><input type="radio" name="suneditor_video_radio" class="se-modal-btn-radio" value="center">${lang.center}</label>
861
+ <label><input type="radio" name="suneditor_video_radio" class="se-modal-btn-radio" value="right">${lang.right}</label>
862
+ </div>
863
+ <button type="submit" class="se-btn-primary" title="${lang.submitButton}" aria-label="${lang.submitButton}"><span>${lang.submitButton}</span></button>
864
+ </div>
865
+ </form>`;
866
+
867
+ return domUtils.createElement('DIV', { class: 'se-modal-content' }, html);
868
+ }
869
+
870
+ export default Video;