@jsb188/mday 1.1.11 → 1.1.12
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.
- package/package.json +58 -23
- package/src/constants/agentMemory.ts +14 -45
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +5 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +156 -47
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +12 -38
- package/src/constants/dataTableFieldTypes.generated.ts +3 -7
- package/src/constants/docAccess.ts +3 -2
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +114 -12
- package/src/constants/fieldDoc.ts +74 -4
- package/src/constants/graphqlReactivity.ts +108 -25
- package/src/constants/log.ts +9 -0
- package/src/constants/logDisplay/README.md +88 -0
- package/src/constants/logDisplay/defaults.ts +39 -0
- package/src/constants/logDisplay/index.ts +27 -0
- package/src/constants/logDisplay/operations/arable.ts +16 -0
- package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
- package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
- package/src/constants/logDisplay/shared/accounting.ts +13 -0
- package/src/constants/logDisplay/shared/interactions.ts +13 -0
- package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
- package/src/constants/logTaxonomy.generated.ts +1834 -730
- package/src/constants/organization.ts +13 -14
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +65 -101
- package/src/constants/sms.ts +18 -0
- package/src/constants/storage.ts +33 -9
- package/src/constants/usage.ts +3 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +106 -283
- package/src/schemas/inboundContact.ts +5 -5
- package/src/types/agentMemory.d.ts +38 -14
- package/src/types/agentNote.d.ts +443 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1043 -193
- package/src/types/contact.d.ts +15 -0
- package/src/types/csvExport.d.ts +213 -0
- package/src/types/dataAnalysis.d.ts +44 -0
- package/src/types/dataTable.d.ts +102 -309
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +144 -55
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +579 -150
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +8 -0
- package/src/types/log.d.ts +94 -3
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +8 -3
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +180 -463
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +266 -27
- package/src/types/workflow.d.ts +196 -66
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +31 -14
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +642 -209
- package/src/utils/campaignAI.ts +72 -0
- package/src/utils/campaignAccess.ts +239 -0
- package/src/utils/campaignEmail.ts +601 -0
- package/src/utils/campaignEmailCompiler.ts +372 -0
- package/src/utils/campaignEmailImages.ts +60 -0
- package/src/utils/campaignEmailStyles.ts +544 -0
- package/src/utils/campaignLifecycle.ts +104 -0
- package/src/utils/campaignPreview.ts +285 -0
- package/src/utils/contact.ts +50 -0
- package/src/utils/csvExport.ts +19 -0
- package/src/utils/dataTable.ts +18 -556
- package/src/utils/dataTableFieldTypeRegistry.ts +1 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/email.ts +208 -1
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +81 -37
- package/src/utils/fieldDocAnswers.ts +128 -0
- package/src/utils/fieldDocDefaults.ts +36 -0
- package/src/utils/fieldDocProgram.ts +36 -0
- package/src/utils/fieldDocSummary.ts +30 -0
- package/src/utils/log.ts +232 -141
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logStoreRead.ts +9 -13
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomyDisplay.ts +80 -124
- package/src/utils/noteDoc.ts +66 -284
- package/src/utils/organization.ts +117 -283
- package/src/utils/qrCode.helpers.ts +189 -0
- package/src/utils/qrCode.test.ts +519 -0
- package/src/utils/qrCode.ts +273 -0
- package/src/utils/richTextHTML.ts +385 -0
- package/src/utils/sheet.ts +123 -4834
- package/src/utils/sheetAxisMove.ts +77 -291
- package/src/utils/sheetBootstrap.ts +771 -1138
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +23 -88
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +17 -69
- package/src/utils/sheetFeatureReference.ts +183 -0
- package/src/utils/sheetFormulaArgs.ts +168 -0
- package/src/utils/sheetFormulaCompile.ts +475 -0
- package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
- package/src/utils/sheetFormulaCriteria.ts +656 -0
- package/src/utils/sheetFormulaDate.ts +444 -0
- package/src/utils/sheetFormulaEvaluation.ts +388 -403
- package/src/utils/sheetFormulaEvaluator.ts +589 -444
- package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
- package/src/utils/sheetFormulaLogical.ts +116 -0
- package/src/utils/sheetFormulaLookup.ts +488 -0
- package/src/utils/sheetFormulaMath.ts +48 -0
- package/src/utils/sheetFormulaParser.ts +729 -0
- package/src/utils/sheetFormulaRange.ts +330 -0
- package/src/utils/sheetFormulaReference.ts +703 -0
- package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
- package/src/utils/sheetFormulaReferenceDates.ts +237 -0
- package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
- package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
- package/src/utils/sheetFormulaReferenceMath.ts +95 -0
- package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
- package/src/utils/sheetFormulaReferenceText.ts +462 -0
- package/src/utils/sheetFormulaSyntax.ts +1027 -0
- package/src/utils/sheetFormulaText.ts +430 -0
- package/src/utils/sheetJournal.ts +140 -18
- package/src/utils/sheetNumberFormat.ts +68 -267
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +13 -43
- package/src/utils/sheetSnapshot.ts +176 -429
- package/src/utils/sheetStructureEdit.ts +537 -907
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/storage.ts +49 -3
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +199 -73
- package/src/utils/workflowLogFingerprint.ts +302 -0
- package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
- package/src/utils/workflowProgress.ts +280 -0
- package/src/utils/workflowTriggers.ts +61 -0
- package/tests/agentNote.test.ts +395 -0
- package/tests/campaignAI.test.ts +119 -0
- package/tests/campaignAccess.test.ts +239 -0
- package/tests/campaignEmail.test.ts +441 -0
- package/tests/campaignLifecycle.test.ts +134 -0
- package/tests/campaignPublication.test.ts +309 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +2 -1
- package/tests/dataTableRelativeDate.test.ts +412 -0
- package/tests/email.test.ts +39 -0
- package/tests/fieldDocProgram.test.ts +114 -0
- package/tests/logDisplay.fixtures.ts +67 -0
- package/tests/logDisplay.test.ts +227 -0
- package/tests/noteDoc.test.ts +37 -192
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +49 -40
- package/tests/sheetBootstrap.test.ts +1967 -0
- package/tests/sheetFeatureReference.test.ts +22 -0
- package/tests/sheetFormulaCriteria.test.ts +269 -0
- package/tests/sheetFormulaEvaluator.test.ts +93 -200
- package/tests/sheetFormulaFunctions.test.ts +538 -0
- package/tests/sheetFormulaLanguage.test.ts +361 -0
- package/tests/sheetFormulaParity.fixtures.ts +872 -0
- package/tests/sheetFormulaParity.test.ts +188 -0
- package/tests/sheetFormulaRange.test.ts +167 -0
- package/tests/sheetFormulaReference.test.ts +78 -0
- package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
- package/tests/sheetFormulaTextDate.test.ts +512 -0
- package/tests/sheetSequence.test.ts +4 -23
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +492 -37
- package/tests/sheetStructureReferences.test.ts +589 -0
- package/tests/workflowLifecycleStatus.test.ts +60 -0
- package/tests/workflowLogFingerprint.test.ts +203 -0
- package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
- package/tests/workflowProgress.test.ts +180 -0
- package/tests/workflowTriggers.test.ts +29 -0
- package/src/constants/agentDoc.ts +0 -12
- package/src/constants/logActivityGroupColors.generated.ts +0 -19
- package/src/constants/schedule.ts +0 -220
- package/src/constants/scheduleRuleTemplateSeed.ts +0 -138
- package/src/constants/scheduleRuleTemplates.generated.ts +0 -145
- package/src/constants/sheetRegionSources.generated.ts +0 -578
- package/src/schemas/fieldDocsQuery.ts +0 -12
- package/src/schemas/organization.ts +0 -68
- package/src/types/agentDoc.d.ts +0 -64
- package/src/types/noteDoc.d.ts +0 -86
- package/src/types/schedule.d.ts +0 -391
- package/src/utils/agentDoc.ts +0 -109
- package/src/utils/campaignFormEditor.ts +0 -871
- package/src/utils/dataTableRealtimeAuthority.ts +0 -209
- package/src/utils/dataTableRealtimeSelection.ts +0 -134
- package/src/utils/dataTableRowDocument.ts +0 -508
- package/src/utils/dataTableSource.ts +0 -230
- package/src/utils/schedule.ts +0 -799
- package/src/utils/scheduleEvaluation.ts +0 -1994
- package/src/utils/scheduleICS.ts +0 -246
- package/src/utils/scheduleRuleTemplates.ts +0 -188
- package/src/utils/sheetRegion.ts +0 -374
- package/src/utils/sheetRegionFilter.ts +0 -1259
- package/src/utils/sheetRegionSourceRegistry.ts +0 -594
- package/tests/schedule.test.ts +0 -693
- package/tests/scheduleEvaluation.test.ts +0 -1970
- package/tests/scheduleICS.test.ts +0 -208
- package/tests/scheduleRuleTemplates.test.ts +0 -176
- package/tests/scheduleSweepInvariants.test.ts +0 -428
- package/tests/sheetRegionFilter.test.ts +0 -1135
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
SheetMergedRangeObj,
|
|
5
|
-
} from '../types/sheet.d.ts';
|
|
1
|
+
import { SHEET_MAX_ROW_COUNT } from '../constants/sheet.ts';
|
|
2
|
+
import type { SheetAxisDesignObj, SheetDesignObj, SheetMergedRangeObj } from '../types/sheet.d.ts';
|
|
3
|
+
import { parseSheetFormulaExpression, tokenizeSheetFormulaReferences } from './sheetFormulaParser.ts';
|
|
6
4
|
import {
|
|
7
5
|
getSheetFormulaCellReferenceText,
|
|
6
|
+
getSheetFormulaColumnReferenceText,
|
|
8
7
|
getSheetFormulaExpression,
|
|
9
8
|
getSheetFormulaSheetTabNameLookupKey,
|
|
10
9
|
isSheetFormulaText,
|
|
11
|
-
parseSheetFormulaCall,
|
|
12
|
-
parseSheetFormulaExpression,
|
|
13
10
|
type SheetFormulaCellReference,
|
|
14
11
|
type SheetFormulaReferenceToken,
|
|
15
|
-
|
|
16
|
-
} from './sheet.ts';
|
|
12
|
+
} from './sheetFormulaSyntax.ts';
|
|
17
13
|
|
|
18
14
|
export type SheetAxisMoveType = 'COLUMN' | 'ROW';
|
|
19
15
|
|
|
@@ -36,9 +32,7 @@ export interface SheetAxisMoveInput {
|
|
|
36
32
|
* The moved source block occupies the original target interval after the
|
|
37
33
|
* forward move, so replay can invert the operation without materializing cells.
|
|
38
34
|
*/
|
|
39
|
-
export function getInverseSheetAxisMoveInput(
|
|
40
|
-
input: SheetAxisMoveInput,
|
|
41
|
-
): SheetAxisMoveInput {
|
|
35
|
+
export function getInverseSheetAxisMoveInput(input: SheetAxisMoveInput): SheetAxisMoveInput {
|
|
42
36
|
const width = input.sourceEndIndex - input.sourceStartIndex + 1;
|
|
43
37
|
|
|
44
38
|
return {
|
|
@@ -120,18 +114,10 @@ export function getSheetAxisMoveIndexes(params: {
|
|
|
120
114
|
const movingColumns = params.axis === 'COLUMN';
|
|
121
115
|
|
|
122
116
|
return {
|
|
123
|
-
sourceEndIndex: movingColumns
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
? params.sourceRange.startColumnIndex
|
|
128
|
-
: params.sourceRange.startRowIndex,
|
|
129
|
-
targetEndIndex: movingColumns
|
|
130
|
-
? params.targetRange.endColumnIndex
|
|
131
|
-
: params.targetRange.endRowIndex,
|
|
132
|
-
targetStartIndex: movingColumns
|
|
133
|
-
? params.targetRange.startColumnIndex
|
|
134
|
-
: params.targetRange.startRowIndex,
|
|
117
|
+
sourceEndIndex: movingColumns ? params.sourceRange.endColumnIndex : params.sourceRange.endRowIndex,
|
|
118
|
+
sourceStartIndex: movingColumns ? params.sourceRange.startColumnIndex : params.sourceRange.startRowIndex,
|
|
119
|
+
targetEndIndex: movingColumns ? params.targetRange.endColumnIndex : params.targetRange.endRowIndex,
|
|
120
|
+
targetStartIndex: movingColumns ? params.targetRange.startColumnIndex : params.targetRange.startRowIndex,
|
|
135
121
|
};
|
|
136
122
|
}
|
|
137
123
|
|
|
@@ -146,15 +132,9 @@ export function getSheetAxisMoveAffectedRange(
|
|
|
146
132
|
): SheetMergedRangeObj {
|
|
147
133
|
if (axis === 'COLUMN') {
|
|
148
134
|
return {
|
|
149
|
-
endColumnIndex: Math.max(
|
|
150
|
-
sourceRange.endColumnIndex,
|
|
151
|
-
targetRange.endColumnIndex,
|
|
152
|
-
),
|
|
135
|
+
endColumnIndex: Math.max(sourceRange.endColumnIndex, targetRange.endColumnIndex),
|
|
153
136
|
endRowIndex: sourceRange.endRowIndex,
|
|
154
|
-
startColumnIndex: Math.min(
|
|
155
|
-
sourceRange.startColumnIndex,
|
|
156
|
-
targetRange.startColumnIndex,
|
|
157
|
-
),
|
|
137
|
+
startColumnIndex: Math.min(sourceRange.startColumnIndex, targetRange.startColumnIndex),
|
|
158
138
|
startRowIndex: sourceRange.startRowIndex,
|
|
159
139
|
};
|
|
160
140
|
}
|
|
@@ -163,10 +143,7 @@ export function getSheetAxisMoveAffectedRange(
|
|
|
163
143
|
endColumnIndex: sourceRange.endColumnIndex,
|
|
164
144
|
endRowIndex: Math.max(sourceRange.endRowIndex, targetRange.endRowIndex),
|
|
165
145
|
startColumnIndex: sourceRange.startColumnIndex,
|
|
166
|
-
startRowIndex: Math.min(
|
|
167
|
-
sourceRange.startRowIndex,
|
|
168
|
-
targetRange.startRowIndex,
|
|
169
|
-
),
|
|
146
|
+
startRowIndex: Math.min(sourceRange.startRowIndex, targetRange.startRowIndex),
|
|
170
147
|
};
|
|
171
148
|
}
|
|
172
149
|
|
|
@@ -183,73 +160,40 @@ export function getSheetAxisMoveSourceIndex(params: {
|
|
|
183
160
|
}) {
|
|
184
161
|
if (params.targetStartIndex > params.sourceStartIndex) {
|
|
185
162
|
if (params.destinationIndex >= params.targetStartIndex) {
|
|
186
|
-
return
|
|
187
|
-
params.sourceStartIndex +
|
|
188
|
-
params.destinationIndex -
|
|
189
|
-
params.targetStartIndex
|
|
190
|
-
);
|
|
163
|
+
return params.sourceStartIndex + params.destinationIndex - params.targetStartIndex;
|
|
191
164
|
}
|
|
192
165
|
|
|
193
|
-
return
|
|
194
|
-
params.sourceEndIndex +
|
|
195
|
-
1 +
|
|
196
|
-
params.destinationIndex -
|
|
197
|
-
params.sourceStartIndex
|
|
198
|
-
);
|
|
166
|
+
return params.sourceEndIndex + 1 + params.destinationIndex - params.sourceStartIndex;
|
|
199
167
|
}
|
|
200
168
|
|
|
201
169
|
if (params.destinationIndex <= params.targetEndIndex) {
|
|
202
|
-
return
|
|
203
|
-
params.sourceStartIndex +
|
|
204
|
-
params.destinationIndex -
|
|
205
|
-
params.targetStartIndex
|
|
206
|
-
);
|
|
170
|
+
return params.sourceStartIndex + params.destinationIndex - params.targetStartIndex;
|
|
207
171
|
}
|
|
208
172
|
|
|
209
|
-
return
|
|
210
|
-
params.targetStartIndex +
|
|
211
|
-
params.destinationIndex -
|
|
212
|
-
params.targetEndIndex -
|
|
213
|
-
1
|
|
214
|
-
);
|
|
173
|
+
return params.targetStartIndex + params.destinationIndex - params.targetEndIndex - 1;
|
|
215
174
|
}
|
|
216
175
|
|
|
217
176
|
/*
|
|
218
177
|
* Resolve the destination occupied by one original axis index after inserting
|
|
219
178
|
* the selected block at its target.
|
|
220
179
|
*/
|
|
221
|
-
export function getSheetAxisMoveDestinationIndex(
|
|
222
|
-
sourceIndex: number,
|
|
223
|
-
params: SheetAxisMoveIndexes,
|
|
224
|
-
) {
|
|
180
|
+
export function getSheetAxisMoveDestinationIndex(sourceIndex: number, params: SheetAxisMoveIndexes) {
|
|
225
181
|
const width = params.sourceEndIndex - params.sourceStartIndex + 1;
|
|
226
182
|
|
|
227
183
|
if (params.targetStartIndex > params.sourceStartIndex) {
|
|
228
|
-
if (
|
|
229
|
-
sourceIndex >= params.sourceStartIndex &&
|
|
230
|
-
sourceIndex <= params.sourceEndIndex
|
|
231
|
-
) {
|
|
184
|
+
if (sourceIndex >= params.sourceStartIndex && sourceIndex <= params.sourceEndIndex) {
|
|
232
185
|
return sourceIndex + params.targetStartIndex - params.sourceStartIndex;
|
|
233
186
|
}
|
|
234
|
-
if (
|
|
235
|
-
sourceIndex > params.sourceEndIndex &&
|
|
236
|
-
sourceIndex <= params.targetEndIndex
|
|
237
|
-
) {
|
|
187
|
+
if (sourceIndex > params.sourceEndIndex && sourceIndex <= params.targetEndIndex) {
|
|
238
188
|
return sourceIndex - width;
|
|
239
189
|
}
|
|
240
190
|
return sourceIndex;
|
|
241
191
|
}
|
|
242
192
|
|
|
243
|
-
if (
|
|
244
|
-
sourceIndex >= params.sourceStartIndex &&
|
|
245
|
-
sourceIndex <= params.sourceEndIndex
|
|
246
|
-
) {
|
|
193
|
+
if (sourceIndex >= params.sourceStartIndex && sourceIndex <= params.sourceEndIndex) {
|
|
247
194
|
return sourceIndex + params.targetStartIndex - params.sourceStartIndex;
|
|
248
195
|
}
|
|
249
|
-
if (
|
|
250
|
-
sourceIndex >= params.targetStartIndex &&
|
|
251
|
-
sourceIndex < params.sourceStartIndex
|
|
252
|
-
) {
|
|
196
|
+
if (sourceIndex >= params.targetStartIndex && sourceIndex < params.sourceStartIndex) {
|
|
253
197
|
return sourceIndex + width;
|
|
254
198
|
}
|
|
255
199
|
return sourceIndex;
|
|
@@ -265,14 +209,8 @@ export function getSheetCoordinateAfterAxisMove(
|
|
|
265
209
|
indexes: SheetAxisMoveIndexes,
|
|
266
210
|
) {
|
|
267
211
|
return {
|
|
268
|
-
columnIndex:
|
|
269
|
-
|
|
270
|
-
? getSheetAxisMoveDestinationIndex(columnIndex, indexes)
|
|
271
|
-
: columnIndex,
|
|
272
|
-
rowIndex:
|
|
273
|
-
axis === 'ROW'
|
|
274
|
-
? getSheetAxisMoveDestinationIndex(rowIndex, indexes)
|
|
275
|
-
: rowIndex,
|
|
212
|
+
columnIndex: axis === 'COLUMN' ? getSheetAxisMoveDestinationIndex(columnIndex, indexes) : columnIndex,
|
|
213
|
+
rowIndex: axis === 'ROW' ? getSheetAxisMoveDestinationIndex(rowIndex, indexes) : rowIndex,
|
|
276
214
|
};
|
|
277
215
|
}
|
|
278
216
|
|
|
@@ -280,11 +218,7 @@ export function getSheetCoordinateAfterAxisMove(
|
|
|
280
218
|
* Return the bounding axis interval and whether it remains contiguous after
|
|
281
219
|
* every original index follows the same permutation.
|
|
282
220
|
*/
|
|
283
|
-
export function getSheetMovedAxisRange(
|
|
284
|
-
startIndex: number,
|
|
285
|
-
endIndex: number,
|
|
286
|
-
indexes: SheetAxisMoveIndexes,
|
|
287
|
-
) {
|
|
221
|
+
export function getSheetMovedAxisRange(startIndex: number, endIndex: number, indexes: SheetAxisMoveIndexes) {
|
|
288
222
|
const candidates = new Set([startIndex, endIndex]);
|
|
289
223
|
[
|
|
290
224
|
indexes.sourceStartIndex - 1,
|
|
@@ -300,9 +234,7 @@ export function getSheetMovedAxisRange(
|
|
|
300
234
|
candidates.add(index);
|
|
301
235
|
}
|
|
302
236
|
});
|
|
303
|
-
const destinations = [...candidates].map((index) =>
|
|
304
|
-
getSheetAxisMoveDestinationIndex(index, indexes),
|
|
305
|
-
);
|
|
237
|
+
const destinations = [...candidates].map((index) => getSheetAxisMoveDestinationIndex(index, indexes));
|
|
306
238
|
const movedStartIndex = Math.min(...destinations);
|
|
307
239
|
const movedEndIndex = Math.max(...destinations);
|
|
308
240
|
|
|
@@ -318,9 +250,7 @@ export function getSheetMovedAxisRange(
|
|
|
318
250
|
* means the move would split the rectangle into a union that Sheet ranges
|
|
319
251
|
* cannot currently represent.
|
|
320
252
|
*/
|
|
321
|
-
export function getSheetCoordinateRangeAfterAxisMove<
|
|
322
|
-
TRange extends SheetMergedRangeObj,
|
|
323
|
-
>(
|
|
253
|
+
export function getSheetCoordinateRangeAfterAxisMove<TRange extends SheetMergedRangeObj>(
|
|
324
254
|
range: TRange,
|
|
325
255
|
axis: SheetAxisMoveType,
|
|
326
256
|
indexes: SheetAxisMoveIndexes,
|
|
@@ -353,20 +283,14 @@ export function getSheetCoordinateRangeAfterAxisMove<
|
|
|
353
283
|
* Project every coordinate rectangle through an axis permutation, failing
|
|
354
284
|
* closed when any rectangle would become a discontiguous union.
|
|
355
285
|
*/
|
|
356
|
-
export function getSheetCoordinateRangesAfterAxisMove<
|
|
357
|
-
TRange extends SheetMergedRangeObj,
|
|
358
|
-
>(
|
|
286
|
+
export function getSheetCoordinateRangesAfterAxisMove<TRange extends SheetMergedRangeObj>(
|
|
359
287
|
ranges: readonly TRange[],
|
|
360
288
|
axis: SheetAxisMoveType,
|
|
361
289
|
indexes: SheetAxisMoveIndexes,
|
|
362
290
|
): TRange[] | null {
|
|
363
291
|
const movedRanges: TRange[] = [];
|
|
364
292
|
for (const range of ranges) {
|
|
365
|
-
const movedRange = getSheetCoordinateRangeAfterAxisMove(
|
|
366
|
-
range,
|
|
367
|
-
axis,
|
|
368
|
-
indexes,
|
|
369
|
-
);
|
|
293
|
+
const movedRange = getSheetCoordinateRangeAfterAxisMove(range, axis, indexes);
|
|
370
294
|
if (!movedRange) {
|
|
371
295
|
return null;
|
|
372
296
|
}
|
|
@@ -386,23 +310,11 @@ export function sheetCoordinateRangeNeedsAxisMoveRemap(params: {
|
|
|
386
310
|
targetRange: SheetMergedRangeObj;
|
|
387
311
|
}) {
|
|
388
312
|
const movingColumns = params.axis === 'COLUMN';
|
|
389
|
-
const startIndex = movingColumns
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const endIndex = movingColumns
|
|
393
|
-
? params.range.endColumnIndex
|
|
394
|
-
: params.range.endRowIndex;
|
|
395
|
-
const movedRange = getSheetMovedAxisRange(
|
|
396
|
-
startIndex,
|
|
397
|
-
endIndex,
|
|
398
|
-
getSheetAxisMoveIndexes(params),
|
|
399
|
-
);
|
|
313
|
+
const startIndex = movingColumns ? params.range.startColumnIndex : params.range.startRowIndex;
|
|
314
|
+
const endIndex = movingColumns ? params.range.endColumnIndex : params.range.endRowIndex;
|
|
315
|
+
const movedRange = getSheetMovedAxisRange(startIndex, endIndex, getSheetAxisMoveIndexes(params));
|
|
400
316
|
|
|
401
|
-
return
|
|
402
|
-
!movedRange.contiguous ||
|
|
403
|
-
movedRange.startIndex !== startIndex ||
|
|
404
|
-
movedRange.endIndex !== endIndex
|
|
405
|
-
);
|
|
317
|
+
return !movedRange.contiguous || movedRange.startIndex !== startIndex || movedRange.endIndex !== endIndex;
|
|
406
318
|
}
|
|
407
319
|
|
|
408
320
|
/*
|
|
@@ -420,40 +332,29 @@ export function getMovedSheetAxisDesign(params: {
|
|
|
420
332
|
return params.axisDesign || {};
|
|
421
333
|
}
|
|
422
334
|
|
|
423
|
-
const affectedStartIndex = Math.min(
|
|
424
|
-
|
|
425
|
-
params.targetStartIndex,
|
|
426
|
-
);
|
|
427
|
-
const affectedEndIndex = Math.max(
|
|
428
|
-
params.sourceEndIndex,
|
|
429
|
-
params.targetEndIndex,
|
|
430
|
-
);
|
|
335
|
+
const affectedStartIndex = Math.min(params.sourceStartIndex, params.targetStartIndex);
|
|
336
|
+
const affectedEndIndex = Math.max(params.sourceEndIndex, params.targetEndIndex);
|
|
431
337
|
const next = { ...(params.axisDesign || {}) };
|
|
432
|
-
const affectedEntries = Object.entries(params.axisDesign || {}).filter(
|
|
433
|
-
(
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
},
|
|
442
|
-
);
|
|
338
|
+
const affectedEntries = Object.entries(params.axisDesign || {}).filter(([sourceKey]) => {
|
|
339
|
+
const sourceIndex = Number(sourceKey);
|
|
340
|
+
return (
|
|
341
|
+
Number.isSafeInteger(sourceIndex) &&
|
|
342
|
+
sourceIndex >= affectedStartIndex &&
|
|
343
|
+
sourceIndex <= affectedEndIndex &&
|
|
344
|
+
String(sourceIndex) === sourceKey
|
|
345
|
+
);
|
|
346
|
+
});
|
|
443
347
|
|
|
444
348
|
affectedEntries.forEach(([sourceKey]) => {
|
|
445
349
|
delete next[sourceKey];
|
|
446
350
|
});
|
|
447
351
|
affectedEntries.forEach(([sourceKey, sourceDesign]) => {
|
|
448
|
-
const destinationIndex = getSheetAxisMoveDestinationIndex(
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
targetStartIndex: params.targetStartIndex,
|
|
455
|
-
},
|
|
456
|
-
);
|
|
352
|
+
const destinationIndex = getSheetAxisMoveDestinationIndex(Number(sourceKey), {
|
|
353
|
+
sourceEndIndex: params.sourceEndIndex,
|
|
354
|
+
sourceStartIndex: params.sourceStartIndex,
|
|
355
|
+
targetEndIndex: params.targetEndIndex,
|
|
356
|
+
targetStartIndex: params.targetStartIndex,
|
|
357
|
+
});
|
|
457
358
|
if (sourceDesign) {
|
|
458
359
|
next[String(destinationIndex)] = sourceDesign;
|
|
459
360
|
}
|
|
@@ -467,31 +368,15 @@ export function getMovedSheetAxisDesign(params: {
|
|
|
467
368
|
* normalized row or column permutation. A null result fails closed when a
|
|
468
369
|
* stored rectangle cannot remain contiguous.
|
|
469
370
|
*/
|
|
470
|
-
export function getSheetDesignAfterAxisMove(
|
|
471
|
-
design:
|
|
472
|
-
input: SheetAxisMoveInput,
|
|
473
|
-
): SheetDesignObj | null {
|
|
474
|
-
const axisCount =
|
|
475
|
-
input.axis === 'COLUMN'
|
|
476
|
-
? Number(design.grid.columnCount)
|
|
477
|
-
: Number(design.grid.rowCount);
|
|
371
|
+
export function getSheetDesignAfterAxisMove(design: SheetDesignObj, input: SheetAxisMoveInput): SheetDesignObj | null {
|
|
372
|
+
const axisCount = input.axis === 'COLUMN' ? Number(design.grid.columnCount) : Number(design.grid.rowCount);
|
|
478
373
|
const indexes = normalizeSheetAxisMoveInput(input, axisCount);
|
|
479
374
|
const designMergedRanges = design.metadata?.merges;
|
|
480
375
|
const hasMergedRanges = Array.isArray(designMergedRanges);
|
|
481
|
-
const mergedRanges = hasMergedRanges
|
|
482
|
-
? (designMergedRanges as SheetMergedRangeObj[])
|
|
483
|
-
: [];
|
|
376
|
+
const mergedRanges = hasMergedRanges ? (designMergedRanges as SheetMergedRangeObj[]) : [];
|
|
484
377
|
const hasNamedRanges = Array.isArray(design.namedRanges);
|
|
485
|
-
const movedMergedRanges = getSheetCoordinateRangesAfterAxisMove(
|
|
486
|
-
|
|
487
|
-
input.axis,
|
|
488
|
-
indexes,
|
|
489
|
-
);
|
|
490
|
-
const movedNamedRanges = getSheetCoordinateRangesAfterAxisMove(
|
|
491
|
-
design.namedRanges || [],
|
|
492
|
-
input.axis,
|
|
493
|
-
indexes,
|
|
494
|
-
);
|
|
378
|
+
const movedMergedRanges = getSheetCoordinateRangesAfterAxisMove(mergedRanges, input.axis, indexes);
|
|
379
|
+
const movedNamedRanges = getSheetCoordinateRangesAfterAxisMove(design.namedRanges || [], input.axis, indexes);
|
|
495
380
|
if (!movedMergedRanges || !movedNamedRanges) {
|
|
496
381
|
return null;
|
|
497
382
|
}
|
|
@@ -539,11 +424,7 @@ function sheetAxisMoveFormulaReferenceTargetsMovedTab(
|
|
|
539
424
|
return params.formulaSheetTabId === params.movedSheetTabId;
|
|
540
425
|
}
|
|
541
426
|
|
|
542
|
-
return (
|
|
543
|
-
params.sheetTabIdByNameKey.get(
|
|
544
|
-
getSheetFormulaSheetTabNameLookupKey(sheetName),
|
|
545
|
-
) === params.movedSheetTabId
|
|
546
|
-
);
|
|
427
|
+
return params.sheetTabIdByNameKey.get(getSheetFormulaSheetTabNameLookupKey(sheetName)) === params.movedSheetTabId;
|
|
547
428
|
}
|
|
548
429
|
|
|
549
430
|
/*
|
|
@@ -554,14 +435,8 @@ function getSheetAxisMovedFormulaCellText(
|
|
|
554
435
|
axis: SheetAxisMoveType,
|
|
555
436
|
indexes: SheetAxisMoveIndexes,
|
|
556
437
|
) {
|
|
557
|
-
const columnIndex =
|
|
558
|
-
|
|
559
|
-
? getSheetAxisMoveDestinationIndex(reference.columnIndex, indexes)
|
|
560
|
-
: reference.columnIndex;
|
|
561
|
-
const rowIndex =
|
|
562
|
-
axis === 'ROW'
|
|
563
|
-
? getSheetAxisMoveDestinationIndex(reference.rowIndex, indexes)
|
|
564
|
-
: reference.rowIndex;
|
|
438
|
+
const columnIndex = axis === 'COLUMN' ? getSheetAxisMoveDestinationIndex(reference.columnIndex, indexes) : reference.columnIndex;
|
|
439
|
+
const rowIndex = axis === 'ROW' ? getSheetAxisMoveDestinationIndex(reference.rowIndex, indexes) : reference.rowIndex;
|
|
565
440
|
|
|
566
441
|
return getSheetFormulaCellReferenceText({
|
|
567
442
|
...reference,
|
|
@@ -595,19 +470,9 @@ function getSheetAxisMovedFormulaRangeTokenText(
|
|
|
595
470
|
axis: SheetAxisMoveType,
|
|
596
471
|
indexes: SheetAxisMoveIndexes,
|
|
597
472
|
) {
|
|
598
|
-
const startAxisIndex =
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
: token.startReference.rowIndex;
|
|
602
|
-
const endAxisIndex =
|
|
603
|
-
axis === 'COLUMN'
|
|
604
|
-
? token.endReference.columnIndex
|
|
605
|
-
: token.endReference.rowIndex;
|
|
606
|
-
const movedRange = getSheetMovedAxisRange(
|
|
607
|
-
Math.min(startAxisIndex, endAxisIndex),
|
|
608
|
-
Math.max(startAxisIndex, endAxisIndex),
|
|
609
|
-
indexes,
|
|
610
|
-
);
|
|
473
|
+
const startAxisIndex = axis === 'COLUMN' ? token.startReference.columnIndex : token.startReference.rowIndex;
|
|
474
|
+
const endAxisIndex = axis === 'COLUMN' ? token.endReference.columnIndex : token.endReference.rowIndex;
|
|
475
|
+
const movedRange = getSheetMovedAxisRange(Math.min(startAxisIndex, endAxisIndex), Math.max(startAxisIndex, endAxisIndex), indexes);
|
|
611
476
|
if (!movedRange.contiguous) {
|
|
612
477
|
return null;
|
|
613
478
|
}
|
|
@@ -622,54 +487,39 @@ function getSheetAxisMovedFormulaRangeTokenText(
|
|
|
622
487
|
...token.startReference,
|
|
623
488
|
...(axis === 'COLUMN'
|
|
624
489
|
? {
|
|
625
|
-
columnIndex:
|
|
626
|
-
startAxisIndex <= endAxisIndex
|
|
627
|
-
? movedRange.startIndex
|
|
628
|
-
: movedRange.endIndex,
|
|
490
|
+
columnIndex: startAxisIndex <= endAxisIndex ? movedRange.startIndex : movedRange.endIndex,
|
|
629
491
|
}
|
|
630
492
|
: {
|
|
631
|
-
rowIndex:
|
|
632
|
-
startAxisIndex <= endAxisIndex
|
|
633
|
-
? movedRange.startIndex
|
|
634
|
-
: movedRange.endIndex,
|
|
493
|
+
rowIndex: startAxisIndex <= endAxisIndex ? movedRange.startIndex : movedRange.endIndex,
|
|
635
494
|
}),
|
|
636
495
|
};
|
|
637
496
|
const movedEndReference = {
|
|
638
497
|
...token.endReference,
|
|
639
498
|
...(axis === 'COLUMN'
|
|
640
499
|
? {
|
|
641
|
-
columnIndex:
|
|
642
|
-
startAxisIndex <= endAxisIndex
|
|
643
|
-
? movedRange.endIndex
|
|
644
|
-
: movedRange.startIndex,
|
|
500
|
+
columnIndex: startAxisIndex <= endAxisIndex ? movedRange.endIndex : movedRange.startIndex,
|
|
645
501
|
}
|
|
646
502
|
: {
|
|
647
|
-
rowIndex:
|
|
648
|
-
startAxisIndex <= endAxisIndex
|
|
649
|
-
? movedRange.endIndex
|
|
650
|
-
: movedRange.startIndex,
|
|
503
|
+
rowIndex: startAxisIndex <= endAxisIndex ? movedRange.endIndex : movedRange.startIndex,
|
|
651
504
|
}),
|
|
652
505
|
};
|
|
653
506
|
|
|
654
507
|
return (
|
|
655
|
-
token.text.slice(
|
|
656
|
-
0,
|
|
657
|
-
token.startReferenceCoordinateStartIndex - token.startIndex,
|
|
658
|
-
) +
|
|
508
|
+
token.text.slice(0, token.startReferenceCoordinateStartIndex - token.startIndex) +
|
|
659
509
|
getSheetFormulaCellReferenceText(movedStartReference) +
|
|
660
510
|
token.text.slice(
|
|
661
511
|
token.startReferenceCoordinateEndIndex - token.startIndex,
|
|
662
512
|
token.endReferenceCoordinateStartIndex - token.startIndex,
|
|
663
513
|
) +
|
|
664
|
-
|
|
514
|
+
(token.endRowOpen && movedEndReference.rowIndex === SHEET_MAX_ROW_COUNT
|
|
515
|
+
? getSheetFormulaColumnReferenceText(movedEndReference)
|
|
516
|
+
: getSheetFormulaCellReferenceText(movedEndReference)) +
|
|
665
517
|
token.text.slice(token.endReferenceCoordinateEndIndex - token.startIndex)
|
|
666
518
|
);
|
|
667
519
|
}
|
|
668
520
|
|
|
669
521
|
/*
|
|
670
|
-
* Rewrite
|
|
671
|
-
* expressions recurse through the same transformer instead of maintaining a
|
|
672
|
-
* second formula-coordinate implementation.
|
|
522
|
+
* Rewrite references to the moved tab through one row or column permutation.
|
|
673
523
|
*/
|
|
674
524
|
function rewriteSheetAxisMoveFormulaExpression(
|
|
675
525
|
value: string,
|
|
@@ -695,20 +545,9 @@ function rewriteSheetAxisMoveFormulaExpression(
|
|
|
695
545
|
text += value.slice(cursor, token.startIndex);
|
|
696
546
|
let tokenText = token.text;
|
|
697
547
|
|
|
698
|
-
if (
|
|
699
|
-
token.
|
|
700
|
-
|
|
701
|
-
) {
|
|
702
|
-
tokenText = getSheetAxisMovedFormulaCellTokenText(
|
|
703
|
-
token,
|
|
704
|
-
params.axis,
|
|
705
|
-
params.indexes,
|
|
706
|
-
);
|
|
707
|
-
if (
|
|
708
|
-
tokenText !== token.text &&
|
|
709
|
-
token.sheetName &&
|
|
710
|
-
params.allowQualifiedReferences === false
|
|
711
|
-
) {
|
|
548
|
+
if (token.kind === 'SHEET_CELL' && sheetAxisMoveFormulaReferenceTargetsMovedTab(token.sheetName, params)) {
|
|
549
|
+
tokenText = getSheetAxisMovedFormulaCellTokenText(token, params.axis, params.indexes);
|
|
550
|
+
if (tokenText !== token.text && token.sheetName && params.allowQualifiedReferences === false) {
|
|
712
551
|
return {
|
|
713
552
|
changed: false,
|
|
714
553
|
reason: 'QUALIFIED_REFERENCE',
|
|
@@ -716,15 +555,8 @@ function rewriteSheetAxisMoveFormulaExpression(
|
|
|
716
555
|
text: value,
|
|
717
556
|
};
|
|
718
557
|
}
|
|
719
|
-
} else if (
|
|
720
|
-
token.
|
|
721
|
-
sheetAxisMoveFormulaReferenceTargetsMovedTab(token.sheetName, params)
|
|
722
|
-
) {
|
|
723
|
-
const movedText = getSheetAxisMovedFormulaRangeTokenText(
|
|
724
|
-
token,
|
|
725
|
-
params.axis,
|
|
726
|
-
params.indexes,
|
|
727
|
-
);
|
|
558
|
+
} else if (token.kind === 'SHEET_RANGE' && sheetAxisMoveFormulaReferenceTargetsMovedTab(token.sheetName, params)) {
|
|
559
|
+
const movedText = getSheetAxisMovedFormulaRangeTokenText(token, params.axis, params.indexes);
|
|
728
560
|
if (movedText === null) {
|
|
729
561
|
return {
|
|
730
562
|
changed: false,
|
|
@@ -733,11 +565,7 @@ function rewriteSheetAxisMoveFormulaExpression(
|
|
|
733
565
|
text: value,
|
|
734
566
|
};
|
|
735
567
|
}
|
|
736
|
-
if (
|
|
737
|
-
movedText !== token.text &&
|
|
738
|
-
token.sheetName &&
|
|
739
|
-
params.allowQualifiedReferences === false
|
|
740
|
-
) {
|
|
568
|
+
if (movedText !== token.text && token.sheetName && params.allowQualifiedReferences === false) {
|
|
741
569
|
return {
|
|
742
570
|
changed: false,
|
|
743
571
|
reason: 'QUALIFIED_REFERENCE',
|
|
@@ -746,46 +574,6 @@ function rewriteSheetAxisMoveFormulaExpression(
|
|
|
746
574
|
};
|
|
747
575
|
}
|
|
748
576
|
tokenText = movedText;
|
|
749
|
-
} else if (token.kind === 'DATA_TABLE_CELL') {
|
|
750
|
-
const rowIdentifierText = token.rowIdentifierExpression.trim();
|
|
751
|
-
const nested = rewriteSheetAxisMoveFormulaExpression(
|
|
752
|
-
rowIdentifierText,
|
|
753
|
-
params,
|
|
754
|
-
);
|
|
755
|
-
if (nested.status === 'UNSAFE') {
|
|
756
|
-
return nested;
|
|
757
|
-
}
|
|
758
|
-
const call = parseSheetFormulaCall(token.text);
|
|
759
|
-
if (nested.changed && call?.args.length === 2) {
|
|
760
|
-
tokenText = `${call.name}(${nested.text}, ${call.args[1].trim()})`;
|
|
761
|
-
}
|
|
762
|
-
} else if (token.kind === 'DATA_TABLE_QUERY_CELL') {
|
|
763
|
-
let queryChanged = false;
|
|
764
|
-
const conditions: string[] = [];
|
|
765
|
-
for (const condition of token.conditions) {
|
|
766
|
-
if (condition.valueNode.kind !== 'CELL_REFERENCE') {
|
|
767
|
-
conditions.push(condition.text);
|
|
768
|
-
continue;
|
|
769
|
-
}
|
|
770
|
-
const nested = rewriteSheetAxisMoveFormulaExpression(
|
|
771
|
-
condition.valueExpression,
|
|
772
|
-
params,
|
|
773
|
-
);
|
|
774
|
-
if (nested.status === 'UNSAFE') {
|
|
775
|
-
return nested;
|
|
776
|
-
}
|
|
777
|
-
queryChanged = queryChanged || nested.changed;
|
|
778
|
-
conditions.push(
|
|
779
|
-
condition.text.slice(
|
|
780
|
-
0,
|
|
781
|
-
condition.text.length - condition.valueExpression.length,
|
|
782
|
-
) + nested.text,
|
|
783
|
-
);
|
|
784
|
-
}
|
|
785
|
-
const whereIndex = token.text.search(/\bWHERE\b/i);
|
|
786
|
-
if (queryChanged && whereIndex >= 0) {
|
|
787
|
-
tokenText = `${token.text.slice(0, whereIndex).trimEnd()} WHERE ${conditions.join(' AND ')}`;
|
|
788
|
-
}
|
|
789
577
|
}
|
|
790
578
|
|
|
791
579
|
text += tokenText;
|
|
@@ -794,9 +582,7 @@ function rewriteSheetAxisMoveFormulaExpression(
|
|
|
794
582
|
}
|
|
795
583
|
|
|
796
584
|
text += value.slice(cursor);
|
|
797
|
-
return changed
|
|
798
|
-
? { changed: true, status: 'CHANGED', text }
|
|
799
|
-
: { changed: false, status: 'UNCHANGED', text: value };
|
|
585
|
+
return changed ? { changed: true, status: 'CHANGED', text } : { changed: false, status: 'UNCHANGED', text: value };
|
|
800
586
|
}
|
|
801
587
|
|
|
802
588
|
/*
|