'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /* *+------------------------------------------------------------------------+ *| Licensed Materials - Property of IBM *| IBM Cognos Products: Dashboard *| (C) Copyright IBM Corp. 2018, 2020 *| *| US Government Users Restricted Rights - Use, duplication or disclosure *| restricted by GSA ADP Schedule Contract with IBM Corp. *+------------------------------------------------------------------------+ */ define(['jquery', 'underscore', '../../../lib/@waca/core-client/js/core-client/utils/ClassFactory', '../../layout/views/LayoutBaseView', 'react', 'react-dom', '../../layout/authoring/views/feature/CommonAuthoringFeature'], function ($, _, ClassFactory, LayoutBaseView, React, ReactDOM, CommonAuthoringFeature) { var makeReactLayoutClass = function makeReactLayoutClass(data) { var ReactLayout = null; ReactLayout = LayoutBaseView.extend({ init: function init(options) { ReactLayout.inherited('init', this, arguments); this.model = options.model; this.content = options.content; this.layoutController = options.layoutController; this.services = options.services; this.commonAuthoringFeature = new CommonAuthoringFeature(this); }, onShow: function onShow() { ReactLayout.inherited('onShow', this, arguments); if (this.layoutController) { var className = data.type + '-react-layout-view'; var $root = null; if (this.domNode) { $root = $(this.domNode); } else { $root = this.layoutController.$el.find('.' + className); } if ($root.length > 0) { var existingDomNodes = this._collectExistingItemNodes($root); ReactDOM.render(React.createElement(data.Component, { items: this.model ? this.model.items : [], model: this.model, services: this.services, layoutController: this.layoutController }, null), $root.get(0)); this._repositionExistingItemNodes($root, existingDomNodes); } } }, _collectExistingItemNodes: function _collectExistingItemNodes($root) { var existingDomNodes = []; if (this.model && this.model.items) { _.each(this.model.items, function (item) { var $node = $root.find('#' + item.id); if ($node.length) { existingDomNodes.push({ item: item, node: $node[0] }); } }); } return existingDomNodes; }, _repositionExistingItemNodes: function _repositionExistingItemNodes($root, existingDomNodes) { _.each(existingDomNodes, function (o) { var $stub = $root.find('#' + o.item.id + '_stub'); if ($stub.length) { $stub.append(o.node); } }); }, add: function add() /*layoutView, insertBeforeId*/{ //no-op - expected by CommonAuthoringFeature.onModelAddItem }, destroy: function destroy() {} }); ReactLayout.getTemplate = function () { return ['