Skip to content

Commit

Permalink
Merge branch 'release/v8.3.0' into fix/external-short-link
Browse files Browse the repository at this point in the history
# Conflicts:
#	cell/model/WorkbookElems.js
  • Loading branch information
GoshaZotov committed Dec 28, 2024
2 parents f5692e7 + 29f1e81 commit d8843d8
Show file tree
Hide file tree
Showing 44 changed files with 2,092 additions and 1,579 deletions.
134 changes: 96 additions & 38 deletions cell/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ var editor;
callback(false);
return;
}
callback(AscCommon.parseText(text, options, true));
callback(text);
}
};

Expand Down Expand Up @@ -907,6 +907,92 @@ var editor;
}
};

/**
* @param {string} text
* @param {number | undefined} opt_count
* @param {string[] | undefined} opt_delimiters
* @return {{delimiterChar: string, text: string}}
*/
function getCSVDelimiter(text, opt_count, opt_delimiters) {
//check header: sep=
const textHeadLower = text.substring(0, 5).toLowerCase();
let delimiter;
let offset = 0;
if (textHeadLower.startsWith('sep=')) {
delimiter = text[4];
offset = 5;
} else if (textHeadLower.startsWith('"sep=') && '"' === text[6]) {
delimiter = text[5];
offset = 7;
}
if (undefined !== delimiter) {
//win cr
if ('\r' === text[offset]) {
offset++;
}
//check new line
if ('\n' === text[offset]) {
return {delimiterChar: delimiter, text: text.substring(offset + 1)}
}
}
//Count occurrences of opt_delimiters characters within text
const count = opt_count ? Math.min(opt_count, text.length) : text.length;
const delimiters = opt_delimiters ? opt_delimiters : [",", "\t", ";", ":"];
const counter = {}
for (let i = 0; i < delimiters.length; i += 1) {
counter[delimiters[i]] = 0;
}
let isQuoteOpen = false;
for (let i = 0; i < count; i += 1) {
const sym = text[i];
if (sym === '"') {
isQuoteOpen = !isQuoteOpen;
}
if (!isQuoteOpen && counter[sym] != null) {
counter[sym] += 1;
}
}
let max = 0;
delimiter = delimiters[0];
for (let i in counter) {
if (counter[i] > max) {
max = counter[i];
delimiter = i;
}
}
return {delimiterChar: delimiter, text: text};
}
function getDelimiterEnumByChar(delimiter) {
switch (delimiter) {
case '\t':
return AscCommon.c_oAscCsvDelimiter.Tab;
case ';':
return AscCommon.c_oAscCsvDelimiter.Semicolon;
case ':':
return AscCommon.c_oAscCsvDelimiter.Colon;
case ',':
return AscCommon.c_oAscCsvDelimiter.Comma;
case ' ':
return AscCommon.c_oAscCsvDelimiter.Space;
}
return AscCommon.c_oAscCsvDelimiter.None;
}
/**
* @param {string} text
* @param {number | undefined} opt_count
* @param {string[] | undefined} opt_delimiters
* @return {{delimiterChar: string, text: string}}
*/
spreadsheet_api.prototype.asc_getCSVDelimiter = function (text, opt_count, opt_delimiters) {
let res = getCSVDelimiter(text, opt_count, opt_delimiters);
let delimiter = getDelimiterEnumByChar(res.delimiterChar);
if (AscCommon.c_oAscCsvDelimiter.None !== delimiter) {
return {"text": res.text, "delimiterChar": res.delimiterChar, "delimiter": delimiter};
} else {
return {"text": res.text, "delimiterChar": res.delimiterChar};
}
};

