var Unibase;
(function (Unibase) {
let Apps;
(function (Apps) {
let Collaboration;
(function (Collaboration) {
let Components;
(function (Components) {
let Sheets;
(function (Sheets) {
class SpellChecker {
constructor() {
this.dic = {};
this.hederText = {};
}
init(base) {
this.base = base;
this.ssObj = this.base.ssObj;
}
processWords() {
this.dic = {};
this.words = '';
let sheet = this.ssObj.biz.getActiveSheet();
let rngIndexes = this.base.getIndexesFromAddress(sheet.selectedRange);
for (let i = rngIndexes[0]; i <= rngIndexes[2]; i++) {
if (!this.ssObj.biz.isRowAvailable(i, sheet)) {
continue;
}
for (let j = rngIndexes[1]; j <= rngIndexes[3]; j++) {
let cellObj = ej.spreadsheet.getCell(i, j, sheet);
if (cellObj && cellObj.value && typeof cellObj.value !== 'number') {
let value = cellObj.value.toString();
let temp = value.split(' ');
let values = [];
for (let k = 0; k < temp.length; k++) {
let val = temp[k];
if (!this.dic[val]) {
this.dic[val.trim()] = [{ rowIndex: i, colIndex: j }];
values.push(val.trim());
}
else {
this.dic[val.trim()].push({ rowIndex: i, colIndex: j });
}
}
values.length && (this.words = this.words + ' ' + values.toString().replaceAll(',', ' '));
}
}
}
this.splitWords = this.words.trim().split(' ').reverse();
this.requestServer();
}
requestServer() {
var data = {
LanguageID: 1033,
TexttoCheck: this.words.trim(),
CheckSpelling: true,
CheckSuggestion: true,
AddWord: false,
};
Unibase.Apps.Collaboration.DocumentManager.Instance().spellCheck(data).then((res) => { this.successCallback(res); });
}
successCallback(result) {
this.ssObj.allowEditing = false;
for (var i = 0; i < result.length; i++) {
result[i] = JSON.parse(result[i]);
}
this.result = result.reverse();
ej.popups.hideSpinner(this.dlgObj.element);
this.dlgObj.content = `
`;
this.dlgObj.dataBind();
this.dlgObj.element.querySelector('.e-footer-content').classList.add('biz-hide');
this.infoElem = this.dlgObj.element.querySelector('.biz-sc-info');
this.textObj = new ej.inputs.TextBox({}, this.dlgObj.element.querySelector('.biz-sc-value'));
this.ddSug = new ej.dropdowns.DropDownList({
dataSource: [], select: (e) => {
this.textObj.value = e.itemData.value;
}
}, this.dlgObj.element.querySelector('.biz-sc-sugg'));
let items = [
{
text: 'Change all',
}
];
this.spanElem = this.dlgObj.element.querySelector('.biz-sc-info');
this.ddChange = new ej.splitbuttons.SplitButton({ items: items, click: (e) => { this.change(); }, select: (e) => { this.changeAll(); } }, this.dlgObj.element.querySelector('.biz-sc-change'));
items = [
{
text: 'Ignore all',
}
];
this.ddIgnore = new ej.splitbuttons.SplitButton({ items: items, click: (e) => { this.ignore(); }, select: (e) => { this.ignoreAll(); } }, this.dlgObj.element.querySelector('.biz-sc-ignore'));
this.moveNext();
}
convertAsItemModel(items) {
for (let i = 0; i < items.length; i++) {
items[i] = { text: items[i] };
}
}
moveNext(skipPop) {
if (!this.splitWords.length) {
this.dlgObj.content = 'No spelling errors';
this.dlgObj.height = '95px';
this.dlgObj.dataBind();
this.dlgObj.element.querySelector('.e-footer-content').classList.remove('biz-hide');
this.ssObj.allowEditing = true;
setTimeout(() => {
this.destroySpellDialog();
}, 3000);
return;
}
if (!skipPop) {
this.value = this.splitWords.pop();
this.spellObj = this.result.pop();
this.spanElem.innerHTML = "Change " + this.value + " to:";
}
let addr = this.dic[this.value];
if (this.spellObj['Suggestions'] && this.spellObj['Suggestions'].length && addr.length) {
this.ssObj.selectRange(this.base.generateHeaderText(addr[0].colIndex + 1) + (addr[0].rowIndex + 1));
this.ddSug.dataSource = this.spellObj['Suggestions'];
this.ddSug.value = this.spellObj['Suggestions'][0];
this.textObj.value = this.spellObj['Suggestions'][0];
}
else {
delete this.dic[this.value];
this.moveNext();
}
}
change() {
let addr = this.dic[this.value];
let sheet = this.ssObj.biz.getActiveSheet();
let cellObj = ej.spreadsheet.getCell(addr[0].rowIndex, addr[0].colIndex, sheet);
let value = cellObj.value === this.value ? this.textObj.value : cellObj.value.replace(this.value, this.textObj.value);
let args = { rowIdx: addr[0].rowIndex, colIdx: addr[0].colIndex, value: value, action: 'spellcheck', origin: 'biz', sheetIndex: this.base.getSheetIndex() };
this.applySpellValue(addr[0].rowIndex, addr[0].colIndex, value);
this.ignore();
Unibase.Apps.Collaboration.Components.Sheets.Base.Instance().bizSignalr(args);
}
applySpellValue(rowIdx, colIdx, value) {
let sheet = this.ssObj.biz.getActiveSheet();
let cellObj = ej.spreadsheet.getCell(rowIdx, colIdx, sheet);
cellObj.value = value;
this.ssObj.biz.setCell(rowIdx, colIdx, sheet, cellObj);
Unibase.Apps.Collaboration.Components.Common.Download.Instance().ssAutoSave({ action: "cellSave", eventArgs: { address: "sheet!" + this.base.ssObj.biz.getRange() } }, this.base, true);
}
changeAll() {
let len = this.dic[this.value].length;
for (let i = 0; i < len; i++) {
this.change();
}
}
ignore() {
this.dic[this.value].shift();
this.moveNext(true);
}
ignoreAll() {
delete this.dic[this.value];
this.moveNext();
}
renderSpellDialog() {
let div = this.ssObj.element.querySelector('.biz-spelldlg') || ej.base.createElement('div', { className: 'biz-spelldlg' });
this.ssObj.element.querySelector('.e-sheet-panel').appendChild(div);
this.dlgObj = new ej.popups.Dialog({
target: this.ssObj.element.querySelector('.e-sheet-panel'),
content: '',
width: '350px',
height: '170px',
position: { X: 'right', Y: 'top' },
animationSettings: { effect: 'None' },
showCloseIcon: false,
buttons: [{
click: this.destroySpellDialog.bind(this),
buttonModel: { content: 'Close' }
}],
open: () => {
ej.popups.createSpinner({ target: this.dlgObj.element });
ej.popups.showSpinner(this.dlgObj.element);
},
});
this.dlgObj.appendTo(div);
this.processWords();
}
destroySpellDialog() {
this.ddSug.destroy();
this.ddChange.destroy();
this.ddIgnore.destroy();
this.dlgObj.destroy();
}
static Instance() {
if (this.instance === undefined) {
this.instance = new SpellChecker();
}
return this.instance;
}
}
Sheets.SpellChecker = SpellChecker;
})(Sheets = Components.Sheets || (Components.Sheets = {}));
})(Components = Collaboration.Components || (Collaboration.Components = {}));
})(Collaboration = Apps.Collaboration || (Apps.Collaboration = {}));
})(Apps = Unibase.Apps || (Unibase.Apps = {}));
})(Unibase || (Unibase = {}));