@bilig/headless 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -45,6 +45,8 @@ export function prepareInitialMixedSheetLoad(args) {
|
|
|
45
45
|
const writtenColumns = new Uint8Array(maxColumnCount);
|
|
46
46
|
const rowIds = [];
|
|
47
47
|
const colIds = [];
|
|
48
|
+
const ensureRowId = args.engine.workbook.createLogicalAxisIdEnsurer(args.sheetId, 'row');
|
|
49
|
+
const ensureColumnId = args.engine.workbook.createLogicalAxisIdEnsurer(args.sheetId, 'column');
|
|
48
50
|
let writtenColumnCount = 0;
|
|
49
51
|
const formulaRefs = args.inspection?.formulaCellCount !== undefined ? Array(args.inspection.formulaCellCount) : [];
|
|
50
52
|
let formulaRefCount = 0;
|
|
@@ -62,10 +64,11 @@ export function prepareInitialMixedSheetLoad(args) {
|
|
|
62
64
|
const formula = readInitialFormulaSource(raw);
|
|
63
65
|
if (formula !== undefined) {
|
|
64
66
|
const cellIndex = cellStore.allocateReserved(args.sheetId, rowIndex, colIndex);
|
|
65
|
-
rowId
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
const materializedRowId = rowId ?? ensureRowId(rowIndex);
|
|
68
|
+
rowId = materializedRowId;
|
|
69
|
+
rowIds[rowIndex] = materializedRowId;
|
|
70
|
+
const colId = (colIds[colIndex] ??= ensureColumnId(colIndex));
|
|
71
|
+
attachFreshCell(rowIndex, colIndex, cellIndex, materializedRowId, colId);
|
|
69
72
|
formulaRefs[formulaRefCount] = {
|
|
70
73
|
sheetId: args.sheetId,
|
|
71
74
|
cellIndex,
|
|
@@ -91,10 +94,11 @@ export function prepareInitialMixedSheetLoad(args) {
|
|
|
91
94
|
cellStore.versions[cellIndex] = 1;
|
|
92
95
|
cellStore.topoRanks[cellIndex] = 0;
|
|
93
96
|
cellStore.cycleGroupIds[cellIndex] = -1;
|
|
94
|
-
rowId
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
97
|
+
const materializedRowId = rowId ?? ensureRowId(rowIndex);
|
|
98
|
+
rowId = materializedRowId;
|
|
99
|
+
rowIds[rowIndex] = materializedRowId;
|
|
100
|
+
const colId = (colIds[colIndex] ??= ensureColumnId(colIndex));
|
|
101
|
+
attachFreshCell(rowIndex, colIndex, cellIndex, materializedRowId, colId);
|
|
98
102
|
if (typeof raw === 'number') {
|
|
99
103
|
cellStore.tags[cellIndex] = ValueTag.Number;
|
|
100
104
|
cellStore.numbers[cellIndex] = raw;
|
|
@@ -145,6 +149,7 @@ function createFreshInitialCellAttacher(sheet) {
|
|
|
145
149
|
let lastRowId;
|
|
146
150
|
let lastRowSet;
|
|
147
151
|
const columnSets = new Map();
|
|
152
|
+
const setGridCell = sheet.grid.createRowMajorSetter();
|
|
148
153
|
const ensureResidentColumnSet = (id) => {
|
|
149
154
|
const cached = columnSets.get(id);
|
|
150
155
|
if (cached) {
|
|
@@ -177,7 +182,7 @@ function createFreshInitialCellAttacher(sheet) {
|
|
|
177
182
|
residentByCell.set(cellIndex, { rowId, colId });
|
|
178
183
|
ensureResidentRowSet(rowId).add(cellIndex);
|
|
179
184
|
ensureResidentColumnSet(colId).add(cellIndex);
|
|
180
|
-
|
|
185
|
+
setGridCell(row, col, cellIndex);
|
|
181
186
|
};
|
|
182
187
|
}
|
|
183
188
|
function readInitialFormulaSource(raw) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initial-sheet-load.js","sourceRoot":"","sources":["../src/initial-sheet-load.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,8BAA8B,EAC9B,kBAAkB,GAKnB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAOrD,MAAM,UAAU,uBAAuB,CACrC,MAAyB,EACzB,OAAe,EACf,OAAuB,EACvB,UAAkD;IAElD,8BAA8B,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM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AS,yBAAyB,CAAC,cAA0B,EAAE,KAAa;IAC1E,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC,CAAA;IACtC,IAAI,UAAU,GAAG,CAAC,CAAA;IAClB,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,cAAc,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QACxD,IAAI,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,OAAO,CAAC,UAAU,CAAC,GAAG,GAAG,CAAA;YACzB,UAAU,IAAI,CAAC,CAAA;QACjB,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAMrC;IACC,MAAM,QAAQ,GAAG,4BAA4B,CAAC,IAAI,CAAC,CAAA;IACnD,IAAI,QAAQ,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtC,OAAM;IACR,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,6BAA6B,CAAC,QAAQ,CAAC,WAAW,EAAE,QAAQ,CAAC,iBAAiB,CAAC,CAAA;AAC7F,CAAC"}
|
|
@@ -256,8 +256,12 @@ export declare class WorkPaper {
|
|
|
256
256
|
private computeNamedExpressionChanges;
|
|
257
257
|
private canUseTrackedStructuralFastPath;
|
|
258
258
|
private canUseTrackedMutationFastPath;
|
|
259
|
+
private canUseNamedExpressionChangeFastPath;
|
|
260
|
+
private canUseMetadataOnlySheetRenameFastPath;
|
|
259
261
|
private downgradeTrackedBatchFastPath;
|
|
260
262
|
private computeTrackedChangesWithoutVisibilityCache;
|
|
263
|
+
private tryCaptureNamedExpressionChangeWithoutSnapshots;
|
|
264
|
+
private tryRenameSheetWithoutVisibilitySnapshots;
|
|
261
265
|
private captureTrackedChangesWithoutVisibilityCache;
|
|
262
266
|
private tryBuildDirectSingleLiteralTrackedChange;
|
|
263
267
|
private tryBuildDirectExistingNumericTrackedChanges;
|
|
@@ -256,6 +256,45 @@ function scalarFromResult(result) {
|
|
|
256
256
|
}
|
|
257
257
|
return result.values[0] ?? emptyValue();
|
|
258
258
|
}
|
|
259
|
+
const SIMPLE_NUMERIC_FORMULA_RE = /^[+-]?(?:(?:\d+(?:\.\d*)?)|(?:\.\d+))(?:[Ee][+-]?\d+)?$/;
|
|
260
|
+
function tryReadSimpleScalarFormulaBody(raw) {
|
|
261
|
+
if (typeof raw !== 'string') {
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
const trimmed = raw.trim();
|
|
265
|
+
if (!trimmed.startsWith('=')) {
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
const body = trimmed.slice(1).trim();
|
|
269
|
+
return body.length === 0 ? undefined : body;
|
|
270
|
+
}
|
|
271
|
+
function tryEvaluateSimpleScalarFormulaBody(body) {
|
|
272
|
+
if (SIMPLE_NUMERIC_FORMULA_RE.test(body)) {
|
|
273
|
+
const value = Number(body);
|
|
274
|
+
return Number.isFinite(value) ? { tag: ValueTag.Number, value: Object.is(value, -0) ? 0 : value } : undefined;
|
|
275
|
+
}
|
|
276
|
+
const upper = body.toUpperCase();
|
|
277
|
+
if (upper === 'TRUE') {
|
|
278
|
+
return { tag: ValueTag.Boolean, value: true };
|
|
279
|
+
}
|
|
280
|
+
if (upper === 'FALSE') {
|
|
281
|
+
return { tag: ValueTag.Boolean, value: false };
|
|
282
|
+
}
|
|
283
|
+
if (body.length >= 2 && body.startsWith('"') && body.endsWith('"')) {
|
|
284
|
+
return { tag: ValueTag.String, value: body.slice(1, -1).replaceAll('""', '"'), stringId: 0 };
|
|
285
|
+
}
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
288
|
+
function tryEvaluateSimpleNamedExpression(raw) {
|
|
289
|
+
if (raw === null || typeof raw === 'number' || typeof raw === 'boolean') {
|
|
290
|
+
return scalarValueFromLiteral(raw);
|
|
291
|
+
}
|
|
292
|
+
if (typeof raw === 'string' && !raw.trim().startsWith('=')) {
|
|
293
|
+
return scalarValueFromLiteral(raw);
|
|
294
|
+
}
|
|
295
|
+
const body = tryReadSimpleScalarFormulaBody(raw);
|
|
296
|
+
return body === undefined ? undefined : tryEvaluateSimpleScalarFormulaBody(body);
|
|
297
|
+
}
|
|
259
298
|
function valuesEqual(left, right) {
|
|
260
299
|
if (left.tag !== right.tag) {
|
|
261
300
|
return false;
|
|
@@ -569,10 +608,18 @@ function inspectSheetDimensionsWithinLimits(sheetName, sheet, config) {
|
|
|
569
608
|
throw new WorkPaperUnableToParseError({ sheetName, reason: 'Rows must be arrays' });
|
|
570
609
|
}
|
|
571
610
|
width = Math.max(width, row.length);
|
|
611
|
+
let rowHasMaterializedCell = false;
|
|
612
|
+
let lastMaterializedCol = -1;
|
|
572
613
|
for (let colIndex = 0; colIndex < row.length; colIndex += 1) {
|
|
573
614
|
if (row[colIndex] !== null) {
|
|
574
|
-
|
|
575
|
-
|
|
615
|
+
rowHasMaterializedCell = true;
|
|
616
|
+
lastMaterializedCol = colIndex;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (rowHasMaterializedCell) {
|
|
620
|
+
materializedHeight = rowIndex + 1;
|
|
621
|
+
if (lastMaterializedCol + 1 > materializedWidth) {
|
|
622
|
+
materializedWidth = lastMaterializedCol + 1;
|
|
576
623
|
}
|
|
577
624
|
}
|
|
578
625
|
}
|
|
@@ -625,18 +672,26 @@ function inspectSheetWithinLimits(sheetName, sheet, config) {
|
|
|
625
672
|
throw new WorkPaperUnableToParseError({ sheetName, reason: 'Rows must be arrays' });
|
|
626
673
|
}
|
|
627
674
|
width = Math.max(width, row.length);
|
|
675
|
+
let rowHasMaterializedCell = false;
|
|
676
|
+
let lastMaterializedCol = -1;
|
|
628
677
|
for (let colIndex = 0; colIndex < row.length; colIndex += 1) {
|
|
629
678
|
const cell = row[colIndex];
|
|
630
679
|
if (cell !== null) {
|
|
631
680
|
materializedCellCount += 1;
|
|
632
|
-
|
|
633
|
-
|
|
681
|
+
rowHasMaterializedCell = true;
|
|
682
|
+
lastMaterializedCol = colIndex;
|
|
634
683
|
}
|
|
635
684
|
if (typeof cell === 'string' && cellHasFormulaPrefix(cell)) {
|
|
636
685
|
formulaCellCount += 1;
|
|
637
686
|
hasFormula = true;
|
|
638
687
|
}
|
|
639
688
|
}
|
|
689
|
+
if (rowHasMaterializedCell) {
|
|
690
|
+
materializedHeight = rowIndex + 1;
|
|
691
|
+
if (lastMaterializedCol + 1 > materializedWidth) {
|
|
692
|
+
materializedWidth = lastMaterializedCol + 1;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
640
695
|
}
|
|
641
696
|
if (height > (config.maxRows ?? MAX_ROWS) || width > (config.maxColumns ?? MAX_COLS)) {
|
|
642
697
|
throw new WorkPaperSheetSizeLimitExceededError();
|
|
@@ -659,14 +714,14 @@ function cellHasFormulaPrefix(value) {
|
|
|
659
714
|
}
|
|
660
715
|
return value.trimStart().charCodeAt(0) === 61;
|
|
661
716
|
}
|
|
662
|
-
function
|
|
663
|
-
|
|
664
|
-
if (runtimeSnapshot.sheets.length !== sheetNames.length) {
|
|
717
|
+
function runtimeSnapshotMatchesSheetEntries(sheetEntries, runtimeSnapshot) {
|
|
718
|
+
if (runtimeSnapshot.sheets.length !== sheetEntries.length) {
|
|
665
719
|
return false;
|
|
666
720
|
}
|
|
667
721
|
const matchedNames = new Set();
|
|
722
|
+
const sheetNames = new Set(sheetEntries.map(([sheetName]) => sheetName));
|
|
668
723
|
for (const snapshotSheet of runtimeSnapshot.sheets) {
|
|
669
|
-
if (!
|
|
724
|
+
if (!sheetNames.has(snapshotSheet.name) || matchedNames.has(snapshotSheet.name)) {
|
|
670
725
|
return false;
|
|
671
726
|
}
|
|
672
727
|
matchedNames.add(snapshotSheet.name);
|
|
@@ -771,6 +826,10 @@ class WorkPaperEmitter {
|
|
|
771
826
|
hasListeners(eventName) {
|
|
772
827
|
return this.listeners[eventName].size > 0 || this.detailedListeners[eventName].size > 0;
|
|
773
828
|
}
|
|
829
|
+
hasAnyListeners() {
|
|
830
|
+
return (Object.values(this.listeners).some((listeners) => listeners.size > 0) ||
|
|
831
|
+
Object.values(this.detailedListeners).some((listeners) => listeners.size > 0));
|
|
832
|
+
}
|
|
774
833
|
emitDetailed(event) {
|
|
775
834
|
this.dispatchDetailed(event);
|
|
776
835
|
}
|
|
@@ -1087,52 +1146,57 @@ export class WorkPaper {
|
|
|
1087
1146
|
}
|
|
1088
1147
|
static buildFromSheets(sheets, configInput = {}, namedExpressions = []) {
|
|
1089
1148
|
const workbook = new WorkPaper(configInput);
|
|
1149
|
+
const sheetEntries = Object.entries(sheets);
|
|
1090
1150
|
const runtimeSnapshot = namedExpressions.length === 0 ? readRuntimeSnapshot(sheets) : undefined;
|
|
1091
|
-
const runtimeSnapshotMatchesSheets = runtimeSnapshot !== undefined &&
|
|
1151
|
+
const runtimeSnapshotMatchesSheets = runtimeSnapshot !== undefined && runtimeSnapshotMatchesSheetEntries(sheetEntries, runtimeSnapshot);
|
|
1092
1152
|
const runtimeSnapshotSheetsByName = runtimeSnapshotMatchesSheets
|
|
1093
1153
|
? new Map(runtimeSnapshot.sheets.map((sheet) => [sheet.name, sheet]))
|
|
1094
1154
|
: undefined;
|
|
1095
1155
|
const runtimeImageSheetCellsByName = runtimeSnapshotMatchesSheets && runtimeSnapshot
|
|
1096
1156
|
? new Map((readRuntimeImage(runtimeSnapshot)?.sheetCells ?? []).map((sheet) => [sheet.sheetName, sheet]))
|
|
1097
1157
|
: undefined;
|
|
1098
|
-
const inspectedSheets =
|
|
1099
|
-
|
|
1158
|
+
const inspectedSheets = [];
|
|
1159
|
+
for (let index = 0; index < sheetEntries.length; index += 1) {
|
|
1160
|
+
const [sheetName, sheet] = sheetEntries[index];
|
|
1100
1161
|
const snapshotSheet = runtimeSnapshotSheetsByName?.get(sheetName);
|
|
1101
|
-
inspectedSheets
|
|
1162
|
+
inspectedSheets[index] = snapshotSheet
|
|
1102
1163
|
? (() => {
|
|
1164
|
+
const runtimeSheetCells = runtimeImageSheetCellsByName?.get(sheetName);
|
|
1103
1165
|
const dimensions = inspectRuntimeSnapshotSheetDimensionsWithinLimits({
|
|
1104
1166
|
sheetName,
|
|
1105
1167
|
snapshotSheet,
|
|
1106
|
-
runtimeSheetCells
|
|
1168
|
+
runtimeSheetCells,
|
|
1107
1169
|
config: workbook.config,
|
|
1108
1170
|
});
|
|
1109
1171
|
return {
|
|
1110
1172
|
hasFormula: false,
|
|
1111
1173
|
dimensions,
|
|
1112
|
-
materializedCellCount:
|
|
1174
|
+
materializedCellCount: runtimeSheetCells?.cellCount ?? 0,
|
|
1113
1175
|
maxColumnCount: dimensions.width,
|
|
1114
1176
|
formulaCellCount: 0,
|
|
1115
1177
|
};
|
|
1116
1178
|
})()
|
|
1117
|
-
: inspectSheetWithinLimits(sheetName, sheet, workbook.config)
|
|
1118
|
-
}
|
|
1179
|
+
: inspectSheetWithinLimits(sheetName, sheet, workbook.config);
|
|
1180
|
+
}
|
|
1119
1181
|
workbook.withEngineEventCaptureDisabled(() => {
|
|
1120
1182
|
if (runtimeSnapshot && runtimeSnapshotMatchesSheets) {
|
|
1121
1183
|
workbook.engine.importSnapshot(runtimeSnapshot);
|
|
1122
1184
|
}
|
|
1123
1185
|
else {
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1186
|
+
const sheetIds = [];
|
|
1187
|
+
for (let index = 0; index < sheetEntries.length; index += 1) {
|
|
1188
|
+
sheetIds[index] = workbook.engine.createSheetForInitialization(sheetEntries[index][0]);
|
|
1189
|
+
}
|
|
1127
1190
|
namedExpressions.forEach((expression) => {
|
|
1128
1191
|
workbook.upsertNamedExpressionInternal(expression, { duringInitialization: true });
|
|
1129
1192
|
});
|
|
1130
|
-
|
|
1131
|
-
const
|
|
1132
|
-
const
|
|
1193
|
+
for (let index = 0; index < sheetEntries.length; index += 1) {
|
|
1194
|
+
const [, sheet] = sheetEntries[index];
|
|
1195
|
+
const sheetId = sheetIds[index];
|
|
1196
|
+
const inspected = inspectedSheets[index];
|
|
1133
1197
|
if (!inspected?.hasFormula) {
|
|
1134
1198
|
loadInitialLiteralSheet(workbook.engine, sheetId, sheet, inspected);
|
|
1135
|
-
|
|
1199
|
+
continue;
|
|
1136
1200
|
}
|
|
1137
1201
|
const rewriteInitialFormula = workbook.namedExpressions.size === 0 && workbook.functionAliasLookup.size === 0
|
|
1138
1202
|
? (formula) => formula
|
|
@@ -1144,14 +1208,15 @@ export class WorkPaper {
|
|
|
1144
1208
|
rewriteFormula: rewriteInitialFormula,
|
|
1145
1209
|
inspection: inspected,
|
|
1146
1210
|
});
|
|
1147
|
-
}
|
|
1211
|
+
}
|
|
1148
1212
|
}
|
|
1149
|
-
|
|
1150
|
-
const
|
|
1151
|
-
|
|
1152
|
-
|
|
1213
|
+
for (let index = 0; index < sheetEntries.length; index += 1) {
|
|
1214
|
+
const sheetId = workbook.requireSheetId(sheetEntries[index][0]);
|
|
1215
|
+
const inspected = inspectedSheets[index];
|
|
1216
|
+
if (inspected !== undefined) {
|
|
1217
|
+
workbook.cacheInitializedSheetDimensions(sheetId, inspected.dimensions);
|
|
1153
1218
|
}
|
|
1154
|
-
}
|
|
1219
|
+
}
|
|
1155
1220
|
});
|
|
1156
1221
|
workbook.clearHistoryStacks();
|
|
1157
1222
|
workbook.resetChangeTrackingCaches();
|
|
@@ -1929,9 +1994,15 @@ export class WorkPaper {
|
|
|
1929
1994
|
});
|
|
1930
1995
|
}
|
|
1931
1996
|
changeNamedExpression(expressionName, expression, scope, options) {
|
|
1932
|
-
|
|
1997
|
+
this.validateNamedExpression(expressionName, expression, scope);
|
|
1998
|
+
const existing = this.namedExpressions.get(makeNamedExpressionKey(expressionName, scope));
|
|
1999
|
+
if (!existing) {
|
|
1933
2000
|
throw new WorkPaperNamedExpressionDoesNotExistError(expressionName);
|
|
1934
2001
|
}
|
|
2002
|
+
const fastPathChanges = this.tryCaptureNamedExpressionChangeWithoutSnapshots(existing, expressionName, expression, scope, options);
|
|
2003
|
+
if (fastPathChanges) {
|
|
2004
|
+
return fastPathChanges;
|
|
2005
|
+
}
|
|
1935
2006
|
return this.captureChanges(undefined, () => {
|
|
1936
2007
|
this.upsertNamedExpressionInternal({ name: expressionName, expression, scope, options }, { duringInitialization: false });
|
|
1937
2008
|
});
|
|
@@ -2548,11 +2619,38 @@ export class WorkPaper {
|
|
|
2548
2619
|
});
|
|
2549
2620
|
}
|
|
2550
2621
|
renameSheet(sheetId, nextName) {
|
|
2551
|
-
|
|
2622
|
+
const sheet = this.sheetRecord(sheetId);
|
|
2623
|
+
const newName = nextName.trim();
|
|
2624
|
+
if (newName.length === 0) {
|
|
2625
|
+
throw new WorkPaperInvalidArgumentsError('Sheet name must be non-empty');
|
|
2626
|
+
}
|
|
2627
|
+
const existing = this.engine.workbook.getSheet(newName);
|
|
2628
|
+
if (existing && existing.id !== sheetId) {
|
|
2552
2629
|
throw new WorkPaperSheetError(`Sheet '${sheetId}' cannot be renamed to '${nextName}'`);
|
|
2553
2630
|
}
|
|
2554
|
-
const oldName =
|
|
2555
|
-
|
|
2631
|
+
const oldName = sheet.name;
|
|
2632
|
+
if (this.canUseMetadataOnlySheetRenameFastPath()) {
|
|
2633
|
+
this.assertNotDisposed();
|
|
2634
|
+
if (this.pendingLazyTrackedChanges.length === 0 && !this.batchUsesTrackedFastPath) {
|
|
2635
|
+
try {
|
|
2636
|
+
if (this.engine.renameSheetMetadataOnly(oldName, newName)) {
|
|
2637
|
+
this.sheetRecordsCache = null;
|
|
2638
|
+
this.trackedEngineEvents = [];
|
|
2639
|
+
return [];
|
|
2640
|
+
}
|
|
2641
|
+
}
|
|
2642
|
+
catch (error) {
|
|
2643
|
+
if (error instanceof Error && WORKPAPER_PUBLIC_ERROR_NAMES.has(error.name)) {
|
|
2644
|
+
throw error;
|
|
2645
|
+
}
|
|
2646
|
+
throw new WorkPaperOperationError(this.messageOf(error, 'Mutation failed'));
|
|
2647
|
+
}
|
|
2648
|
+
}
|
|
2649
|
+
const fastPathChanges = this.tryRenameSheetWithoutVisibilitySnapshots(oldName, newName);
|
|
2650
|
+
if (fastPathChanges) {
|
|
2651
|
+
return fastPathChanges;
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2556
2654
|
return this.captureChanges({
|
|
2557
2655
|
eventName: 'sheetRenamed',
|
|
2558
2656
|
payload: {
|
|
@@ -3634,6 +3732,12 @@ export class WorkPaper {
|
|
|
3634
3732
|
canUseTrackedMutationFastPath() {
|
|
3635
3733
|
return this.batchDepth === 0 && !this.evaluationSuspended && this.visibilityCache === null && this.namedExpressions.size === 0;
|
|
3636
3734
|
}
|
|
3735
|
+
canUseNamedExpressionChangeFastPath() {
|
|
3736
|
+
return this.batchDepth === 0 && !this.evaluationSuspended && this.visibilityCache === null && !this.emitter.hasAnyListeners();
|
|
3737
|
+
}
|
|
3738
|
+
canUseMetadataOnlySheetRenameFastPath() {
|
|
3739
|
+
return this.batchDepth === 0 && !this.evaluationSuspended && this.visibilityCache === null && !this.emitter.hasAnyListeners();
|
|
3740
|
+
}
|
|
3637
3741
|
downgradeTrackedBatchFastPath() {
|
|
3638
3742
|
if (!this.batchUsesTrackedFastPath || this.batchDepth === 0) {
|
|
3639
3743
|
return;
|
|
@@ -3658,6 +3762,136 @@ export class WorkPaper {
|
|
|
3658
3762
|
}
|
|
3659
3763
|
return fastPath.changes;
|
|
3660
3764
|
}
|
|
3765
|
+
tryCaptureNamedExpressionChangeWithoutSnapshots(existing, expressionName, expression, scope, options) {
|
|
3766
|
+
if (!this.canUseNamedExpressionChangeFastPath()) {
|
|
3767
|
+
return null;
|
|
3768
|
+
}
|
|
3769
|
+
this.assertNotDisposed();
|
|
3770
|
+
this.materializePendingLazyTrackedChanges();
|
|
3771
|
+
this.downgradeTrackedBatchFastPath();
|
|
3772
|
+
if (!this.canUseNamedExpressionChangeFastPath()) {
|
|
3773
|
+
return null;
|
|
3774
|
+
}
|
|
3775
|
+
const key = makeNamedExpressionKey(existing.publicName, existing.scope);
|
|
3776
|
+
const cachedBeforeValue = this.namedExpressionValueCache?.get(key);
|
|
3777
|
+
const beforeValue = cachedBeforeValue ?? this.evaluateNamedExpression(existing);
|
|
3778
|
+
const afterScalarValue = tryEvaluateSimpleNamedExpression(expression);
|
|
3779
|
+
if (afterScalarValue?.tag === ValueTag.Number && !this.emitter.hasAnyListeners()) {
|
|
3780
|
+
const trimmed = expressionName.trim();
|
|
3781
|
+
const internalName = scope === undefined ? trimmed : makeInternalScopedName(scope, trimmed);
|
|
3782
|
+
const record = {
|
|
3783
|
+
publicName: trimmed,
|
|
3784
|
+
normalizedName: normalizeName(trimmed),
|
|
3785
|
+
internalName,
|
|
3786
|
+
scope,
|
|
3787
|
+
expression,
|
|
3788
|
+
options: options ? structuredClone(options) : undefined,
|
|
3789
|
+
};
|
|
3790
|
+
const definedNameSnapshot = this.toDefinedNameSnapshot(expression, scope);
|
|
3791
|
+
try {
|
|
3792
|
+
const changedCellIndices = this.engine.upsertNumericDefinedNameFast(internalName, definedNameSnapshot, afterScalarValue.value);
|
|
3793
|
+
if (changedCellIndices) {
|
|
3794
|
+
this.namedExpressions.set(makeNamedExpressionKey(trimmed, scope), record);
|
|
3795
|
+
if (this.namedExpressionValueCache) {
|
|
3796
|
+
this.namedExpressionValueCache.set(key, cloneNamedExpressionValue(afterScalarValue));
|
|
3797
|
+
}
|
|
3798
|
+
const cellChanges = changedCellIndices
|
|
3799
|
+
.map((cellIndex) => this.readSingleTrackedCellChange(cellIndex))
|
|
3800
|
+
.filter((change) => change !== undefined);
|
|
3801
|
+
const orderedCellChanges = cellChanges.length > 1 ? orderWorkPaperCellChanges(cellChanges, this.listSheetRecords(), cellChanges.length) : cellChanges;
|
|
3802
|
+
return matrixValuesEqual(beforeValue, afterScalarValue)
|
|
3803
|
+
? orderedCellChanges
|
|
3804
|
+
: [
|
|
3805
|
+
...orderedCellChanges,
|
|
3806
|
+
{
|
|
3807
|
+
kind: 'named-expression',
|
|
3808
|
+
name: record.publicName,
|
|
3809
|
+
scope: record.scope,
|
|
3810
|
+
newValue: cloneNamedExpressionValue(afterScalarValue),
|
|
3811
|
+
},
|
|
3812
|
+
];
|
|
3813
|
+
}
|
|
3814
|
+
}
|
|
3815
|
+
catch (error) {
|
|
3816
|
+
if (error instanceof Error && WORKPAPER_PUBLIC_ERROR_NAMES.has(error.name)) {
|
|
3817
|
+
throw error;
|
|
3818
|
+
}
|
|
3819
|
+
throw new WorkPaperOperationError(this.messageOf(error, 'Mutation failed'));
|
|
3820
|
+
}
|
|
3821
|
+
}
|
|
3822
|
+
this.drainTrackedEngineEvents();
|
|
3823
|
+
try {
|
|
3824
|
+
this.withRetainedTrackedEngineEventIndices(() => {
|
|
3825
|
+
this.upsertNamedExpressionInternal({ name: expressionName, expression, scope, options }, { duringInitialization: false });
|
|
3826
|
+
});
|
|
3827
|
+
}
|
|
3828
|
+
catch (error) {
|
|
3829
|
+
if (error instanceof Error && WORKPAPER_PUBLIC_ERROR_NAMES.has(error.name)) {
|
|
3830
|
+
throw error;
|
|
3831
|
+
}
|
|
3832
|
+
throw new WorkPaperOperationError(this.messageOf(error, 'Mutation failed'));
|
|
3833
|
+
}
|
|
3834
|
+
const updated = this.namedExpressionRecord(expressionName, scope);
|
|
3835
|
+
const afterValue = cloneNamedExpressionValue(this.evaluateNamedExpression(updated));
|
|
3836
|
+
if (this.namedExpressionValueCache) {
|
|
3837
|
+
this.namedExpressionValueCache.set(key, cloneNamedExpressionValue(afterValue));
|
|
3838
|
+
}
|
|
3839
|
+
const cellChanges = this.computeTrackedChangesWithoutVisibilityCache(this.drainTrackedEngineEvents(), {
|
|
3840
|
+
preferLazyPublicChanges: !this.emitter.hasAnyListeners(),
|
|
3841
|
+
});
|
|
3842
|
+
if (matrixValuesEqual(beforeValue, afterValue)) {
|
|
3843
|
+
return cellChanges;
|
|
3844
|
+
}
|
|
3845
|
+
return [
|
|
3846
|
+
...cellChanges,
|
|
3847
|
+
{
|
|
3848
|
+
kind: 'named-expression',
|
|
3849
|
+
name: updated.publicName,
|
|
3850
|
+
scope: updated.scope,
|
|
3851
|
+
newValue: cloneNamedExpressionValue(afterValue),
|
|
3852
|
+
},
|
|
3853
|
+
];
|
|
3854
|
+
}
|
|
3855
|
+
tryRenameSheetWithoutVisibilitySnapshots(oldName, newName) {
|
|
3856
|
+
if (!this.canUseMetadataOnlySheetRenameFastPath()) {
|
|
3857
|
+
return null;
|
|
3858
|
+
}
|
|
3859
|
+
this.assertNotDisposed();
|
|
3860
|
+
if (this.pendingLazyTrackedChanges.length > 0) {
|
|
3861
|
+
this.materializePendingLazyTrackedChanges();
|
|
3862
|
+
}
|
|
3863
|
+
if (this.batchUsesTrackedFastPath) {
|
|
3864
|
+
this.downgradeTrackedBatchFastPath();
|
|
3865
|
+
}
|
|
3866
|
+
if (!this.canUseMetadataOnlySheetRenameFastPath()) {
|
|
3867
|
+
return null;
|
|
3868
|
+
}
|
|
3869
|
+
if (this.trackedEngineEvents.length > 0) {
|
|
3870
|
+
this.drainTrackedEngineEvents();
|
|
3871
|
+
}
|
|
3872
|
+
try {
|
|
3873
|
+
if (this.engine.renameSheetMetadataOnly(oldName, newName)) {
|
|
3874
|
+
this.sheetRecordsCache = null;
|
|
3875
|
+
this.trackedEngineEvents = [];
|
|
3876
|
+
}
|
|
3877
|
+
else {
|
|
3878
|
+
this.withEngineEventCaptureDisabled(() => {
|
|
3879
|
+
this.engine.renameSheet(oldName, newName);
|
|
3880
|
+
this.sheetRecordsCache = null;
|
|
3881
|
+
});
|
|
3882
|
+
}
|
|
3883
|
+
}
|
|
3884
|
+
catch (error) {
|
|
3885
|
+
if (error instanceof Error && WORKPAPER_PUBLIC_ERROR_NAMES.has(error.name)) {
|
|
3886
|
+
throw error;
|
|
3887
|
+
}
|
|
3888
|
+
throw new WorkPaperOperationError(this.messageOf(error, 'Mutation failed'));
|
|
3889
|
+
}
|
|
3890
|
+
if (this.trackedEngineEvents.length > 0) {
|
|
3891
|
+
this.drainTrackedEngineEvents();
|
|
3892
|
+
}
|
|
3893
|
+
return [];
|
|
3894
|
+
}
|
|
3661
3895
|
captureTrackedChangesWithoutVisibilityCache(mutate, options = {}) {
|
|
3662
3896
|
this.assertNotDisposed();
|
|
3663
3897
|
if (this.pendingLazyTrackedChanges.length > 0) {
|
|
@@ -4312,7 +4546,7 @@ export class WorkPaper {
|
|
|
4312
4546
|
}
|
|
4313
4547
|
else {
|
|
4314
4548
|
Object.keys(serializedSheets).forEach((sheetName) => {
|
|
4315
|
-
this.engine.
|
|
4549
|
+
this.engine.createSheetForInitialization(sheetName);
|
|
4316
4550
|
});
|
|
4317
4551
|
serializedNamedExpressions.forEach((expression) => {
|
|
4318
4552
|
this.upsertNamedExpressionInternal(expression, { duringInitialization: true });
|
|
@@ -4454,6 +4688,10 @@ export class WorkPaper {
|
|
|
4454
4688
|
this.sheetRecord(scope);
|
|
4455
4689
|
}
|
|
4456
4690
|
if (isFormulaContent(expression)) {
|
|
4691
|
+
const simpleBody = tryReadSimpleScalarFormulaBody(expression);
|
|
4692
|
+
if (simpleBody !== undefined && tryEvaluateSimpleScalarFormulaBody(simpleBody) !== undefined) {
|
|
4693
|
+
return;
|
|
4694
|
+
}
|
|
4457
4695
|
try {
|
|
4458
4696
|
const parsed = parseFormula(stripLeadingEquals(expression));
|
|
4459
4697
|
if (formulaHasRelativeReferences(parsed)) {
|
|
@@ -4472,7 +4710,9 @@ export class WorkPaper {
|
|
|
4472
4710
|
}
|
|
4473
4711
|
}
|
|
4474
4712
|
upsertNamedExpressionInternal(expression, options) {
|
|
4475
|
-
|
|
4713
|
+
if (options.skipValidation !== true) {
|
|
4714
|
+
this.validateNamedExpression(expression.name, expression.expression, expression.scope);
|
|
4715
|
+
}
|
|
4476
4716
|
const trimmed = expression.name.trim();
|
|
4477
4717
|
const internalName = expression.scope === undefined ? trimmed : makeInternalScopedName(expression.scope, trimmed);
|
|
4478
4718
|
const record = {
|
|
@@ -4494,6 +4734,13 @@ export class WorkPaper {
|
|
|
4494
4734
|
return expression;
|
|
4495
4735
|
}
|
|
4496
4736
|
if (typeof expression === 'string' && expression.trim().startsWith('=')) {
|
|
4737
|
+
const simpleBody = tryReadSimpleScalarFormulaBody(expression);
|
|
4738
|
+
if (simpleBody !== undefined && tryEvaluateSimpleScalarFormulaBody(simpleBody) !== undefined) {
|
|
4739
|
+
return {
|
|
4740
|
+
kind: 'formula',
|
|
4741
|
+
formula: `=${simpleBody}`,
|
|
4742
|
+
};
|
|
4743
|
+
}
|
|
4497
4744
|
return {
|
|
4498
4745
|
kind: 'formula',
|
|
4499
4746
|
formula: `=${this.rewriteFormulaForStorage(stripLeadingEquals(expression), scope ?? this.listSheetRecords()[0]?.id ?? 1)}`,
|
|
@@ -4510,13 +4757,11 @@ export class WorkPaper {
|
|
|
4510
4757
|
}
|
|
4511
4758
|
evaluateNamedExpression(expression) {
|
|
4512
4759
|
const raw = expression.expression;
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
if (typeof raw === 'string' && !raw.trim().startsWith('=')) {
|
|
4517
|
-
return scalarValueFromLiteral(raw);
|
|
4760
|
+
const simpleValue = tryEvaluateSimpleNamedExpression(raw);
|
|
4761
|
+
if (simpleValue !== undefined) {
|
|
4762
|
+
return simpleValue;
|
|
4518
4763
|
}
|
|
4519
|
-
return this.calculateFormula(raw, expression.scope);
|
|
4764
|
+
return typeof raw === 'string' ? this.calculateFormula(raw, expression.scope) : scalarValueFromLiteral(raw);
|
|
4520
4765
|
}
|
|
4521
4766
|
cellSnapshotToRawContent(cell, ownerSheetId) {
|
|
4522
4767
|
if (cell.formula) {
|