popup.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /**
  2. * DevExtreme (ui/html_editor/modules/popup.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. function _typeof(obj) {
  11. "@babel/helpers - typeof";
  12. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) {
  13. return typeof obj
  14. } : function(obj) {
  15. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
  16. }, _typeof(obj)
  17. }
  18. Object.defineProperty(exports, "__esModule", {
  19. value: true
  20. });
  21. var _quill_importer = require("../quill_importer");
  22. var _renderer = require("../../../core/renderer");
  23. var _renderer2 = _interopRequireDefault(_renderer);
  24. var _extend = require("../../../core/utils/extend");
  25. var _window = require("../../../core/utils/window");
  26. var _popup = require("../../popup");
  27. var _popup2 = _interopRequireDefault(_popup);
  28. var _list = require("../../list");
  29. var _list2 = _interopRequireDefault(_list);
  30. function _interopRequireDefault(obj) {
  31. return obj && obj.__esModule ? obj : {
  32. "default": obj
  33. }
  34. }
  35. function _classCallCheck(instance, Constructor) {
  36. if (!(instance instanceof Constructor)) {
  37. throw new TypeError("Cannot call a class as a function")
  38. }
  39. }
  40. function _defineProperties(target, props) {
  41. for (var i = 0; i < props.length; i++) {
  42. var descriptor = props[i];
  43. descriptor.enumerable = descriptor.enumerable || false;
  44. descriptor.configurable = true;
  45. if ("value" in descriptor) {
  46. descriptor.writable = true
  47. }
  48. Object.defineProperty(target, descriptor.key, descriptor)
  49. }
  50. }
  51. function _createClass(Constructor, protoProps, staticProps) {
  52. if (protoProps) {
  53. _defineProperties(Constructor.prototype, protoProps)
  54. }
  55. if (staticProps) {
  56. _defineProperties(Constructor, staticProps)
  57. }
  58. Object.defineProperty(Constructor, "prototype", {
  59. writable: false
  60. });
  61. return Constructor
  62. }
  63. function _inherits(subClass, superClass) {
  64. if ("function" !== typeof superClass && null !== superClass) {
  65. throw new TypeError("Super expression must either be null or a function")
  66. }
  67. subClass.prototype = Object.create(superClass && superClass.prototype, {
  68. constructor: {
  69. value: subClass,
  70. writable: true,
  71. configurable: true
  72. }
  73. });
  74. Object.defineProperty(subClass, "prototype", {
  75. writable: false
  76. });
  77. if (superClass) {
  78. _setPrototypeOf(subClass, superClass)
  79. }
  80. }
  81. function _setPrototypeOf(o, p) {
  82. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
  83. o.__proto__ = p;
  84. return o
  85. };
  86. return _setPrototypeOf(o, p)
  87. }
  88. function _createSuper(Derived) {
  89. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  90. return function() {
  91. var result, Super = _getPrototypeOf(Derived);
  92. if (hasNativeReflectConstruct) {
  93. var NewTarget = _getPrototypeOf(this).constructor;
  94. result = Reflect.construct(Super, arguments, NewTarget)
  95. } else {
  96. result = Super.apply(this, arguments)
  97. }
  98. return _possibleConstructorReturn(this, result)
  99. }
  100. }
  101. function _possibleConstructorReturn(self, call) {
  102. if (call && ("object" === _typeof(call) || "function" === typeof call)) {
  103. return call
  104. } else {
  105. if (void 0 !== call) {
  106. throw new TypeError("Derived constructors may only return object or undefined")
  107. }
  108. }
  109. return _assertThisInitialized(self)
  110. }
  111. function _assertThisInitialized(self) {
  112. if (void 0 === self) {
  113. throw new ReferenceError("this hasn't been initialised - super() hasn't been called")
  114. }
  115. return self
  116. }
  117. function _isNativeReflectConstruct() {
  118. if ("undefined" === typeof Reflect || !Reflect.construct) {
  119. return false
  120. }
  121. if (Reflect.construct.sham) {
  122. return false
  123. }
  124. if ("function" === typeof Proxy) {
  125. return true
  126. }
  127. try {
  128. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
  129. return true
  130. } catch (e) {
  131. return false
  132. }
  133. }
  134. function _getPrototypeOf(o) {
  135. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(o) {
  136. return o.__proto__ || Object.getPrototypeOf(o)
  137. };
  138. return _getPrototypeOf(o)
  139. }
  140. var SUGGESTION_LIST_CLASS = "dx-suggestion-list";
  141. var SUGGESTION_LIST_WRAPPER_CLASS = "dx-suggestion-list-wrapper";
  142. var BaseModule = (0, _quill_importer.getQuill)().import("core/module");
  143. var MIN_HEIGHT = 100;
  144. var ListPopupModule = function(_BaseModule) {
  145. _inherits(ListPopupModule, _BaseModule);
  146. var _super = _createSuper(ListPopupModule);
  147. function ListPopupModule(quill, options) {
  148. var _this;
  149. _classCallCheck(this, ListPopupModule);
  150. _this = _super.call(this, quill, options);
  151. _this.options = (0, _extend.extend)({}, _this._getDefaultOptions(), options);
  152. _this._popup = _this.renderPopup();
  153. _this._popup._wrapper().addClass(SUGGESTION_LIST_WRAPPER_CLASS);
  154. return _this
  155. }
  156. _createClass(ListPopupModule, [{
  157. key: "_getDefaultOptions",
  158. value: function() {
  159. return {
  160. dataSource: null
  161. }
  162. }
  163. }, {
  164. key: "renderList",
  165. value: function($container, options) {
  166. var $list = (0, _renderer2.default)("<div>").addClass(SUGGESTION_LIST_CLASS).appendTo($container);
  167. this._list = this.options.editorInstance._createComponent($list, _list2.default, options)
  168. }
  169. }, {
  170. key: "renderPopup",
  171. value: function() {
  172. var editorInstance = this.options.editorInstance;
  173. var $container = (0, _renderer2.default)("<div>").appendTo(editorInstance.$element());
  174. var popupConfig = this._getPopupConfig();
  175. return editorInstance._createComponent($container, _popup2.default, popupConfig)
  176. }
  177. }, {
  178. key: "_getPopupConfig",
  179. value: function() {
  180. var _this2 = this;
  181. return {
  182. contentTemplate: function(contentElem) {
  183. var listConfig = _this2._getListConfig(_this2.options);
  184. _this2.renderList((0, _renderer2.default)(contentElem), listConfig)
  185. },
  186. deferRendering: false,
  187. onShown: function() {
  188. _this2._list.focus()
  189. },
  190. onHidden: function() {
  191. _this2._list.unselectAll();
  192. _this2._list.option("focusedElement", null)
  193. },
  194. showTitle: false,
  195. width: "auto",
  196. height: "auto",
  197. shading: false,
  198. closeOnTargetScroll: true,
  199. closeOnOutsideClick: true,
  200. animation: {
  201. show: {
  202. type: "fade",
  203. duration: 0,
  204. from: 0,
  205. to: 1
  206. },
  207. hide: {
  208. type: "fade",
  209. duration: 400,
  210. from: 1,
  211. to: 0
  212. }
  213. },
  214. fullScreen: false,
  215. maxHeight: this.maxHeight
  216. }
  217. }
  218. }, {
  219. key: "_getListConfig",
  220. value: function(options) {
  221. return {
  222. dataSource: options.dataSource,
  223. onSelectionChanged: this.selectionChangedHandler.bind(this),
  224. selectionMode: "single",
  225. pageLoadMode: "scrollBottom"
  226. }
  227. }
  228. }, {
  229. key: "maxHeight",
  230. get: function() {
  231. var window = (0, _window.getWindow)();
  232. var windowHeight = window && (0, _renderer2.default)(window).height() || 0;
  233. return Math.max(MIN_HEIGHT, .5 * windowHeight)
  234. }
  235. }, {
  236. key: "selectionChangedHandler",
  237. value: function(e) {
  238. if (this._popup.option("visible")) {
  239. this._popup.hide();
  240. this.insertEmbedContent(e)
  241. }
  242. }
  243. }, {
  244. key: "insertEmbedContent",
  245. value: function(selectionChangedEvent) {}
  246. }, {
  247. key: "showPopup",
  248. value: function() {
  249. this._popup && this._popup.show()
  250. }
  251. }, {
  252. key: "savePosition",
  253. value: function(position) {
  254. this.caretPosition = position
  255. }
  256. }, {
  257. key: "getPosition",
  258. value: function() {
  259. return this.caretPosition
  260. }
  261. }]);
  262. return ListPopupModule
  263. }(BaseModule);
  264. exports.default = ListPopupModule;