ui.diagram.rightpanel.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /**
  2. * DevExtreme (ui/diagram/ui.diagram.rightpanel.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. var _renderer = require("../../core/renderer");
  11. var _renderer2 = _interopRequireDefault(_renderer);
  12. var _diagram = require("./diagram.panel");
  13. var _diagram2 = _interopRequireDefault(_diagram);
  14. var _accordion = require("../accordion");
  15. var _accordion2 = _interopRequireDefault(_accordion);
  16. var _form = require("../form");
  17. var _form2 = _interopRequireDefault(_form);
  18. var _uiDiagram = require("./ui.diagram.commands");
  19. var _uiDiagram2 = _interopRequireDefault(_uiDiagram);
  20. var _extend = require("../../core/utils/extend");
  21. var _diagram_bar = require("./diagram_bar");
  22. var _diagram_bar2 = _interopRequireDefault(_diagram_bar);
  23. function _interopRequireDefault(obj) {
  24. return obj && obj.__esModule ? obj : {
  25. "default": obj
  26. }
  27. }
  28. function _typeof(obj) {
  29. "@babel/helpers - typeof";
  30. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj) {
  31. return typeof obj
  32. } : function(obj) {
  33. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj
  34. }, _typeof(obj)
  35. }
  36. function _classCallCheck(instance, Constructor) {
  37. if (!(instance instanceof Constructor)) {
  38. throw new TypeError("Cannot call a class as a function")
  39. }
  40. }
  41. function _defineProperties(target, props) {
  42. for (var i = 0; i < props.length; i++) {
  43. var descriptor = props[i];
  44. descriptor.enumerable = descriptor.enumerable || false;
  45. descriptor.configurable = true;
  46. if ("value" in descriptor) {
  47. descriptor.writable = true
  48. }
  49. Object.defineProperty(target, descriptor.key, descriptor)
  50. }
  51. }
  52. function _createClass(Constructor, protoProps, staticProps) {
  53. if (protoProps) {
  54. _defineProperties(Constructor.prototype, protoProps)
  55. }
  56. if (staticProps) {
  57. _defineProperties(Constructor, staticProps)
  58. }
  59. Object.defineProperty(Constructor, "prototype", {
  60. writable: false
  61. });
  62. return Constructor
  63. }
  64. function _get() {
  65. if ("undefined" !== typeof Reflect && Reflect.get) {
  66. _get = Reflect.get.bind()
  67. } else {
  68. _get = function(target, property, receiver) {
  69. var base = _superPropBase(target, property);
  70. if (!base) {
  71. return
  72. }
  73. var desc = Object.getOwnPropertyDescriptor(base, property);
  74. if (desc.get) {
  75. return desc.get.call(arguments.length < 3 ? target : receiver)
  76. }
  77. return desc.value
  78. }
  79. }
  80. return _get.apply(this, arguments)
  81. }
  82. function _superPropBase(object, property) {
  83. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  84. object = _getPrototypeOf(object);
  85. if (null === object) {
  86. break
  87. }
  88. }
  89. return object
  90. }
  91. function _inherits(subClass, superClass) {
  92. if ("function" !== typeof superClass && null !== superClass) {
  93. throw new TypeError("Super expression must either be null or a function")
  94. }
  95. subClass.prototype = Object.create(superClass && superClass.prototype, {
  96. constructor: {
  97. value: subClass,
  98. writable: true,
  99. configurable: true
  100. }
  101. });
  102. Object.defineProperty(subClass, "prototype", {
  103. writable: false
  104. });
  105. if (superClass) {
  106. _setPrototypeOf(subClass, superClass)
  107. }
  108. }
  109. function _setPrototypeOf(o, p) {
  110. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function(o, p) {
  111. o.__proto__ = p;
  112. return o
  113. };
  114. return _setPrototypeOf(o, p)
  115. }
  116. function _createSuper(Derived) {
  117. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  118. return function() {
  119. var result, Super = _getPrototypeOf(Derived);
  120. if (hasNativeReflectConstruct) {
  121. var NewTarget = _getPrototypeOf(this).constructor;
  122. result = Reflect.construct(Super, arguments, NewTarget)
  123. } else {
  124. result = Super.apply(this, arguments)
  125. }
  126. return _possibleConstructorReturn(this, result)
  127. }
  128. }
  129. function _possibleConstructorReturn(self, call) {
  130. if (call && ("object" === _typeof(call) || "function" === typeof call)) {
  131. return call
  132. } else {
  133. if (void 0 !== call) {
  134. throw new TypeError("Derived constructors may only return object or undefined")
  135. }
  136. }
  137. return _assertThisInitialized(self)
  138. }
  139. function _assertThisInitialized(self) {
  140. if (void 0 === self) {
  141. throw new ReferenceError("this hasn't been initialised - super() hasn't been called")
  142. }
  143. return self
  144. }
  145. function _isNativeReflectConstruct() {
  146. if ("undefined" === typeof Reflect || !Reflect.construct) {
  147. return false
  148. }
  149. if (Reflect.construct.sham) {
  150. return false
  151. }
  152. if ("function" === typeof Proxy) {
  153. return true
  154. }
  155. try {
  156. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
  157. return true
  158. } catch (e) {
  159. return false
  160. }
  161. }
  162. function _getPrototypeOf(o) {
  163. _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function(o) {
  164. return o.__proto__ || Object.getPrototypeOf(o)
  165. };
  166. return _getPrototypeOf(o)
  167. }
  168. var DIAGRAM_RIGHT_PANEL_CLASS = "dx-diagram-right-panel";
  169. var DIAGRAM_RIGHT_PANEL_BEGIN_GROUP_CLASS = "dx-diagram-right-panel-begin-group";
  170. var DiagramRightPanel = function(_DiagramPanel) {
  171. _inherits(DiagramRightPanel, _DiagramPanel);
  172. var _super = _createSuper(DiagramRightPanel);
  173. function DiagramRightPanel() {
  174. _classCallCheck(this, DiagramRightPanel);
  175. return _super.apply(this, arguments)
  176. }
  177. _createClass(DiagramRightPanel, [{
  178. key: "_init",
  179. value: function() {
  180. _get(_getPrototypeOf(DiagramRightPanel.prototype), "_init", this).call(this);
  181. this.bar = new OptionsDiagramBar(this);
  182. this._valueConverters = {}
  183. }
  184. }, {
  185. key: "_initMarkup",
  186. value: function() {
  187. _get(_getPrototypeOf(DiagramRightPanel.prototype), "_initMarkup", this).call(this);
  188. this.$element().addClass(DIAGRAM_RIGHT_PANEL_CLASS);
  189. var $accordion = (0, _renderer2.default)("<div>").appendTo(this.$element());
  190. this._renderAccordion($accordion)
  191. }
  192. }, {
  193. key: "_getAccordionDataSource",
  194. value: function() {
  195. return [{
  196. title: "Page Properties",
  197. onTemplate: function(widget, $element) {
  198. return widget._renderOptions($element)
  199. }
  200. }]
  201. }
  202. }, {
  203. key: "_renderAccordion",
  204. value: function($container) {
  205. var _this = this;
  206. this._accordionInstance = this._createComponent($container, _accordion2.default, {
  207. multiple: true,
  208. collapsible: true,
  209. displayExpr: "title",
  210. dataSource: this._getAccordionDataSource(),
  211. itemTemplate: function(data, index, $element) {
  212. return data.onTemplate(_this, $element)
  213. }
  214. })
  215. }
  216. }, {
  217. key: "_renderOptions",
  218. value: function($container) {
  219. var _this2 = this;
  220. this._formInstance = this._createComponent($container, _form2.default, {
  221. items: _uiDiagram2.default.getOptions().map(function(item) {
  222. return (0, _extend.extend)(true, {
  223. editorType: item.widget,
  224. dataField: item.command.toString(),
  225. cssClass: item.beginGroup && DIAGRAM_RIGHT_PANEL_BEGIN_GROUP_CLASS,
  226. label: {
  227. text: item.text
  228. },
  229. options: {
  230. text: item.text,
  231. hint: item.hint,
  232. icon: item.icon,
  233. onInitialized: function(e) {
  234. return _this2._onToolbarItemInitialized(e.component, item.command)
  235. }
  236. }
  237. }, _this2._createWidgetOptions(item))
  238. }),
  239. onFieldDataChanged: function(e) {
  240. return _this2._onDiagramOptionChanged(e.dataField, e.value)
  241. }
  242. })
  243. }
  244. }, {
  245. key: "_createWidgetOptions",
  246. value: function(item) {
  247. if (item.getValue && item.setValue) {
  248. this._valueConverters[item.command] = {
  249. getValue: item.getValue,
  250. setValue: item.setValue
  251. }
  252. }
  253. if ("dxSelectBox" === item.widget) {
  254. return {
  255. editorOptions: {
  256. dataSource: item.items,
  257. displayExpr: "title",
  258. valueExpr: "value"
  259. }
  260. }
  261. }
  262. }
  263. }, {
  264. key: "_onDiagramOptionChanged",
  265. value: function(key, value) {
  266. if (!this._updateLocked && void 0 !== value) {
  267. var valueConverter = this._valueConverters[key];
  268. if (valueConverter) {
  269. value = valueConverter.getValue(value)
  270. }
  271. this.bar.raiseBarCommandExecuted(parseInt(key), value)
  272. }
  273. }
  274. }, {
  275. key: "_setItemValue",
  276. value: function(key, value) {
  277. var valueConverter = this._valueConverters[key];
  278. if (valueConverter) {
  279. value = valueConverter.setValue(value)
  280. }
  281. this._updateLocked = true;
  282. this._formInstance.updateData(key.toString(), value);
  283. this._updateLocked = false
  284. }
  285. }, {
  286. key: "_setItemSubItems",
  287. value: function(key, items) {
  288. this._updateLocked = true;
  289. var editorInstance = this._formInstance.getEditor(key.toString());
  290. editorInstance.option("items", items.map(function(item) {
  291. var value = "object" === _typeof(item.value) ? JSON.stringify(item.value) : item.value;
  292. return {
  293. value: value,
  294. title: item.text
  295. }
  296. }));
  297. this._updateLocked = false
  298. }
  299. }, {
  300. key: "_setEnabled",
  301. value: function(enabled) {
  302. this._formInstance.option("disabled", !enabled)
  303. }
  304. }, {
  305. key: "_getDefaultOptions",
  306. value: function() {
  307. return (0, _extend.extend)(_get(_getPrototypeOf(DiagramRightPanel.prototype), "_getDefaultOptions", this).call(this), {
  308. container: null
  309. })
  310. }
  311. }]);
  312. return DiagramRightPanel
  313. }(_diagram2.default);
  314. var OptionsDiagramBar = function(_DiagramBar) {
  315. _inherits(OptionsDiagramBar, _DiagramBar);
  316. var _super2 = _createSuper(OptionsDiagramBar);
  317. function OptionsDiagramBar() {
  318. _classCallCheck(this, OptionsDiagramBar);
  319. return _super2.apply(this, arguments)
  320. }
  321. _createClass(OptionsDiagramBar, [{
  322. key: "getCommandKeys",
  323. value: function() {
  324. return _uiDiagram2.default.getOptions().map(function(c) {
  325. return c.command
  326. })
  327. }
  328. }, {
  329. key: "setItemValue",
  330. value: function(key, value) {
  331. this._owner._setItemValue(key, value)
  332. }
  333. }, {
  334. key: "setEnabled",
  335. value: function(enabled) {
  336. this._owner._setEnabled(enabled)
  337. }
  338. }, {
  339. key: "setItemSubItems",
  340. value: function(key, items) {
  341. this._owner._setItemSubItems(key, items)
  342. }
  343. }]);
  344. return OptionsDiagramBar
  345. }(_diagram_bar2.default);
  346. module.exports = DiagramRightPanel;