mirror of
https://github.com/ONLYOFFICE/sdkjs.git
synced 2026-02-10 18:15:19 +08:00
[se] Revert CSharedStrings to 986bc4190e
This commit is contained in:
committed by
Sergey Luzyanin
parent
246f624b36
commit
1e631939a3
@ -13032,14 +13032,12 @@ function RangeDataManagerElem(bbox, data)
|
||||
this.bssr = null;
|
||||
}
|
||||
|
||||
CSharedStrings.prototype.addText = function(text, isReadingTable) {
|
||||
CSharedStrings.prototype.addText = function(text) {
|
||||
var textMap = this.text;
|
||||
var index = textMap[text];
|
||||
var allArray = this.all;
|
||||
if (isReadingTable || undefined === index) {
|
||||
allArray.push(text);
|
||||
}
|
||||
if (undefined === index) {
|
||||
var allArray = this.all;
|
||||
allArray.push(text);
|
||||
index = allArray.length;
|
||||
textMap[text] = index;
|
||||
if (AscFonts.IsCheckSymbols) {
|
||||
@ -13048,7 +13046,7 @@ function RangeDataManagerElem(bbox, data)
|
||||
}
|
||||
return index;
|
||||
};
|
||||
CSharedStrings.prototype.addMultiText = function(multiText, isReadingTable) {
|
||||
CSharedStrings.prototype.addMultiText = function(multiText) {
|
||||
var index, i;
|
||||
var text = multiText.reduce(function(accumulator, currentValue) {
|
||||
return accumulator + currentValue.text;
|
||||
@ -13064,10 +13062,8 @@ function RangeDataManagerElem(bbox, data)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isReadingTable || undefined === index) {
|
||||
this.all.push(multiText);
|
||||
}
|
||||
if (undefined === index) {
|
||||
this.all.push(multiText);
|
||||
index = this.all.length;
|
||||
mapElem.push(index);
|
||||
if (AscFonts.IsCheckSymbols) {
|
||||
@ -13077,24 +13073,46 @@ function RangeDataManagerElem(bbox, data)
|
||||
return index;
|
||||
};
|
||||
/**
|
||||
* Initialize with sharedStrings from file. rely on uniqines
|
||||
* Adds new shared strings to existing ones without removing existing data
|
||||
* Initialize with sharedStrings from file. Relies on uniqueness.
|
||||
* Adds new shared strings to existing ones without removing existing data.
|
||||
* @param {Array<string | Array<{text: string, format: CellXfs}>>} sharedStrings
|
||||
* @param {Array<number>} [opt_sharedStringIndexMap] - optional array to collect index mappings
|
||||
*/
|
||||
CSharedStrings.prototype.initWithSharedStrings = function(sharedStrings, opt_sharedStringIndexMap, sharedStringOffset) {
|
||||
sharedStringOffset = sharedStringOffset || 0;
|
||||
for (let i = sharedStringOffset; i < sharedStrings.length; i++) {
|
||||
CSharedStrings.prototype.initWithSharedStrings = function(sharedStrings, opt_sharedStringIndexMap) {
|
||||
if (this.all.length > 0) {
|
||||
for (let i = 0; i < sharedStrings.length; i++) {
|
||||
const item = sharedStrings[i];
|
||||
let index;
|
||||
if (typeof item === 'string') {
|
||||
index = this.addText(item, true);
|
||||
index = this.addText(item);
|
||||
} else {
|
||||
index = this.addMultiText(item, true);
|
||||
index = this.addMultiText(item);
|
||||
}
|
||||
if (opt_sharedStringIndexMap) {
|
||||
opt_sharedStringIndexMap[i] = index;
|
||||
opt_sharedStringIndexMap.push(index);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.replaceSharedStrings(sharedStrings, opt_sharedStringIndexMap);
|
||||
};
|
||||
/**
|
||||
* Replace all shared strings with new ones (fast path for empty state).
|
||||
* @param {Array<string | Array<{text: string, format: CellXfs}>>} sharedStrings
|
||||
* @param {Array<number>} [opt_sharedStringIndexMap] - optional array to collect index mappings
|
||||
*/
|
||||
CSharedStrings.prototype.replaceSharedStrings = function(sharedStrings, opt_sharedStringIndexMap) {
|
||||
this.all = sharedStrings.slice(); // copy
|
||||
this.text = Object.create(null);
|
||||
this.multiTextMap = Object.create(null);
|
||||
|
||||
for (let i = 0; i < sharedStrings.length; i++) {
|
||||
const text = sharedStrings[i];
|
||||
this._addSharedStringCacheByIndex(text, i + 1); // 1-based indexing
|
||||
if (opt_sharedStringIndexMap) {
|
||||
opt_sharedStringIndexMap.push(i + 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
CSharedStrings.prototype._addSharedStringCacheByIndex = function(text, index) {
|
||||
if (typeof text === 'string') {
|
||||
|
||||
Reference in New Issue
Block a user