spreadsheet_api.prototype.asc_ShowSpecialPasteButton = function(props) {
if (this.canEdit()) {
this.wb.showSpecialPasteButton(props);
Expand Down Expand Up @@ -4089,41 +4175,11 @@ var editor;
return false;
}

var scale = this.asc_getZoom();

var t = this;
var addWorksheet = function(res) {
if (res) {
// ToDo перейти от wsViews на wsViewsId
History.Create_NewPoint();
History.StartTransaction();

var renameParamsArr = [], renameSheetMap = {};
for (var i = arrSheets.length - 1; i >= 0; --i) {
t.wb.pasteSheet(arrSheets[i], where, arrNames[i], function(renameParams) {
// Делаем активным скопированный
renameParamsArr.push(renameParams);
renameSheetMap[renameParams.lastName] = renameParams.newName;
t.asc_showWorksheet(where);
t.asc_setZoom(scale);
// Посылаем callback об изменении списка листов
t.sheetsChanged();
});

}
//парсинг формул после вставки всех листов, поскольку внутри одного листа может быть ссылка в формуле на другой лист который ещё не вставился
//поэтому дожидаемся вставку всех листов
for(var j = 0; j < renameParamsArr.length; j++) {
var newSheet = t.wb.model.getWorksheetByName(renameParamsArr[j].newName);
newSheet.copyFromFormulas(renameParamsArr[j], renameSheetMap);
}

// Делаем активным скопированный
t.wbModel.setActive(where);
t.wb.updateWorksheetByModel();
t.wb.showWorksheet();
History.EndTransaction();
// Посылаем callback об изменении списка листов
t.sheetsChanged();
t.wb.pasteSheets(arrSheets, where, arrNames);
}
};

Expand Down Expand Up @@ -6505,8 +6561,8 @@ var editor;
spreadsheet_api.prototype.asc_canEnterWizardRange = function(char) {
return this.wb.canEnterWizardRange(char);
};
spreadsheet_api.prototype.asc_insertArgumentsInFormula = function(val, argNum, argType, name) {
var res = this.wb.insertArgumentsInFormula(val, argNum, argType, name);
spreadsheet_api.prototype.asc_insertArgumentsInFormula = function(val, argNum, argType, name, bEndInsertArg) {
var res = this.wb.insertArgumentsInFormula(val, argNum, argType, name, bEndInsertArg);
this.wb.restoreFocus();
return res;
};
Expand Down Expand Up @@ -9009,10 +9065,10 @@ var editor;
* start timer if true, clear timer if false
* if update from interface all links, timer restart
* if part of links - not restart
* event from model to view - "changeExternalReferenceAutoUpdate"
* event from model to view - "changeUpdateLinks"
* @param {bool} val
* */
spreadsheet_api.prototype.asc_setUpdateLinks = function(val) {
spreadsheet_api.prototype.asc_setUpdateLinks = function(val, bFirstStart) {
//ms desktop: update automatic(realtime) only if open source file(not depends on workbookPr->UpdateLinks property). if source file changed by another editor - not update links
//workbookPr->UpdateLinks only the opening is affected
//ms online
Expand All @@ -9024,7 +9080,7 @@ var editor;
if (!wbModel) {
return;
}
wbModel.setUpdateLinks(val, true);
wbModel.setUpdateLinks(val, true, bFirstStart);
};

spreadsheet_api.prototype.asc_getUpdateLinks = function() {
Expand Down Expand Up @@ -9676,6 +9732,7 @@ var editor;
prot["asc_TextImport"] = prot.asc_TextImport;
prot["asc_TextToColumns"] = prot.asc_TextToColumns;
prot["asc_TextFromFileOrUrl"] = prot.asc_TextFromFileOrUrl;
prot["asc_getCSVDelimiter"] = prot.asc_getCSVDelimiter;

prot["asc_initPrintPreview"] = prot.asc_initPrintPreview;
prot["asc_updatePrintPreview"] = prot.asc_updatePrintPreview;
Expand Down Expand Up @@ -10189,6 +10246,7 @@ var editor;
prot["asc_updateExternalReferences"] = prot.asc_updateExternalReferences;
prot["asc_removeExternalReferences"] = prot.asc_removeExternalReferences;
prot["asc_openExternalReference"] = prot.asc_openExternalReference;
prot["asc_changeExternalReference"] = prot.asc_changeExternalReference;
prot["asc_setUpdateLinks"] = prot.asc_setUpdateLinks;
prot["asc_getUpdateLinks"] = prot.asc_getUpdateLinks;

Expand Down
2 changes: 1 addition & 1 deletion cell/model/FormulaObjects/textanddataFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ function (window, undefined) {
cIMPORTRANGE.prototype.argumentsMin = 2;
cIMPORTRANGE.prototype.argumentsMax = 2;
cIMPORTRANGE.prototype.isXLUDF = true;
cIMPORTRANGE.prototype.argumentsType = [argType.reference, argType.text];
cIMPORTRANGE.prototype.argumentsType = [argType.text, argType.text];
cIMPORTRANGE.prototype.Calculate = function (arg) {
//gs -> allow array(get first element), cRef, cRef3D, cName, cName3d
//not allow area/area3d
Expand Down
34 changes: 15 additions & 19 deletions cell/model/Serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3709,33 +3709,29 @@
};
this.WriteWorkbookPr = function()
{
var oWorkbookPr = this.wb.workbookPr;
if(null != oWorkbookPr)
{
if(null != oWorkbookPr.Date1904)
{
let oWorkbookPr = this.wb.workbookPr;
if (null != oWorkbookPr) {
if (null != oWorkbookPr.Date1904) {
this.memory.WriteByte(c_oSerWorkbookPrTypes.Date1904);
this.memory.WriteByte(c_oSerPropLenType.Byte);
this.memory.WriteBool(oWorkbookPr.Date1904);
}
else if (null != oWorkbookPr.DateCompatibility)
{
if (null != oWorkbookPr.DateCompatibility) {
this.memory.WriteByte(c_oSerWorkbookPrTypes.DateCompatibility);
this.memory.WriteByte(c_oSerPropLenType.Byte);
this.memory.WriteBool(oWorkbookPr.DateCompatibility);
}
else if (null != oWorkbookPr.HidePivotFieldList)
{
this.memory.WriteByte(c_oSerWorkbookPrTypes.HidePivotFieldList);
this.memory.WriteByte(c_oSerPropLenType.Byte);
this.memory.WriteBool(oWorkbookPr.HidePivotFieldList);
}
else if (null != oWorkbookPr.ShowPivotChartFilter)
{
this.memory.WriteByte(c_oSerWorkbookPrTypes.ShowPivotChartFilter);
this.memory.WriteByte(c_oSerPropLenType.Byte);
this.memory.WriteBool(oWorkbookPr.ShowPivotChartFilter);
} else if (null != oWorkbookPr.UpdateLinks) {
if (null != oWorkbookPr.HidePivotFieldList) {
this.memory.WriteByte(c_oSerWorkbookPrTypes.HidePivotFieldList);
this.memory.WriteByte(c_oSerPropLenType.Byte);
this.memory.WriteBool(oWorkbookPr.HidePivotFieldList);
}
if (null != oWorkbookPr.ShowPivotChartFilter) {
this.memory.WriteByte(c_oSerWorkbookPrTypes.ShowPivotChartFilter);
this.memory.WriteByte(c_oSerPropLenType.Byte);
this.memory.WriteBool(oWorkbookPr.ShowPivotChartFilter);
}
if (null != oWorkbookPr.UpdateLinks) {
this.memory.WriteByte(c_oSerWorkbookPrTypes.UpdateLinks);
this.memory.WriteByte(c_oSerPropLenType.Byte);
this.memory.WriteBool(oWorkbookPr.UpdateLinks);
Expand Down
2 changes: 1 addition & 1 deletion cell/model/UndoRedo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2791,7 +2791,7 @@ function (window, undefined) {
AscCommonExcel.g_cCalcRecursion.initCalcProperties(wb.calcPr);

} else if(AscCH.historyitem_Workbook_UpdateLinks === Type) {
wb.setUpdateLinks(bUndo ? Data.from : Data.to);
wb.setUpdateLinks(bUndo ? Data.from : Data.to, null, null, !wb.oApi.isDocumentLoadComplete && wb.bCollaborativeChanges);
}
};
UndoRedoWorkbook.prototype.forwardTransformationIsAffect = function (Type) {
Expand Down
8 changes: 5 additions & 3 deletions cell/model/Workbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -5506,7 +5506,7 @@
this.addExternalReferences(newExternalReferences);
};

Workbook.prototype.setUpdateLinks = function (val, addToHistory) {
Workbook.prototype.setUpdateLinks = function (val, addToHistory, bFirstStart, bNotStartTimer) {
var from = !!(this.workbookPr.UpdateLinks && this.workbookPr.UpdateLinks);
if (val !== from) {
this.workbookPr.UpdateLinks = val;
Expand All @@ -5515,12 +5515,14 @@
History.Add(AscCommonExcel.g_oUndoRedoWorkbook, AscCH.historyitem_Workbook_UpdateLinks,
null, null, new UndoRedoData_FromTo(from, val));
}
this.handlers && this.handlers.trigger("changeUpdateLinks");
!bNotStartTimer && this.handlers && this.handlers.trigger("changeUpdateLinks");
} else if (bFirstStart) {
!bNotStartTimer && this.handlers && this.handlers.trigger("changeUpdateLinks");
}
};

Workbook.prototype.getUpdateLinks = function () {
return !!(this.workbookPr && this.workbookPr.workbookPr);
return !!(this.workbookPr && this.workbookPr.UpdateLinks);
};

Workbook.prototype.unlockUserProtectedRanges = function(){
Expand Down
20 changes: 20 additions & 0 deletions cell/model/WorkbookElems.js
Original file line number Diff line number Diff line change
Expand Up @@ -14387,6 +14387,8 @@ function RangeDataManagerElem(bbox, data)
this.formulaResult = null;
this.functionResult = null;

this.arguments = null;

this._init(name);

return this;
Expand Down Expand Up @@ -14425,6 +14427,12 @@ function RangeDataManagerElem(bbox, data)
CFunctionInfo.prototype.asc_getName = function () {
return this.name;
};
CFunctionInfo.prototype.asc_getArguments = function () {
return this.arguments;
};
CFunctionInfo.prototype.asc_setArguments = function (val) {
this.arguments = val;
};


function CPrintPreviewState(wb) {
Expand Down Expand Up @@ -14848,6 +14856,9 @@ function RangeDataManagerElem(bbox, data)
//portalName
this.referenceData = null;

//temp for update
this.sKey = null;

this.worksheets = {};
}

Expand Down Expand Up @@ -15590,6 +15601,9 @@ function RangeDataManagerElem(bbox, data)
}
};

ExternalReference.prototype.getKey = function() {
return this.sKey;
};
ExternalReference.prototype.shiftData = function () {
/* shift data to 1 position left */
for (let i in this.SheetDataSet) {
Expand All @@ -15600,6 +15614,9 @@ function RangeDataManagerElem(bbox, data)
}
};

ExternalReference.prototype.setKey = function(val) {
this.sKey = val;
};

function asc_CExternalReference() {
this.type = null;
Expand Down Expand Up @@ -19159,6 +19176,9 @@ function RangeDataManagerElem(bbox, data)
prot["asc_getFormulaResult"] = prot.asc_getFormulaResult;
prot["asc_getFunctionResult"] = prot.asc_getFunctionResult;
prot["asc_getName"] = prot.asc_getName;
prot["asc_getArguments"] = prot.asc_getArguments;
prot["asc_setArguments"] = prot.asc_setArguments;


window["Asc"]["asc_CExternalReference"] = window["Asc"].asc_CExternalReference = asc_CExternalReference;
prot = asc_CExternalReference.prototype;
Expand Down
11 changes: 10 additions & 1 deletion cell/model/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2718,7 +2718,16 @@

drawingObject.graphicObject.setDrawingObjects(ws.objectRender);
drawingObject.graphicObject.setWorksheet(ws.model);
xfrm.setOffX(ws.checkRtl(curCol, null, 3));
let _left = ws.checkRtl(curCol, null, 3);
if (ws.getRightToLeft()) {
let mmToPx = Asc.getCvtRatio(3/*px*/, 0/*pt*/, ws._getPPIX());
let _widthDrawing = drawingObject.getWidthFromTo() / mmToPx;
let _widthCtx = ws.getCtxWidth() / mmToPx;
if (_left + _widthDrawing > _widthCtx) {
_left -= _left + _widthDrawing - _widthCtx;
}
}
xfrm.setOffX( _left);
xfrm.setOffY(curRow);
aDrawings.push(drawingObject.graphicObject);
drawingObject.graphicObject.getAllRasterImages(aImagesSync);
Expand Down
4 changes: 2 additions & 2 deletions cell/view/CellEditorView.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,11 +705,11 @@ function (window, undefined) {

// ToDo move this code to moveCursor

this.lastRangePos = this._parseResult && this._parseResult.argPosArr
this.lastRangePos = this._parseResult && this._parseResult.argPosArr && this._parseResult.argPosArr.length
? this._parseResult.argPosArr[0].start
: this.cursorPos;

this.lastRangeLength = this._parseResult && this._parseResult.argPosArr
this.lastRangeLength = this._parseResult && this._parseResult.argPosArr && this._parseResult.argPosArr.length
? this._parseResult.argPosArr[this._parseResult.argPosArr.length - 1].end - this._parseResult.argPosArr[0].start
: 0;
}
Expand Down
Loading

0 comments on commit d8843d8

Please sign in to comment.