Built files from Bizgaze WebServer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

formatpainter.js 95KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520
  1. var Unibase;
  2. (function (Unibase) {
  3. let Apps;
  4. (function (Apps) {
  5. let Collaboration;
  6. (function (Collaboration) {
  7. let Components;
  8. (function (Components) {
  9. let Sheets;
  10. (function (Sheets) {
  11. class FormatPainter {
  12. constructor() {
  13. this.hederText = {};
  14. this.isDrag = false;
  15. this.isScroll = false;
  16. this.isLeftScroll = false;
  17. this.isTopScroll = false;
  18. this.isVertical = false;
  19. this.side = -1;
  20. this.isEdit = false;
  21. this.isCellDrag = false;
  22. this.isCellDragged = false;
  23. this.isCellEdit = false;
  24. }
  25. init(base) {
  26. this.base = base;
  27. this.ssObj = base.ssObj;
  28. this.util = Unibase.Apps.Collaboration.Components.Common.Util.Instance();
  29. this.initProp();
  30. }
  31. initProp() {
  32. this.selectFn = this.selected.bind(this);
  33. this.ssObj.addEventListener("select", this.selectFn);
  34. this.createdFn = this.created.bind(this);
  35. this.ssObj.addEventListener("created", this.createdFn);
  36. this.initialLoadFn = this.initialLoad.bind(this);
  37. this.ssObj.on("initialLoad", this.initialLoadFn);
  38. this.ssObj.on("activeSheetChanged", this.activeSheetChanged, this);
  39. this.ssObj.on("mouseDown", this.mouseDown, this);
  40. }
  41. destroy() {
  42. this.ssObj.removeEventListener("select", this.selectFn);
  43. this.ssObj.removeEventListener("created", this.createdFn);
  44. this.ssObj.off("initialLoad", this.initialLoadFn);
  45. this.ssObj.off("activeSheetChanged", this.activeSheetChanged);
  46. this.ssObj.off("mouseDown", this.mouseDown);
  47. ej.base.EventHandler.remove(this.ssObj.element, 'mousemove', this.mouseMoveHandler);
  48. ej.base.EventHandler.remove(this.ssObj.element, 'mouseup', this.mouseUp);
  49. }
  50. activeSheetChanged() {
  51. if (this.isClicked) {
  52. this.hideFPBdr();
  53. setTimeout(() => {
  54. if (this.activesheet === this.ssObj.biz.getActiveSheet()) {
  55. this.updateFPBdr();
  56. }
  57. }, 650);
  58. setTimeout(() => {
  59. this.ssObj.element.querySelector('#' + this.ssObj.element.id + '_formatpainter').classList.add('biz-fp-color');
  60. }, 50);
  61. }
  62. }
  63. createFPBdr() {
  64. if (!this.ssObj.element.getElementsByClassName('biz-fp')[0]) {
  65. this.element = document.createElement('div');
  66. this.element.classList.add('biz-fp');
  67. this.element.appendChild(ej.base.createElement('div', { className: 'e-top' }));
  68. this.element.appendChild(ej.base.createElement('div', { className: 'e-bottom' }));
  69. this.element.appendChild(ej.base.createElement('div', { className: 'e-left' }));
  70. this.element.appendChild(ej.base.createElement('div', { className: 'e-right' }));
  71. let content = this.ssObj.element.getElementsByClassName('e-sheet-content')[0];
  72. content.appendChild(this.element);
  73. }
  74. this.element.classList.remove('biz-hide');
  75. }
  76. updateFPBdr() {
  77. if (this.isClicked) {
  78. this.createFPBdr();
  79. let sel = this.ssObj.element.getElementsByClassName('e-selection')[0];
  80. let activecell = this.ssObj.element.getElementsByClassName('e-active-cell')[0];
  81. let selection = sel.classList.contains('e-hide') ? activecell : sel;
  82. let offset = selection.getBoundingClientRect();
  83. this.element.style.top = selection.style.top;
  84. this.element.style.left = selection.style.left;
  85. this.element.style.width = offset.width + 'px';
  86. this.element.style.height = offset.height + 'px';
  87. }
  88. }
  89. hideFPBdr() {
  90. let ele = this.ssObj.element.getElementsByClassName('biz-fp')[0];
  91. if (ele) {
  92. ele.classList.add('biz-hide');
  93. }
  94. }
  95. mouseDown(e) {
  96. let target = ej.base.closest(e.target, '.biz-icon-painter');
  97. if (target) {
  98. this.isClicked = true;
  99. this.ssObj.element.querySelector('#' + this.ssObj.element.id + '_formatpainter').classList.add('biz-fp-color');
  100. this.updateFPBdr();
  101. }
  102. if (this.splitDlgObj && !this.splitDlgObj.isDestroyed) {
  103. let cbox = ej.base.closest(e.target, '.e-checkbox-wrapper');
  104. if (cbox) {
  105. let isRefresh = true;
  106. let tickicon = cbox.firstElementChild;
  107. tickicon.classList.contains('e-check') ? tickicon.classList.remove('e-check') : tickicon.classList.add('e-check');
  108. if (cbox.classList.contains('biz-st-other')) {
  109. this.inputObj.enabled = tickicon.classList.contains('e-check');
  110. if (this.inputObj.value && this.inputObj.value.length) {
  111. isRefresh = false;
  112. }
  113. }
  114. isRefresh && this.refreshST();
  115. }
  116. }
  117. this.mdown(e);
  118. this.mdown2(e);
  119. }
  120. initialLoad() {
  121. let getRibbonItemsFn = this.ssObj.ribbonModule.getRibbonItems.bind(this.ssObj.ribbonModule);
  122. this.ssObj.ribbonModule.getRibbonItems = () => {
  123. let items = getRibbonItemsFn();
  124. let home = items[0].content;
  125. let item = { id: this.ssObj.element.id + '_formatpainter', prefixIcon: "biz-icon-painter", tooltipText: "Format Painter" };
  126. home.splice(6, 0, item);
  127. item = { template: this.getRotationElem(), id: this.ssObj.element.id + '_text_rotation', tooltipText: "Text rotation" };
  128. home.splice(27, 0, item);
  129. return items;
  130. };
  131. }
  132. isSingleCellSel(ranges) {
  133. if (ranges[0] === ranges[2] && ranges[1] === ranges[3]) {
  134. return true;
  135. }
  136. return false;
  137. }
  138. applyFormatPaint(srcRange, destRange, srcSheetIndex) {
  139. let srcSheet = this.ssObj.sheets[srcSheetIndex];
  140. this.formatIndexes = this.base.getIndexesFromAddress(destRange);
  141. this.rangeIndexes = this.base.getIndexesFromAddress(srcRange);
  142. let r = -1;
  143. let c = -1;
  144. let sheet = this.ssObj.biz.getActiveSheet();
  145. let values = [];
  146. for (let i = this.rangeIndexes[0]; i <= this.rangeIndexes[2]; i++) {
  147. let row = [];
  148. for (let j = this.rangeIndexes[1]; j <= this.rangeIndexes[3]; j++) {
  149. let obj = ej.base.extend({}, ej.spreadsheet.getCell(i, j, sheet));
  150. row.push(obj);
  151. }
  152. values.push(row);
  153. }
  154. if (this.isSingleCellSel(this.formatIndexes)) {
  155. r = this.formatIndexes[0] - 1;
  156. c = this.formatIndexes[1] - 1;
  157. for (let i = this.rangeIndexes[0]; i <= this.rangeIndexes[2]; i++) {
  158. r++;
  159. c = this.formatIndexes[1] - 1;
  160. let row = values.shift();
  161. for (let j = this.rangeIndexes[1]; j <= this.rangeIndexes[3]; j++) {
  162. c++;
  163. let srcObj = row.shift();
  164. let destObj = ej.spreadsheet.getCell(r, c, sheet) || {};
  165. this.copyValues(srcObj, destObj, ['style', 'format', 'hyperlink', 'wrap']);
  166. this.ssObj.biz.setCell(r, c, sheet, destObj);
  167. }
  168. }
  169. this.ssObj.selectRange(this.base.generateHeaderText(this.formatIndexes[1] + 1) + (this.formatIndexes[0] + 1) + ':' + this.base.generateHeaderText(c + 1) + (r + 1));
  170. }
  171. else {
  172. let m = 0;
  173. let n = 0;
  174. for (let i = this.formatIndexes[0]; i <= this.formatIndexes[2]; i++) {
  175. if (m === values.length) {
  176. m = 0;
  177. }
  178. n = 0;
  179. for (let j = this.formatIndexes[1]; j <= this.formatIndexes[3]; j++) {
  180. if (n === values[m].length) {
  181. n = 0;
  182. }
  183. let srcObj = values[m][n];
  184. let destObj = ej.spreadsheet.getCell(i, j, sheet) || {};
  185. this.copyValues(srcObj, destObj, ['style', 'format', 'hyperlink', 'wrap']);
  186. this.ssObj.biz.setCell(i, j, sheet, destObj);
  187. n++;
  188. }
  189. m++;
  190. }
  191. }
  192. }
  193. selected(e) {
  194. this.formatRange = e.range;
  195. this.formatIndexes = this.base.getIndexesFromAddress(this.formatRange);
  196. if (this.isClicked) {
  197. this.formatRange = e.range;
  198. let args = { srcRange: this.range, destRange: this.formatRange, destIndexes: this.ssObj.biz.getIndexes(), origin: 'biz', action: 'formatpaint', srcSheetIndex: this.base.getSheetIndex(this.activesheet), sheetIndex: this.base.getSheetIndex() };
  199. this.ssObj.updateUndoRedoCollection({ name: 'bizAction', args: { action: 'formatpaint', options: args, oldCells: this.base.getCellsFromIndexes(args.destIndexes) } });
  200. this.applyFormatPaint(this.range, this.formatRange, args.srcSheetIndex);
  201. this.hideFPBdr();
  202. this.base.download.ssAutoSave({ action: "format", eventArgs: {} }, this.base, true);
  203. this.ssObj.element.querySelector('#' + this.ssObj.element.id + '_formatpainter').classList.remove('biz-fp-color');
  204. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args);
  205. }
  206. this.isClicked = false;
  207. this.range = e.range;
  208. this.activesheet = this.ssObj.biz.getActiveSheet();
  209. this.selectionSignalr();
  210. }
  211. copyValues(srcObj, destObj, props) {
  212. for (let i = 0; i < props.length; i++) {
  213. if (srcObj[props[i]]) {
  214. destObj[props[i]] = srcObj[props[i]];
  215. }
  216. else {
  217. delete destObj[props[i]];
  218. }
  219. }
  220. return destObj;
  221. }
  222. created(e) {
  223. ej.base.EventHandler.add(document.body, 'mousemove', this.mouseMoveHandler, this);
  224. ej.base.EventHandler.add(document.body, 'mouseup', this.mouseUp, this);
  225. }
  226. selectionSignalr() {
  227. let userName = Unibase.Platform.Membership.Infos.Identity.getCurrentUser().name;
  228. let args = { range: this.ssObj.biz.getActiveSheet().activeCell, userName: userName, origin: 'biz', action: 'selection', sheetIndex: this.base.getSheetIndex() };
  229. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args);
  230. }
  231. applyUserSelection(range, userName) {
  232. let ranges = this.base.getIndexesFromAddress(range);
  233. let elem = this.ssObj.element.querySelector('.biz-user-selection');
  234. elem && elem.classList.add('biz-hide');
  235. this.clearTooltip();
  236. if (this.ssObj.biz.sheetIndex !== this.base.getSheetIndex(this.ssObj.getActiveSheet())) {
  237. return;
  238. }
  239. let cell = this.ssObj.getCell(ranges[0], ranges[1]);
  240. if (!cell) {
  241. return;
  242. }
  243. !elem && this.drawUserSel(userName);
  244. this.positionUserSel(ranges[0], ranges[1], cell, userName);
  245. elem.classList.remove('biz-hide');
  246. }
  247. drawUserSel(userName) {
  248. let color = this.util.colorHash(userName);
  249. let elem = document.createElement('div');
  250. elem.classList.add('biz-user-selection');
  251. elem.style.borderColor = color.hex;
  252. let content = this.ssObj.element.getElementsByClassName('e-sheet-content')[0];
  253. content.appendChild(elem);
  254. }
  255. positionUserSel(rowIdx, colIdx, cell, userName) {
  256. let sheet = this.ssObj.biz.getActiveSheet();
  257. let freezeRow = this.ssObj.frozenRowCount(sheet);
  258. let freezeCol = this.ssObj.frozenColCount(sheet);
  259. let elem = this.ssObj.element.querySelector('.biz-user-selection');
  260. let dim = ej.spreadsheet.getCellPosition(sheet, [rowIdx, colIdx], freezeRow, freezeCol);
  261. cell.classList.add('biz-user-name');
  262. cell.setAttribute('title', userName);
  263. elem.style.width = cell.offsetWidth + 'px';
  264. elem.style.height = cell.offsetHeight + 'px';
  265. elem.style.top = dim.top + 'px';
  266. elem.style.left = dim.left + 'px';
  267. }
  268. clearTooltip() {
  269. let elem = this.ssObj.element.querySelector('.biz-user-name');
  270. if (elem) {
  271. elem.classList.remove('biz-user-name');
  272. elem.removeAttribute('title');
  273. }
  274. }
  275. deleteValues() {
  276. let rngIndexes = this.base.getIndexesFromAddress(this.range);
  277. let sheet = this.ssObj.biz.getActiveSheet();
  278. for (let i = rngIndexes[0]; i <= rngIndexes[2]; i++) {
  279. if (!sheet.rows[i]) {
  280. return;
  281. }
  282. for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) {
  283. let srcObj = ej.spreadsheet.getCell(i, j, sheet);
  284. delete srcObj.value;
  285. delete srcObj.formula;
  286. this.ssObj.biz.setCell(i, j, sheet, srcObj);
  287. }
  288. }
  289. }
  290. deleteShiftUp(range) {
  291. let args = { range: this.base.ssObj.biz.getRange(), action: 'deleteshiftup', origin: 'biz', sheetIndex: this.base.getSheetIndex() };
  292. this.ssObj.updateUndoRedoCollection({ name: 'bizAction', args: { action: 'deleteshiftup', range: args.range, indexes: this.base.ssObj.biz.getIndexes(), oldCells: this.base.getCellsFromIndexes(this.base.ssObj.biz.getIndexes()) } });
  293. this.applyDeleteShiftUp(range, args);
  294. var selectedRange = this.base.ssObj.getActiveSheet().selectedRange;
  295. this.base.ssObj.selectRange(selectedRange);
  296. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().autoSave(args);
  297. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args);
  298. }
  299. applyDeleteShiftUp(range, args) {
  300. let rngIndexes = this.base.getIndexesFromAddress(range);
  301. let sheet = this.ssObj.biz.getActiveSheet();
  302. let len = rngIndexes[2] - rngIndexes[0] + 1;
  303. for (let i = rngIndexes[0]; i <= sheet.rows.length; i++) {
  304. if (!this.ssObj.biz.isRowAvailable(i + len, sheet)) {
  305. if (this.ssObj.biz.isRowAvailable(i, sheet)) {
  306. for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) {
  307. this.ssObj.biz.setCell(i, j, sheet, {});
  308. delete sheet.rows[i].cells[j];
  309. }
  310. }
  311. continue;
  312. }
  313. else {
  314. for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) {
  315. let destObj = ej.spreadsheet.getCell(i + len, j, sheet);
  316. let srcObj = ej.spreadsheet.getCell(i, j, sheet);
  317. if (destObj) {
  318. destObj = ej.base.extend({}, destObj);
  319. srcObj = destObj;
  320. this.ssObj.biz.setCell(i, j, sheet, srcObj);
  321. }
  322. else {
  323. if (srcObj) {
  324. this.ssObj.biz.setCell(i, j, sheet, {});
  325. delete sheet.rows[i].cells[j];
  326. }
  327. }
  328. }
  329. }
  330. }
  331. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().autoSave(args);
  332. }
  333. deleteShiftLeft(range) {
  334. let args = { range: this.base.ssObj.biz.getRange(), action: 'deleteshiftleft', origin: 'biz', sheetIndex: this.base.getSheetIndex() };
  335. this.ssObj.updateUndoRedoCollection({ name: 'bizAction', args: { action: 'deleteshiftleft', range: args.range, indexes: this.base.ssObj.biz.getIndexes(), oldCells: this.base.getCellsFromIndexes(this.base.ssObj.biz.getIndexes()) } });
  336. this.applyDeleteShiftLeft(range);
  337. var selectedRange = this.base.ssObj.getActiveSheet().selectedRange;
  338. this.base.ssObj.selectRange(selectedRange);
  339. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().autoSave(args);
  340. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args);
  341. }
  342. applyDeleteShiftLeft(range) {
  343. let rngIndexes = this.base.getIndexesFromAddress(range);
  344. let sheet = this.ssObj.biz.getActiveSheet();
  345. let len = rngIndexes[3] - rngIndexes[1] + 1;
  346. for (let i = rngIndexes[0]; i <= rngIndexes[2]; i++) {
  347. if (this.ssObj.biz.isRowAvailable(i, sheet)) {
  348. for (let j = rngIndexes[1]; j <= sheet.rows[i].cells.length; j++) {
  349. let destObj = ej.spreadsheet.getCell(i, j + len, sheet);
  350. let srcObj = ej.spreadsheet.getCell(i, j, sheet);
  351. if (destObj) {
  352. destObj = ej.base.extend({}, destObj);
  353. srcObj = destObj;
  354. this.ssObj.biz.setCell(i, j, sheet, srcObj);
  355. }
  356. else {
  357. if (srcObj) {
  358. this.ssObj.biz.setCell(i, j, sheet, {});
  359. delete sheet.rows[i].cells[j];
  360. }
  361. }
  362. }
  363. }
  364. }
  365. }
  366. insertShiftDown(range) {
  367. let args = { range: this.base.ssObj.biz.getRange(), action: 'insertshiftdown', origin: 'biz', sheetIndex: this.base.getSheetIndex(), usedRange: this.base.ssObj.getActiveSheet().usedRange };
  368. this.ssObj.updateUndoRedoCollection({ name: 'bizAction', args: { action: 'insertshiftdown', range: args.range, indexes: this.base.ssObj.biz.getIndexes() } });
  369. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().autoSave(args);
  370. this.applyInsertShiftDown(range, args);
  371. var selectedRange = this.base.ssObj.getActiveSheet().selectedRange;
  372. this.base.ssObj.selectRange(selectedRange);
  373. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args);
  374. }
  375. applyInsertShiftDown(range, args) {
  376. let rngIndexes = this.base.getIndexesFromAddress(range);
  377. let sheet = this.ssObj.biz.getActiveSheet();
  378. let len = rngIndexes[2] - rngIndexes[0] + 1;
  379. for (let i = sheet.rows.length + len - 1; i >= rngIndexes[0]; i--) {
  380. if (i <= rngIndexes[2]) {
  381. for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) {
  382. this.ssObj.biz.setCell(i, j, sheet, {});
  383. delete sheet.rows[i].cells[j];
  384. }
  385. continue;
  386. }
  387. if (!this.ssObj.biz.isRowAvailable(i - len, sheet)) {
  388. if (this.ssObj.biz.isRowAvailable(i, sheet)) {
  389. for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) {
  390. this.ssObj.biz.setCell(i, j, sheet, {});
  391. delete sheet.rows[i].cells[j];
  392. }
  393. }
  394. continue;
  395. }
  396. else {
  397. for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) {
  398. let destObj = ej.spreadsheet.getCell(i - len, j, sheet);
  399. let srcObj = ej.spreadsheet.getCell(i, j, sheet);
  400. if (destObj) {
  401. destObj = ej.base.extend({}, destObj);
  402. srcObj = destObj;
  403. this.ssObj.biz.setCell(i, j, sheet, srcObj);
  404. }
  405. else {
  406. if (srcObj) {
  407. this.ssObj.biz.setCell(i, j, sheet, {});
  408. delete sheet.rows[i].cells[j];
  409. }
  410. }
  411. }
  412. }
  413. }
  414. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args);
  415. }
  416. insertShiftRight(range) {
  417. let args = { range: this.base.ssObj.biz.getRange(), action: 'insertshiftright', origin: 'biz', sheetIndex: this.base.getSheetIndex() };
  418. this.ssObj.updateUndoRedoCollection({ name: 'bizAction', args: { action: 'insertshiftright', range: args.range, indexes: this.base.ssObj.biz.getIndexes() } });
  419. this.applyInsertShiftRight(range);
  420. var selectedRange = this.base.ssObj.getActiveSheet().selectedRange;
  421. this.base.ssObj.selectRange(selectedRange);
  422. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().autoSave(args);
  423. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args);
  424. }
  425. applyInsertShiftRight(range) {
  426. let rngIndexes = this.base.getIndexesFromAddress(range);
  427. let sheet = this.ssObj.biz.getActiveSheet();
  428. let len = rngIndexes[3] - rngIndexes[1] + 1;
  429. for (let i = rngIndexes[0]; i <= rngIndexes[2]; i++) {
  430. if (this.ssObj.biz.isRowAvailable(i, sheet)) {
  431. for (let j = sheet.rows[i].cells.length + len - 1; j >= rngIndexes[1]; j--) {
  432. let destObj = ej.spreadsheet.getCell(i, j - len, sheet);
  433. let srcObj = ej.spreadsheet.getCell(i, j, sheet);
  434. if (j <= rngIndexes[3]) {
  435. this.ssObj.biz.setCell(i, j, sheet, {});
  436. delete sheet.rows[i].cells[j];
  437. continue;
  438. }
  439. if (destObj) {
  440. destObj = ej.base.extend({}, destObj);
  441. srcObj = destObj;
  442. this.ssObj.biz.setCell(i, j, sheet, srcObj);
  443. }
  444. else {
  445. if (srcObj) {
  446. this.ssObj.biz.setCell(i, j, sheet, {});
  447. delete sheet.rows[i].cells[j];
  448. }
  449. }
  450. }
  451. }
  452. }
  453. }
  454. renderConfirmDlg() {
  455. let elem = this.ssObj.element.querySelector('.biz-delete-con') || ej.base.createElement('div', { className: 'biz-delete-con' });
  456. this.confirmObj = new ej.popups.Dialog({
  457. target: this.ssObj.element,
  458. content: 'Are you sure you want to delete this sheet',
  459. isModal: true,
  460. width: '400px',
  461. animationSettings: { effect: 'None' },
  462. showCloseIcon: false,
  463. buttons: [{
  464. click: this.deleteActiveSheet.bind(this),
  465. buttonModel: { content: 'OK', isPrimary: true }
  466. },
  467. {
  468. click: this.destroyConfirm.bind(this),
  469. buttonModel: { content: 'Cancel' }
  470. }]
  471. });
  472. this.ssObj.element.appendChild(elem);
  473. this.confirmObj.appendTo(elem);
  474. }
  475. deleteActiveSheet() {
  476. this.destroyConfirm();
  477. let sheetIdx = this.base.getSheetIndex();
  478. this.base.ssObj.delete(sheetIdx, sheetIdx, "Sheet");
  479. Unibase.Apps.Collaboration.Components.Common.Download.Instance().ssAutoSave({ action: "removeSheet", sheetIndex: sheetIdx }, this.base, true);
  480. }
  481. destroyConfirm() {
  482. this.confirmObj.destroy();
  483. }
  484. renderAlert(content) {
  485. let alertElem = this.ssObj.element.querySelector('.biz-split-alert') || ej.base.createElement('div', { className: 'biz-split-alert' });
  486. this.alertObj = new ej.popups.Dialog({
  487. target: this.ssObj.element,
  488. content: content,
  489. isModal: true,
  490. width: '400px',
  491. animationSettings: { effect: 'None' },
  492. showCloseIcon: false,
  493. buttons: [{
  494. click: this.destroyAlert.bind(this),
  495. buttonModel: { content: 'OK', isPrimary: true }
  496. }]
  497. });
  498. this.ssObj.element.appendChild(alertElem);
  499. this.alertObj.appendTo(alertElem);
  500. }
  501. destroyAlert() {
  502. this.alertObj.destroy();
  503. }
  504. appenChildrens(parent, elements) {
  505. for (let i = 0; i < elements.length; i++) {
  506. parent.appendChild(elements[i]);
  507. }
  508. }
  509. createCBoxWithWrap(elem) {
  510. let div = ej.base.createElement('div');
  511. div.appendChild(elem);
  512. return div;
  513. }
  514. initSplitDialog() {
  515. let rngIndexes = this.ssObj.biz.getIndexes();
  516. if (rngIndexes[1] !== rngIndexes[3]) {
  517. this.renderAlert('Text to Columns feature can convert only one column at a time, Try again selecting cells in one column only');
  518. return;
  519. }
  520. this.values = [];
  521. this.hasValue = false;
  522. this.setData();
  523. this.hasValue ? this.renderSplitDialog() : this.renderAlert('No data was selected to parse');
  524. }
  525. renderSplitDialog() {
  526. let dlgElem = ej.base.createElement('div', { className: 'biz-split-dlg' });
  527. this.tabElem = this.createCBoxWithWrap(ej.buttons.createCheckBox(this.ssObj.createElement, false, { checked: false, label: 'Tab', cssClass: 'biz-st-cbox' }));
  528. this.semicolonElem = this.createCBoxWithWrap(ej.buttons.createCheckBox(this.ssObj.createElement, false, { checked: false, label: 'Semicolon', cssClass: 'biz-st-cbox' }));
  529. this.commaElem = this.createCBoxWithWrap(ej.buttons.createCheckBox(this.ssObj.createElement, false, { checked: false, label: 'Comma', cssClass: 'biz-st-cbox' }));
  530. this.spaceElem = this.createCBoxWithWrap(ej.buttons.createCheckBox(this.ssObj.createElement, false, { checked: false, label: 'Space', cssClass: 'biz-st-cbox' }));
  531. this.otherElem = this.createCBoxWithWrap(ej.buttons.createCheckBox(this.ssObj.createElement, false, { checked: false, label: 'Other', cssClass: 'biz-st-cbox biz-st-other' }));
  532. let other = ej.base.createElement('div');
  533. this.otherElem.style.display = 'inline';
  534. other.appendChild(this.otherElem);
  535. this.otherInElem = ej.base.createElement('input', { attrs: { type: 'text' }, className: 'biz-sp-input' });
  536. other.appendChild(this.otherInElem);
  537. this.appenChildrens(dlgElem, [
  538. ej.base.createElement('div', { innerHTML: 'Delimiters', styles: 'margin-bottom: 10px;' }), this.tabElem, this.semicolonElem,
  539. this.commaElem, this.spaceElem, other, ej.base.createElement('div', { innerHTML: 'Data Preview', styles: 'margin: 10px 0;' }),
  540. ej.base.createElement('div', { id: this.ssObj.element.id + '_split' })
  541. ]);
  542. this.ssObj.element.appendChild(dlgElem);
  543. this.inputObj = new ej.inputs.TextBox({
  544. width: '50px',
  545. floatLabelType: 'Auto',
  546. enabled: false,
  547. change: this.refreshST.bind(this)
  548. });
  549. this.inputObj.appendTo(this.otherInElem);
  550. this.splitDlgObj = new ej.popups.Dialog({
  551. header: 'Convert Text to Columns',
  552. target: this.ssObj.element,
  553. animationSettings: { effect: 'None' },
  554. isModal: true,
  555. showCloseIcon: false,
  556. width: '550px',
  557. buttons: [{
  558. click: this.applySplitValues.bind(this),
  559. buttonModel: { content: 'OK', isPrimary: true }
  560. },
  561. {
  562. click: this.destroySTDialog.bind(this),
  563. buttonModel: { content: 'Cancel' }
  564. }],
  565. open: this.splitDialogOpen.bind(this),
  566. });
  567. this.splitDlgObj.appendTo(dlgElem);
  568. }
  569. splitDialogOpen() {
  570. this.detectAndUpdate();
  571. this.setSplitedData();
  572. this.renderGrid();
  573. }
  574. refreshST() {
  575. this.setSplitedData();
  576. this.refreshGrid();
  577. }
  578. refreshGrid() {
  579. let obj = this.convertDS();
  580. this.gridObj.dataSource = obj.data;
  581. this.gridObj.columns = obj.cols;
  582. this.gridObj.refreshColumns();
  583. }
  584. applySplitValues() {
  585. let indexes = this.base.ssObj.biz.getIndexes();
  586. let args = { range: this.range, stValues: JSON.parse(JSON.stringify(this.stValues)), action: 'splittext', origin: 'biz', sheetIndex: this.base.getSheetIndex() };
  587. this.ssObj.updateUndoRedoCollection({ name: 'bizAction', args: { action: 'splittext', stValues: this.stValues, range: indexes, oldCells: this.base.getCellsFromIndexes(indexes, this.stValues) } });
  588. this.applySplitText(indexes, this.stValues);
  589. this.destroySTDialog();
  590. Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args);
  591. }
  592. applySplitText(range, stValues) {
  593. let sheet = this.ssObj.biz.getActiveSheet();
  594. let cellObj;
  595. let k = 0;
  596. let l = 0;
  597. for (let i = range[0]; i <= range[2]; i++) {
  598. k = 0;
  599. for (let j = range[1]; j < range[1] + stValues[l].length; j++) {
  600. cellObj = ej.spreadsheet.getCell(i, j, sheet) || {};
  601. cellObj.value = stValues[l][k];
  602. delete cellObj.formula;
  603. this.ssObj.biz.setCell(i, j, sheet, cellObj);
  604. k++;
  605. }
  606. l++;
  607. }
  608. }
  609. destroySTDialog() {
  610. this.inputObj.destroy();
  611. this.gridObj.destroy();
  612. this.splitDlgObj.destroy();
  613. this.ssObj.element.querySelector('.biz-split-dlg').remove();
  614. }
  615. setData() {
  616. let rngIndexes = this.base.getIndexesFromAddress(this.range);
  617. let sheet = this.ssObj.biz.getActiveSheet();
  618. for (let i = rngIndexes[0]; i <= rngIndexes[2]; i++) {
  619. let cellObj = ej.spreadsheet.getCell(i, rngIndexes[1], sheet);
  620. if (cellObj && cellObj.value) {
  621. this.values.push(cellObj.value.toString());
  622. this.hasValue = true;
  623. }
  624. else {
  625. this.values.push('');
  626. }
  627. }
  628. }
  629. getOperators() {
  630. let obj = {};
  631. obj['comma'] = this.isChecked(this.commaElem);
  632. obj['semicolon'] = this.isChecked(this.semicolonElem);
  633. obj['space'] = this.isChecked(this.spaceElem);
  634. obj['tab'] = this.isChecked(this.tabElem);
  635. obj['custom'] = this.isChecked(this.otherElem) && this.inputObj.value && this.inputObj.value.length;
  636. return obj;
  637. }
  638. isChecked(ele) {
  639. return ele.firstElementChild.firstElementChild.classList.contains('e-check');
  640. }
  641. setSplitedData() {
  642. this.stValues = [];
  643. let obj = this.getOperators();
  644. let value;
  645. let res;
  646. for (let i = 0; i < this.values.length; i++) {
  647. value = this.values[i];
  648. if (obj.comma) {
  649. value = this.splitText(value, ',');
  650. }
  651. if (obj.semicolon) {
  652. value = this.splitText(value, ';');
  653. }
  654. if (obj.space) {
  655. value = this.splitText(value, ' ');
  656. }
  657. if (obj.tab) {
  658. value = this.splitText(value, '\t');
  659. }
  660. if (obj.custom) {
  661. value = this.splitText(value, this.inputObj.value);
  662. }
  663. if (Array.isArray(value)) {
  664. value = this.trimText(value);
  665. }
  666. else if (value === null || value === undefined || value === '') {
  667. value = [];
  668. }
  669. else {
  670. value = [value];
  671. }
  672. this.stValues.push(value);
  673. }
  674. }
  675. renderGrid() {
  676. let obj = this.convertDS();
  677. this.gridObj = new ej.grids.Grid({
  678. allowPaging: this.values.length > 8,
  679. pageSettings: { pageSize: 8 },
  680. dataSource: obj.data, gridLines: 'Both', allowSelection: false, rowHeight: 20,
  681. enableHover: false, columns: obj.cols,
  682. dataBound: () => {
  683. this.gridObj.autoFitColumns();
  684. },
  685. });
  686. this.gridObj.appendTo('#' + this.ssObj.element.id + '_split');
  687. }
  688. convertDS() {
  689. let data = [];
  690. let count = 0;
  691. let cols = [];
  692. for (let i = 0; i < this.stValues.length; i++) {
  693. let obj = {};
  694. for (let j = 0; j < this.stValues[i].length; j++) {
  695. obj[j] = this.stValues[i][j];
  696. if (count < this.stValues[i].length) {
  697. count = this.stValues[i].length;
  698. }
  699. }
  700. data.push(obj);
  701. }
  702. for (let i = 0; i < count; i++) {
  703. cols.push({ field: i.toString() });
  704. }
  705. return { data: data, cols: cols, width: 100 };
  706. }
  707. splitText(value, operator) {
  708. if (Array.isArray(value)) {
  709. let res = [];
  710. for (let i = 0; i < value.length; i++) {
  711. res = res.concat(this.splitText(value[i], operator));
  712. }
  713. return res;
  714. }
  715. else {
  716. return value.split(operator);
  717. }
  718. }
  719. trimText(values) {
  720. return values.filter(function (e) { return e.trim() != ''; });
  721. }
  722. detectAndUpdate() {
  723. let isComma, isSpace, isSemiColon;
  724. for (let i = 0; i < this.values.length; i++) {
  725. if (!isSemiColon && this.values[i].indexOf(';') > -1) {
  726. isSemiColon = true;
  727. this.semicolonElem.firstElementChild.firstElementChild.classList.add('e-check');
  728. }
  729. if (this.values[i].indexOf(',') > -1) {
  730. isComma = true;
  731. this.commaElem.firstElementChild.firstElementChild.classList.add('e-check');
  732. this.semicolonElem.firstElementChild.firstElementChild.classList.remove('e-check');
  733. }
  734. if (!isSpace && this.values[i].indexOf(' ') > -1) {
  735. isSpace = true;
  736. this.spaceElem.firstElementChild.firstElementChild.classList.add('e-check');
  737. this.semicolonElem.firstElementChild.firstElementChild.classList.remove('e-check');
  738. this.commaElem.firstElementChild.firstElementChild.classList.remove('e-check');
  739. }
  740. if (isSpace && isComma) {
  741. break;
  742. }
  743. }
  744. }
  745. mouseMoveHandler(e) {
  746. let target = e.target;
  747. let sheet = this.ssObj.biz.getActiveSheet();
  748. let ranges = this.base.getIndexesFromAddress(sheet.selectedRange);
  749. this.mMove1(e);
  750. }
  751. mdown(e) {
  752. let target = e.target;
  753. let sheet = this.ssObj.biz.getActiveSheet();
  754. let ranges = this.base.getIndexesFromAddress(sheet.selectedRange);
  755. }
  756. mouseUp(e) {
  757. let tab = ej.base.closest(e.target, '.biz-dd-active');
  758. if (tab) {
  759. let event = new MouseEvent("contextmenu", {
  760. bubbles: true,
  761. cancelable: false,
  762. view: window,
  763. button: 2,
  764. buttons: 0,
  765. clientX: tab.getBoundingClientRect().x,
  766. clientY: tab.getBoundingClientRect().y
  767. });
  768. if (window.CustomEvent) {
  769. tab.dispatchEvent(new CustomEvent('contextmenu'));
  770. }
  771. else if (document.createEvent) {
  772. tab.dispatchEvent(event);
  773. }
  774. else {
  775. tab.fireEvent('oncontextmenu');
  776. }
  777. tab.dispatchEvent(event);
  778. }
  779. }
  780. renderComment(ranges, isExisting) {
  781. let div = document.createElement('div');
  782. div.classList.add('biz-comment');
  783. div.setAttribute('contenteditable', 'true');
  784. div.setAttribute('rowidx', ranges[0].toString());
  785. div.setAttribute('colidx', ranges[1].toString());
  786. let sheet = this.ssObj.biz.getActiveSheet();
  787. let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {};
  788. if (cell.comment) {
  789. div.innerHTML = cell.comment;
  790. }
  791. let freezeRow = this.ssObj.frozenRowCount(sheet);
  792. let freezeCol = this.ssObj.frozenColCount(sheet);
  793. let positon = ej.spreadsheet.getCellPosition(sheet, [ranges[0], ranges[1]], freezeRow, freezeCol);
  794. let height = sheet.rows[ranges[0]] ? sheet.rows[ranges[0]].height || 20 : 20;
  795. let width = sheet.columns[ranges[1]] ? sheet.columns[ranges[1]].width || 64 : 64;
  796. let scrollTopElem = this.ssObj.element.querySelector('.e-main-panel');
  797. let scrollLeftElem = this.ssObj.getScrollElement();
  798. if (scrollTopElem.offsetHeight + scrollTopElem.scrollTop > positon.top + height + 75) {
  799. div.style.top = positon.top + 'px';
  800. }
  801. else {
  802. div.style.top = positon.top - 75 + 'px';
  803. }
  804. if (scrollLeftElem.offsetWidth + scrollLeftElem.scrollLeft > positon.left + width + 175) {
  805. div.style.left = positon.left + width + 'px';
  806. }
  807. else {
  808. div.style.left = positon.left - 175 + 'px';
  809. }
  810. let content = this.ssObj.element.querySelector('.e-sheet-content');
  811. content.appendChild(div);
  812. this.lastCmtElem = div;
  813. if (!isExisting) {
  814. this.ssObj.allowEditing = false;
  815. this.ssObj.dataBind();
  816. this.isCommentEdit = true;
  817. setTimeout(() => {
  818. div.focus();
  819. }, 0);
  820. this.renderCommentEdge(ranges, positon);
  821. }
  822. else {
  823. this.lastCmtHoverElem = div;
  824. }
  825. }
  826. commentTimer(target) {
  827. setTimeout((elem) => {
  828. if (document.activeElement !== elem) {
  829. console.log('sdaf');
  830. elem && elem.remove();
  831. this.lastCmtElem = null;
  832. }
  833. else {
  834. this.commentTimer(elem);
  835. }
  836. }, 3000, target);
  837. }
  838. renderCommentEdge(ranges, position) {
  839. let div = document.createElement('div');
  840. div.classList.add('biz-comment-edge');
  841. div.setAttribute('id', ('cmt_' + ranges[0] + '_' + ranges[1]));
  842. this.positionCommentEdge(ranges, div, position);
  843. let content = this.ssObj.element.querySelector('.e-sheet-content');
  844. content.appendChild(div);
  845. }
  846. positionCommentEdge(ranges, div, position) {
  847. let sheet = this.ssObj.biz.getActiveSheet();
  848. let height = sheet.rows[ranges[0]] ? sheet.rows[ranges[0]].height || 20 : 20;
  849. let width = sheet.columns[ranges[1]] ? sheet.columns[ranges[1]].width || 64 : 64;
  850. if (!position) {
  851. let freezeRow = this.ssObj.frozenRowCount(sheet);
  852. let freezeCol = this.ssObj.frozenColCount(sheet);
  853. position = ej.spreadsheet.getCellPosition(sheet, [ranges[0], ranges[1]], freezeRow, freezeCol);
  854. }
  855. div.style.top = position.top + 'px';
  856. div.style.left = position.left + width - 5 + 'px';
  857. }
  858. mdown2(e) {
  859. let target = e.target;
  860. if (this.lastCmtElem) {
  861. if (target !== this.lastCmtElem) {
  862. this.commentTimer(this.lastCmtElem);
  863. }
  864. this.updateComment(this.lastCmtElem);
  865. }
  866. if (target.classList.contains('biz-comment')) {
  867. this.isCommentEdit = true;
  868. this.ssObj.isEdit && this.ssObj.endEdit();
  869. this.ssObj.allowEditing = false;
  870. this.ssObj.dataBind();
  871. this.lastCmtElem = target;
  872. }
  873. else if (this.isCommentEdit) {
  874. this.isCommentEdit = false;
  875. this.ssObj.allowEditing = true;
  876. this.ssObj.dataBind();
  877. }
  878. }
  879. mMove1(e) {
  880. let target = e.target;
  881. if (target.classList.contains('e-cell') && !this.isCommentEdit) {
  882. let rowIdx = parseInt(target.parentElement.getAttribute('aria-rowindex')) - 1;
  883. let colIdx = parseInt(target.getAttribute('aria-colindex')) - 1;
  884. let sheet = this.ssObj.biz.getActiveSheet();
  885. let cell = ej.spreadsheet.getCell(rowIdx, colIdx, sheet) || {};
  886. if (cell === this.lastCmtObj) {
  887. return;
  888. }
  889. else {
  890. this.lastCmtObj = null;
  891. this.removeCommentPopup();
  892. }
  893. if (cell.comment) {
  894. this.lastCmtObj = cell;
  895. this.removeCommentPopup();
  896. this.renderComment([rowIdx, colIdx], true);
  897. }
  898. }
  899. }
  900. updateComment(target) {
  901. let rowIdx = parseInt(target.getAttribute('rowidx'));
  902. let colIdx = parseInt(target.getAttribute('colidx'));
  903. let sheet = this.ssObj.biz.getActiveSheet();
  904. let cell = ej.spreadsheet.getCell(rowIdx, colIdx, sheet) || {};
  905. cell.comment = target.innerText;
  906. this.setComment([rowIdx, colIdx], target.innerText);
  907. this.ssObj.biz.setCell(rowIdx, colIdx, sheet, cell);
  908. }
  909. removeComment(ranges) {
  910. let sheet = this.ssObj.biz.getActiveSheet();
  911. let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {};
  912. delete cell.comment;
  913. this.removeCommentPopup();
  914. this.removeCommentEdge(ranges);
  915. }
  916. removeCommentPopup() {
  917. let popup = this.ssObj.element.querySelector('.biz-comment');
  918. popup && popup.remove();
  919. }
  920. getEdgeElem(ranges) {
  921. return this.ssObj.element.querySelector('#cmt_' + ranges[0] + '_' + ranges[1]);
  922. }
  923. removeCommentEdge(ranges) {
  924. let edge = this.getEdgeElem(ranges);
  925. edge && edge.remove();
  926. }
  927. setComment(ranges, value) {
  928. let sheet = this.ssObj.biz.getActiveSheet();
  929. if (!sheet.comments) {
  930. sheet.comments = { rows: {} };
  931. }
  932. let row = sheet.comments.rows[ranges[0]];
  933. if (!row) {
  934. sheet.comments.rows[ranges[0]] = {};
  935. sheet.comments.rows[ranges[0]].cells = {};
  936. }
  937. sheet.comments.rows[ranges[0]].cells[ranges[1]] = value;
  938. }
  939. updateEdgesOnBound() {
  940. this.refreshEdges(true);
  941. }
  942. clearComment() {
  943. let addr1 = this.base.ssObj.getActiveSheet().activeCell;
  944. let ranges1 = ej.spreadsheet.getIndexesFromAddress(addr1);
  945. this.removeComment(ranges1);
  946. }
  947. insertNote() {
  948. let addr = this.base.ssObj.getActiveSheet().activeCell;
  949. let ranges = ej.spreadsheet.getIndexesFromAddress(addr);
  950. this.renderComment(ranges);
  951. }
  952. refreshEdges(fromScratch, rowIdx, colIdx, size) {
  953. let sheet = this.ssObj.biz.getActiveSheet();
  954. if (sheet.comments) {
  955. let rows = Object.keys(sheet.comments.rows);
  956. for (let i = 0; i < rows.length; i++) {
  957. let cols = Object.keys(sheet.comments.rows[rows[i]].cells);
  958. for (let j = 0; j < cols.length; j++) {
  959. let range = [parseInt(rows[i]), parseInt(cols[j])];
  960. if (size == undefined) {
  961. fromScratch ? this.renderCommentEdge(range) : this.positionCommentEdge(range, this.getEdgeElem(range));
  962. }
  963. else {
  964. let div = this.getEdgeElem(range);
  965. if (rowIdx != undefined) {
  966. range[0] > rowIdx && (div.style.top = (parseInt(div.style.top) + size) + 'px');
  967. }
  968. else {
  969. range[1] >= colIdx && (div.style.left = (parseInt(div.style.left) + size) + 'px');
  970. }
  971. }
  972. }
  973. }
  974. }
  975. }
  976. getRotationElem() {
  977. this.textRotationObj = new ej.splitbuttons.DropDownButton({
  978. cssClass: 'e-align-ddb',
  979. iconCss: 'e-icons e-left-icon',
  980. items: [{ iconCss: 'e-icons biz_rotate_0', tooltipText: 'sadfdas' }, { iconCss: 'e-icons biz_rotate_45' }, { iconCss: 'e-icons biz_rotate_-45' }, { iconCss: 'e-icons biz_rotate_90' }, { iconCss: 'e-icons biz_rotate_-90' }, { iconCss: 'biz-deg-dd' }],
  981. beforeOpen: (args) => {
  982. let children = args.element.children;
  983. let range = this.ssObj.biz.getIndexes();
  984. let sheet = this.ssObj.biz.getActiveSheet();
  985. let cellObj = ej.spreadsheet.getCell(range[0], range[1], sheet) || {};
  986. let rotation = cellObj.rotation || 0;
  987. let lastchild = args.element.lastElementChild;
  988. children[0].title = 'None';
  989. children[1].title = 'Tilt up';
  990. children[2].title = 'Tilt down';
  991. children[3].title = 'Rotate up';
  992. children[4].title = 'Rotate down';
  993. children[5].title = 'Custom angle';
  994. let elemMap = { '0': children[0], '45': children[1], '-45': children[2], '90': children[3], '-90': children[4] };
  995. elemMap[rotation.toString()] && elemMap[rotation].classList.add('e-selected');
  996. let data = ['-90', '-75', '-60', '-45', '-30', '-15', '0', '15', '30', '45', '60', '75', '90'];
  997. lastchild.innerHTML = '<input type="text" tabindex="1" id="rotate_options" />';
  998. this.textRotationddObj = new ej.dropdowns.DropDownList({
  999. dataSource: data,
  1000. width: '70px',
  1001. value: rotation.toString(),
  1002. select: (e) => {
  1003. this.setRotation(this.ssObj.biz.getIndexes(), parseInt(e.itemData.value));
  1004. this.textRotationddObj.destroy();
  1005. this.lastSelectedDeg = null;
  1006. this.textRotationObj.toggle();
  1007. },
  1008. });
  1009. this.textRotationddObj.appendTo(lastchild.firstElementChild);
  1010. lastchild.style.display = "inline-block";
  1011. lastchild.firstElementChild.style.top = "-3px";
  1012. },
  1013. select: (args) => {
  1014. this.lastSelectedDeg = args.item.iconCss;
  1015. if (args.item.iconCss !== 'biz-deg-dd') {
  1016. let action = args.item.iconCss.split('e-icons ')[1].split('biz_rotate_')[1];
  1017. this.setRotation(this.ssObj.biz.getIndexes(), parseInt(action));
  1018. }
  1019. },
  1020. beforeClose: (e) => {
  1021. if (this.lastSelectedDeg === 'biz-deg-dd') {
  1022. e.cancel = true;
  1023. }
  1024. else {
  1025. this.textRotationddObj.destroy();
  1026. }
  1027. }
  1028. });
  1029. this.textRotationObj.createElement = this.ssObj.createElement;
  1030. this.textRotationObj.appendTo(this.ssObj.createElement('button', { id: this.ssObj.element.id + '_text_rotate' }));
  1031. return this.textRotationObj.element;
  1032. }
  1033. setRotation(range, deg) {
  1034. let sheet = this.ssObj.biz.getActiveSheet();
  1035. for (let i = range[0]; i <= range[2]; i++) {
  1036. if (!sheet.rows[i]) {
  1037. return;
  1038. }
  1039. for (let j = range[1]; j <= range[3]; j++) {
  1040. let cellObj = ej.spreadsheet.getCell(i, j, sheet) || {};
  1041. if (cellObj.value) {
  1042. let td = this.ssObj.getCell(i, j);
  1043. let obj = this.generateRotElem(cellObj, deg, td);
  1044. this.ssObj.setRowHeight(obj.height, i);
  1045. td.innerHTML = '';
  1046. td.appendChild(obj.element);
  1047. }
  1048. cellObj.rotation = deg;
  1049. this.ssObj.biz.setCell(i, j, sheet, cellObj);
  1050. this.setRotationObj([i, j], deg);
  1051. }
  1052. }
  1053. this.base.autofill.updateAutofill();
  1054. }
  1055. generateRotElem(cellObj, deg, td) {
  1056. let root = ej.base.createElement('div', { className: 'biz-text-of-root' });
  1057. let text = ej.base.createElement('div', { className: 'biz-text-of' });
  1058. text.innerHTML = cellObj.value;
  1059. root.appendChild(text);
  1060. text.style.transform = 'rotate(' + (deg * -1) + 'deg)';
  1061. this.setStyles(text, td, cellObj);
  1062. document.body.appendChild(root);
  1063. let pos = text.getBoundingClientRect();
  1064. let parentPos = text.parentElement.getBoundingClientRect();
  1065. let left = (parentPos.width - pos.width) / 2;
  1066. root.remove();
  1067. root = ej.base.createElement('div', { className: 'biz-text-rotate-root' });
  1068. root.style.height = pos.height + 3 + 'px';
  1069. root.style.width = pos.width + 3 + 'px';
  1070. text = ej.base.createElement('div', { className: 'biz-text-rotate' });
  1071. text.innerHTML = cellObj.value;
  1072. this.setStyles(text, td, cellObj);
  1073. if (deg < 0) {
  1074. root.classList.add('biz-text-rev');
  1075. }
  1076. root.appendChild(text);
  1077. text.style.transform = 'rotate(' + (deg * -1) + 'deg)';
  1078. text.style.lineHeight = pos.height + 3 + 'px';
  1079. text.style.marginLeft = left * -1 + 2 + 'px';
  1080. return { element: root, height: pos.height + 2, width: pos.width + 2 };
  1081. }
  1082. setStyles(element, td, cellObj) {
  1083. let styles = ['fontFamily', 'fontSize', 'fontWeight'];
  1084. let computed = getComputedStyle(td);
  1085. styles.forEach((s) => {
  1086. element.style[s] = computed[s];
  1087. });
  1088. cellObj.style && Object.keys(cellObj.style).forEach((s) => {
  1089. element.style[s] = cellObj.style[s];
  1090. });
  1091. }
  1092. removeRotation(ranges) {
  1093. let sheet = this.ssObj.biz.getActiveSheet();
  1094. let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {};
  1095. delete cell.rotation;
  1096. }
  1097. setRotationObj(ranges, value) {
  1098. let sheet = this.ssObj.biz.getActiveSheet();
  1099. if (!sheet.rotation) {
  1100. sheet.rotation = { rows: {} };
  1101. }
  1102. let row = sheet.rotation.rows[ranges[0]];
  1103. if (!row) {
  1104. sheet.rotation.rows[ranges[0]] = {};
  1105. sheet.rotation.rows[ranges[0]].cells = {};
  1106. }
  1107. sheet.rotation.rows[ranges[0]].cells[ranges[1]] = value;
  1108. }
  1109. bfCellRender(args) {
  1110. this.bfCellRender1(args);
  1111. }
  1112. cellEdit(args) {
  1113. let editElem = this.ssObj.element.querySelector('.e-spreadsheet-edit');
  1114. this.isFormulaEdit = false;
  1115. let content = this.ssObj.element.querySelector('.e-sheet-content');
  1116. let newElem = ej.base.createElement('div', { spellcheck: 'false', className: 'biz-m-edit', id: this.ssObj.element.id + '_rte' });
  1117. let sheet = this.ssObj.biz.getActiveSheet();
  1118. let ranges = this.ssObj.biz.getIndexes();
  1119. let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {};
  1120. this.prevEditStyle = cell.style ? JSON.parse(JSON.stringify(cell.style)) : null;
  1121. let formatValue = cell.value || '';
  1122. let isFormat = !this.isSingleFormat(formatValue);
  1123. let formula = cell.formula && cell.formula.length;
  1124. if (isFormat && !formula) {
  1125. editElem.textContent = "";
  1126. }
  1127. newElem.style.top = (parseInt(editElem.style.top)) + 'px';
  1128. newElem.style.left = (parseInt(editElem.style.left, 10)) + 'px';
  1129. newElem.style.minWidth = editElem.style.minWidth;
  1130. newElem.style.maxWidth = editElem.style.maxWidth;
  1131. newElem.style.minHeight = editElem.style.minHeight;
  1132. newElem.style.maxHeight = editElem.style.maxHeight;
  1133. newElem.setAttribute('spellcheck', 'false');
  1134. content.appendChild(newElem);
  1135. this.rteObj = new ej.richtexteditor.RichTextEditor({
  1136. cssClass: 'biz-rte',
  1137. fontFamily: {
  1138. default: 'Calibri',
  1139. },
  1140. fontSize: {
  1141. default: '11pt'
  1142. },
  1143. width: 'auto',
  1144. height: '17px',
  1145. toolbarSettings: {
  1146. items: ['Bold', 'Italic', 'Underline', 'StrikeThrough',
  1147. 'FontName', 'FontSize', 'FontColor', 'BackgroundColor'
  1148. ]
  1149. },
  1150. created: () => {
  1151. let rteContent = newElem.querySelector('.e-content');
  1152. setTimeout(() => {
  1153. if (parseInt(editElem.style.height)) {
  1154. rteContent.style.minHeight = editElem.style.height;
  1155. rteContent.style.height = editElem.style.height + 1;
  1156. }
  1157. let value = editElem.innerHTML;
  1158. let styles = this.getStyles(cell);
  1159. if (value.length) {
  1160. this.rteObj.value = '<p style="' + styles + '">' + value + '</p>';
  1161. }
  1162. else if (isFormat) {
  1163. this.rteObj.value = formatValue.startsWith('<p') ? formatValue : '<p>' + formatValue + '</p>';
  1164. }
  1165. else {
  1166. this.setRTEStyles(cell, rteContent);
  1167. let styles = this.getStyles(cell);
  1168. this.rteObj.value = styles ? '<p style="' + styles + '">' + formatValue + '</p>' : '<p style="font-size:11pt">' + formatValue + '</p>';
  1169. }
  1170. this.rteObj.dataBind();
  1171. editElem.textContent = this.rteObj.getText();
  1172. let el = this.rteObj.element.querySelector('.e-content');
  1173. !formula && this.setCaret(el);
  1174. formula && this.rteObj.element.classList.add('biz-hide');
  1175. this.rteObj.on("toolbar-updated", this.rteToolbarUpdate, this);
  1176. }, 10);
  1177. this.rteObj.element.addEventListener('keydown', this.keyRTDown.bind(this));
  1178. this.rteObj.element.addEventListener('keyup', this.keyRTUp.bind(this));
  1179. }
  1180. });
  1181. this.rteObj.appendTo(newElem);
  1182. this.clearRTCell(ranges);
  1183. }
  1184. rteToolbarUpdate(args) {
  1185. let id = this.ssObj.element.id + '_';
  1186. let elem = this.ssObj.element.querySelector('#' + id + 'italic');
  1187. args.italic ? elem.classList.add('e-active') : elem.classList.remove('e-active');
  1188. elem = this.ssObj.element.querySelector('#' + id + 'bold');
  1189. args.bold ? elem.classList.add('e-active') : elem.classList.remove('e-active');
  1190. elem = this.ssObj.element.querySelector('#' + id + 'underline');
  1191. args.underline ? elem.classList.add('e-active') : elem.classList.remove('e-active');
  1192. elem = this.ssObj.element.querySelector('#' + id + 'line-through');
  1193. args.strikethrough ? elem.classList.add('e-active') : elem.classList.remove('e-active');
  1194. if (args.fontname) {
  1195. }
  1196. if (args.fontsize) {
  1197. }
  1198. }
  1199. cellSave(args) {
  1200. if (this.rteObj && !this.rteObj.isDestroyed) {
  1201. let editElem = this.ssObj.element.querySelector('.e-spreadsheet-edit');
  1202. let sheet = this.ssObj.biz.getActiveSheet();
  1203. let ranges = this.ssObj.biz.getIndexes();
  1204. let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {};
  1205. let rteValue = this.rteObj.getHtml();
  1206. let value = rteValue;
  1207. let hardCode = false;
  1208. let spt = value.split('<br>');
  1209. if (spt.length > 1 && spt[spt.length - 1] === '</p>') {
  1210. value = this.replaceLast('<br>', '', value);
  1211. }
  1212. if (rteValue === '<p><br></p>') {
  1213. value = editElem.textContent;
  1214. hardCode = true;
  1215. }
  1216. if (!(cell.formula && cell.formula.length)) {
  1217. if (this.isSingleFormat(value)) {
  1218. value = this.rteObj.getText();
  1219. cell.value = value;
  1220. this.ssObj.biz.setCell(ranges[0], ranges[1], sheet, cell);
  1221. }
  1222. else {
  1223. cell.style = this.prevEditStyle;
  1224. value = this.replaceAll(value, '<em>', '<i>');
  1225. value = this.replaceAll(value, '</em>', '</i>');
  1226. args.value = value;
  1227. cell.value = value;
  1228. this.ssObj.biz.setCell(ranges[0], ranges[1], sheet, cell);
  1229. this.refreshMultiCellValue(ranges);
  1230. this.base.download.ssAutoSave({ action: "imageincell", changedValues: [{ row: ranges[0], cell: ranges[1], cellinfo: cell }] }, this.base, true);
  1231. }
  1232. }
  1233. this.rteObj.off("toolbar-updated", this.rteToolbarUpdate);
  1234. this.rteObj.element.classList.remove('biz-hide');
  1235. this.rteObj.destroy();
  1236. this.rteObj.element.removeEventListener('keydown', this.keyRTDown.bind(this));
  1237. this.rteObj.element.removeEventListener('keyup', this.keyRTUp.bind(this));
  1238. this.ssObj.element.querySelector('.biz-m-edit').remove();
  1239. }
  1240. else {
  1241. if (!this.isSingleFormat(args.value)) {
  1242. this.refreshMultiCellValue(ej.spreadsheet.getIndexesFromAddress(args.address));
  1243. }
  1244. }
  1245. }
  1246. replaceLast(find, replace, string) {
  1247. var lastIndex = string.lastIndexOf(find);
  1248. if (lastIndex === -1) {
  1249. return string;
  1250. }
  1251. var beginString = string.substring(0, lastIndex);
  1252. var endString = string.substring(lastIndex + find.length);
  1253. return beginString + replace + endString;
  1254. }
  1255. escapeRegExp(string) {
  1256. return string.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
  1257. }
  1258. replaceAll(str, find, replace) {
  1259. return str.replace(new RegExp(this.escapeRegExp(find), 'g'), replace);
  1260. }
  1261. rtDragnDrop(args) {
  1262. }
  1263. keyRTDown(e) {
  1264. if (this.ssObj.isEdit) {
  1265. let editElem = this.ssObj.element.querySelector('.e-spreadsheet-edit');
  1266. if (!this.isFormulaEdit) {
  1267. let value = this.rteObj.getText();
  1268. editElem.innerHTML = value;
  1269. }
  1270. }
  1271. }
  1272. keyRTUp(e) {
  1273. if (this.ssObj.isEdit) {
  1274. let editElem = this.ssObj.element.querySelector('.e-spreadsheet-edit');
  1275. if (!this.isFormulaEdit) {
  1276. let value = this.rteObj.getText();
  1277. editElem.innerHTML = value;
  1278. if (value != '\n') {
  1279. editElem.innerHTML = value;
  1280. }
  1281. }
  1282. }
  1283. }
  1284. keyUp(e) {
  1285. if (this.ssObj.isEdit && this.isFormulaEdit) {
  1286. let editElem = this.ssObj.element.querySelector('.e-spreadsheet-edit');
  1287. if (editElem.innerHTML.charAt(0) !== '=') {
  1288. this.isFormulaEdit = false;
  1289. this.rteObj.element.classList.remove('biz-hide');
  1290. this.rteObj.value = '<p>' + editElem.innerHTML + '</p>';
  1291. let el = this.rteObj.element.querySelector('.e-content');
  1292. this.setCaret(el);
  1293. }
  1294. }
  1295. if (e.target.classList.contains('e-text-findNext-short')) {
  1296. let value = e.target.value;
  1297. let ranges = this.ssObj.biz.getIndexes();
  1298. let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], this.ssObj.biz.getActiveSheet()) || {};
  1299. let cellValue = cell.value ? cell.value : '';
  1300. if (value.length && cellValue.indexOf(value) < 0) {
  1301. let findObj = { "findOpt": "next", "isCSen": false, "isEMatch": false, "mode": "Sheet", "name": "findNext", "searchBy": "By Row", "sheetIndex": 0 };
  1302. findObj.value = value;
  1303. this.ssObj.workbookfindAndReplaceModule.findNext(findObj);
  1304. }
  1305. }
  1306. }
  1307. applyCustomCellSave(ranges, value) {
  1308. let sheet = this.ssObj.getActive;
  1309. }
  1310. actionComplete(args) {
  1311. if (args.eventArgs && args.eventArgs.address) {
  1312. this.refreshMultiCellValue(ej.spreadsheet.getIndexesFromAddress(args.eventArgs.address));
  1313. }
  1314. if (args.action == "clipboard" && args.eventArgs.copiedInfo.isCut) {
  1315. this.refreshMultiCellValue(args.eventArgs.copiedInfo.range);
  1316. }
  1317. if (args.action == "autofill") {
  1318. let rngIndexes = this.base.getIndexesFromAddress(args.eventArgs.fillRange);
  1319. this.refreshMultiCellValue(rngIndexes);
  1320. }
  1321. }
  1322. refreshMultiCellValue(ranges) {
  1323. let sheet = this.ssObj.biz.getActiveSheet();
  1324. for (let i = ranges[0]; i <= ranges[2]; i++) {
  1325. for (let j = ranges[1]; j <= ranges[3]; j++) {
  1326. let td = this.ssObj.getCell(ranges[0], ranges[1]);
  1327. let cellObj = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {};
  1328. if (cellObj && cellObj.value && !this.isSingleFormat(cellObj.value)) {
  1329. td.innerHTML = cellObj.value;
  1330. td.removeAttribute('style');
  1331. }
  1332. else if (!cellObj.value) {
  1333. td.innerHTML = '';
  1334. }
  1335. }
  1336. }
  1337. }
  1338. clearRTCell(range) {
  1339. var td = this.ssObj.getCell(range[0], range[1]);
  1340. td.innerHTML = "";
  1341. }
  1342. updateRTCell(ranges, value) {
  1343. var td = this.ssObj.getCell(ranges[0], ranges[1]);
  1344. if (value) {
  1345. this.renderRTCell(td, value);
  1346. }
  1347. }
  1348. bfCellRender1(args) {
  1349. let value;
  1350. if (args && args.cell && args.cell.value) {
  1351. value = args.cell.value;
  1352. if (value && !this.isSingleFormat(value)) {
  1353. this.renderRTCell(args.element, value);
  1354. }
  1355. }
  1356. }
  1357. afterCellRender(rowIdx, colIdx, sheet, cellObj) {
  1358. let value = cellObj.value;
  1359. var td = this.ssObj.getCell(rowIdx, colIdx);
  1360. if (value && !this.isSingleFormat(value)) {
  1361. this.renderRTCell(td, value);
  1362. }
  1363. else if (!value) {
  1364. td.innerHTML = '';
  1365. }
  1366. }
  1367. renderRTCell(element, value) {
  1368. if (value.indexOf('<p') === 0) {
  1369. element.innerHTML = value;
  1370. element.firstElementChild.setAttribute('style', "font-size:inherit");
  1371. }
  1372. else {
  1373. element.innerHTML = '<p style="font-size: inherit">' + value + '</p>';
  1374. }
  1375. }
  1376. getStyles(cell) {
  1377. if (cell.style) {
  1378. let str = '';
  1379. let styles = Object.keys(cell.style);
  1380. for (let i = 0; i < styles.length; i++) {
  1381. str = str + ' ' + this.camelToSnake(styles[i]) + ' : ' + cell.style[styles[i]] + ' ;';
  1382. }
  1383. return str;
  1384. }
  1385. return null;
  1386. }
  1387. setRTEStyles(cell, elem) {
  1388. if (cell.style) {
  1389. let styles = Object.keys(cell.style);
  1390. for (let i = 0; i < styles.length; i++) {
  1391. elem.style[this.camelToSnake(styles[i])] = cell.style[styles[i]];
  1392. }
  1393. }
  1394. }
  1395. camelToSnake(string) {
  1396. return string.replace(/([a-z]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
  1397. }
  1398. mdown3(e) {
  1399. let target = ej.base.closest(e.target, '.e-toolbar-item');
  1400. let id = this.ssObj.element.id + '_rte_toolbar_';
  1401. if (this.ssObj.isEdit && target) {
  1402. let btn = target.firstElementChild;
  1403. let action = btn.id.split(this.ssObj.element.id + '_')[1];
  1404. switch (action) {
  1405. case 'bold':
  1406. this.rteObj.element.querySelector('#' + id + 'Bold').click();
  1407. break;
  1408. case 'italic':
  1409. this.rteObj.element.querySelector('#' + id + 'Italic').click();
  1410. break;
  1411. case 'line-through':
  1412. this.rteObj.element.querySelector('#' + id + 'StrikeThrough').click();
  1413. break;
  1414. case 'underline':
  1415. this.rteObj.element.querySelector('#' + id + 'Underline').click();
  1416. break;
  1417. case 'wrap':
  1418. case 'currencyformat':
  1419. case 'percentageformat':
  1420. this.ssObj.endEdit();
  1421. break;
  1422. }
  1423. }
  1424. }
  1425. actionBegin(args) {
  1426. if (this.ssObj.isEdit && args.action === 'format' && args.args.eventArgs.requestType === 'NumberFormat') {
  1427. this.ssObj.endEdit();
  1428. }
  1429. }
  1430. ssCreated() {
  1431. setTimeout(() => {
  1432. this.ssObj.ribbonModule.fontNameDdb.addEventListener('select', this.fontChange.bind(this));
  1433. this.ssObj.ribbonModule.fontSizeDdb.addEventListener('select', this.fontSizeChange.bind(this));
  1434. this.ssObj.on('biz-dd', this.rtDragnDrop, this);
  1435. this.ssObj.on('setCellFormat', this.formatChange, this);
  1436. }, 500);
  1437. }
  1438. fontChange(args) {
  1439. (this.ssObj.isEdit) && (this.rteObj.formatter.editorManager.execCommand('Font', 'FontName', undefined, () => { }, args.item.text, null, "#" + this.ssObj.element.id + "_rte iframe"));
  1440. }
  1441. fontSizeChange(args) {
  1442. (this.ssObj.isEdit) && (this.rteObj.formatter.editorManager.execCommand('Font', 'FontSize', undefined, () => { }, args.item.text + 'pt', null, "#" + this.ssObj.element.id + "_rte iframe"));
  1443. }
  1444. hexToRgb(hex) {
  1445. var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  1446. return result ? {
  1447. r: parseInt(result[1], 16),
  1448. g: parseInt(result[2], 16),
  1449. b: parseInt(result[3], 16)
  1450. } : null;
  1451. }
  1452. formatChange(args) {
  1453. if (this.ssObj.isEdit) {
  1454. let key = Object.keys(args.style)[0];
  1455. if (args.style.color) {
  1456. let rgb = this.hexToRgb(args.style.color);
  1457. this.rteObj.formatter.editorManager.execCommand('Font', 'FontColor', undefined, () => { }, "rgba(" + rgb.r + "," + rgb.g + "," + rgb.b + ",1)", null, "#" + this.ssObj.element.id + "_rte iframe");
  1458. }
  1459. if (args.style.backgroundColor || key.indexOf('border') > -1 || args.style.textAlign || args.style.verticalAlign) {
  1460. this.stopAndApply(args, key);
  1461. }
  1462. }
  1463. }
  1464. stopAndApply(args, key) {
  1465. this.ssObj.endEdit();
  1466. let ranges = this.ssObj.biz.getIndexes();
  1467. let sheet = this.ssObj.biz.getActiveSheet();
  1468. let cell = ej.spreadsheet.getCell(ranges[0], ranges[1], sheet) || {};
  1469. if (!cell.style) {
  1470. cell.style = {};
  1471. }
  1472. cell.style[key] = args.style[key];
  1473. this.ssObj.biz.setCell(ranges[0], ranges[1], sheet, cell);
  1474. }
  1475. getFormatValue(ranges) {
  1476. let sheet = this.ssObj.biz.getActiveSheet();
  1477. return sheet.richtexts && sheet.richtexts.rows[ranges[0]] && sheet.richtexts.rows[ranges[0]].cells[ranges[1]] && sheet.richtexts.rows[ranges[0]].cells[ranges[1]];
  1478. }
  1479. removeRTData(ranges) {
  1480. let sheet = this.ssObj.biz.getActiveSheet();
  1481. delete sheet.richtexts.rows[ranges[0]].cells[ranges[1]];
  1482. }
  1483. addRTData(ranges, value) {
  1484. let sheet = this.ssObj.biz.getActiveSheet();
  1485. if (!sheet.richtexts) {
  1486. sheet.richtexts = { rows: {} };
  1487. }
  1488. let row = sheet.richtexts.rows[ranges[0]];
  1489. if (!row) {
  1490. sheet.richtexts.rows[ranges[0]] = {};
  1491. sheet.richtexts.rows[ranges[0]].cells = {};
  1492. }
  1493. sheet.richtexts.rows[ranges[0]].cells[ranges[1]] = value;
  1494. }
  1495. isSingleFormat(value) {
  1496. let tags = value ? value.toString().split('</') : [];
  1497. return tags.length <= 2 && !(value.includes('<Font'));
  1498. }
  1499. setCaret(el) {
  1500. const selection = window.getSelection();
  1501. const range = document.createRange();
  1502. selection.removeAllRanges();
  1503. range.selectNodeContents(el);
  1504. range.collapse(false);
  1505. selection.addRange(range);
  1506. el.focus();
  1507. }
  1508. static Instance() {
  1509. if (this.instance === undefined) {
  1510. this.instance = new FormatPainter();
  1511. }
  1512. return this.instance;
  1513. }
  1514. }
  1515. Sheets.FormatPainter = FormatPainter;
  1516. })(Sheets = Components.Sheets || (Components.Sheets = {}));
  1517. })(Components = Collaboration.Components || (Collaboration.Components = {}));
  1518. })(Collaboration = Apps.Collaboration || (Apps.Collaboration = {}));
  1519. })(Apps = Unibase.Apps || (Unibase.Apps = {}));
  1520. })(Unibase || (Unibase = {}));