@jsb188/mday 1.1.10 → 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 +140 -54
- package/src/constants/agentMemory.ts +123 -0
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +10 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +236 -0
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +21 -21
- package/src/constants/dataTableFieldTypes.generated.ts +59 -0
- package/src/constants/docAccess.ts +33 -0
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +125 -7
- package/src/constants/fieldDoc.ts +104 -0
- package/src/constants/graphqlReactivity.ts +196 -0
- package/src/constants/integration.ts +8 -9
- package/src/constants/log.ts +14 -408
- 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 +2207 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +18 -21
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +126 -14
- package/src/constants/sms.ts +18 -0
- package/src/constants/square.ts +6 -6
- package/src/constants/storage.ts +80 -7
- package/src/constants/usage.ts +82 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +836 -780
- package/src/schemas/inboundContact.ts +60 -55
- package/src/schemas/logsQuery.ts +55 -49
- package/src/types/account.d.ts +4 -1
- package/src/types/agentMemory.d.ts +98 -0
- package/src/types/agentNote.d.ts +443 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1533 -0
- 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 +115 -403
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +184 -24
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +702 -0
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +10 -1
- package/src/types/log.d.ts +254 -295
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +91 -43
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +678 -129
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +449 -129
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +315 -54
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +43 -0
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +1174 -0
- 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 +95 -618
- package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +317 -51
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +157 -0
- 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 +276 -192
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +262 -0
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +395 -0
- package/src/utils/noteDoc.ts +609 -0
- package/src/utils/organization.ts +337 -84
- package/src/utils/pageRoute.ts +71 -0
- 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 +199 -107
- package/src/utils/sheetAxisMove.ts +616 -0
- package/src/utils/sheetBootstrap.ts +1402 -0
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +358 -0
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +186 -0
- 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 +899 -0
- package/src/utils/sheetFormulaEvaluator.ts +997 -0
- 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 +200 -0
- package/src/utils/sheetNumberFormat.ts +1012 -0
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +118 -0
- package/src/utils/sheetSnapshot.ts +739 -0
- package/src/utils/sheetStructureEdit.ts +914 -0
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/square.ts +22 -12
- package/src/utils/storage.ts +198 -0
- package/src/utils/table-route.ts +127 -11
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +334 -40
- 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 +111 -0
- package/tests/dataTableRelativeDate.test.ts +412 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -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 +514 -0
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +352 -0
- 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 +468 -0
- 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 +22 -0
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +537 -0
- 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/tsconfig.json +10 -10
- package/vitest.config.ts +8 -0
- package/src/constants/log-activityTexts.ts +0 -235
- package/src/constants/product.ts +0 -42
- package/src/constants/report.ts +0 -44
- package/src/schemas/organization.ts +0 -65
- package/src/schemas/productsQuery.ts +0 -53
- package/src/schemas/reportsQuery.ts +0 -20
- package/src/types/product.d.ts +0 -84
- package/src/types/report.d.ts +0 -290
- package/src/utils/product-calEvent.ts +0 -455
- package/src/utils/report.ts +0 -158
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { SHEET_MAX_COLUMN_COUNT, SHEET_MAX_ROW_COUNT } from '../src/constants/sheet.ts';
|
|
3
|
+
import type { SheetDesignObj, SheetMergedRangeObj, SheetNamedRangeObj, SheetStructureOperationEnum } from '../src/types/sheet.d.ts';
|
|
4
|
+
import {
|
|
5
|
+
applySheetStructureEditToDesignPatch,
|
|
6
|
+
getSheetNamedRangeAfterStructureEdit,
|
|
7
|
+
getSheetNamedRangesAfterStructureEdit,
|
|
8
|
+
getSheetStructureDesignAfterEdit,
|
|
9
|
+
getSheetStructureEditAxisMax,
|
|
10
|
+
getSheetStructureInverseEditForAxisCount,
|
|
11
|
+
getSheetStructureSpanAfterEdit,
|
|
12
|
+
getSheetStructureInsertAtCapBlocker,
|
|
13
|
+
getSheetStructureInsertDroppedLineIndex,
|
|
14
|
+
getSheetStructureInverseEdit,
|
|
15
|
+
getSheetStructureInverseOperation,
|
|
16
|
+
getSheetStructureRangeAfterEdit,
|
|
17
|
+
sheetStructureCellHasContent,
|
|
18
|
+
sheetStructureMergesReachLine,
|
|
19
|
+
} from '../src/utils/sheetStructureEdit.ts';
|
|
20
|
+
|
|
21
|
+
const BASE_RANGE = {
|
|
22
|
+
id: 'range-1',
|
|
23
|
+
startRowIndex: 2,
|
|
24
|
+
endRowIndex: 4,
|
|
25
|
+
startColumnIndex: 2,
|
|
26
|
+
endColumnIndex: 4,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* Verify range deletions remove the selected axis at every range boundary.
|
|
31
|
+
*/
|
|
32
|
+
describe('sheet structure range deletion', () => {
|
|
33
|
+
it.each([
|
|
34
|
+
[2, 2, 3],
|
|
35
|
+
[3, 2, 3],
|
|
36
|
+
[4, 2, 3],
|
|
37
|
+
])('shrinks row ranges when deleting row %i', (targetIndex, expectedStart, expectedEnd) => {
|
|
38
|
+
const next = getSheetStructureRangeAfterEdit(BASE_RANGE, 'DELETE_ROW', targetIndex);
|
|
39
|
+
|
|
40
|
+
expect(next).toMatchObject({
|
|
41
|
+
startRowIndex: expectedStart,
|
|
42
|
+
endRowIndex: expectedEnd,
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it.each([
|
|
47
|
+
[2, 2, 3],
|
|
48
|
+
[3, 2, 3],
|
|
49
|
+
[4, 2, 3],
|
|
50
|
+
])('shrinks column ranges when deleting column %i', (targetIndex, expectedStart, expectedEnd) => {
|
|
51
|
+
const next = getSheetStructureRangeAfterEdit(BASE_RANGE, 'DELETE_COLUMN', targetIndex);
|
|
52
|
+
|
|
53
|
+
expect(next).toMatchObject({
|
|
54
|
+
startColumnIndex: expectedStart,
|
|
55
|
+
endColumnIndex: expectedEnd,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('deletes a singleton range on the selected row', () => {
|
|
60
|
+
expect(
|
|
61
|
+
getSheetStructureRangeAfterEdit(
|
|
62
|
+
{
|
|
63
|
+
...BASE_RANGE,
|
|
64
|
+
startRowIndex: 4,
|
|
65
|
+
endRowIndex: 4,
|
|
66
|
+
},
|
|
67
|
+
'DELETE_ROW',
|
|
68
|
+
4,
|
|
69
|
+
),
|
|
70
|
+
).toBeNull();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
/*
|
|
75
|
+
* Build one grid design at the given size, optionally with merges.
|
|
76
|
+
*/
|
|
77
|
+
function buildCapDesign(rowCount: number, columnCount = 26, merges?: SheetMergedRangeObj[]): SheetDesignObj {
|
|
78
|
+
return {
|
|
79
|
+
columns: {},
|
|
80
|
+
grid: { columnCount, rowCount },
|
|
81
|
+
rows: {},
|
|
82
|
+
version: 1,
|
|
83
|
+
...(merges ? { metadata: { merges } } : {}),
|
|
84
|
+
} as SheetDesignObj;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/*
|
|
88
|
+
* Verify the insert-at-cap rules shared by the server guard and the client
|
|
89
|
+
* precheck (browser-1c-r1 D5): the default grid is the cap, so an insert there
|
|
90
|
+
* keeps the count and may only drop a free trailing line.
|
|
91
|
+
*/
|
|
92
|
+
describe('sheet structure insert at the grid cap', () => {
|
|
93
|
+
it('names the dropped line only when the axis is at its cap', () => {
|
|
94
|
+
expect(getSheetStructureInsertDroppedLineIndex(buildCapDesign(SHEET_MAX_ROW_COUNT), 'INSERT_ROW_ABOVE')).toBe(SHEET_MAX_ROW_COUNT);
|
|
95
|
+
expect(getSheetStructureInsertDroppedLineIndex(buildCapDesign(SHEET_MAX_ROW_COUNT - 1), 'INSERT_ROW_ABOVE')).toBeNull();
|
|
96
|
+
expect(getSheetStructureInsertDroppedLineIndex(buildCapDesign(10, SHEET_MAX_COLUMN_COUNT), 'INSERT_COLUMN_LEFT')).toBe(
|
|
97
|
+
SHEET_MAX_COLUMN_COUNT,
|
|
98
|
+
);
|
|
99
|
+
expect(
|
|
100
|
+
getSheetStructureInsertDroppedLineIndex(buildCapDesign(SHEET_MAX_ROW_COUNT, SHEET_MAX_COLUMN_COUNT), 'DELETE_ROW'),
|
|
101
|
+
).toBeNull();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('the shared design math already keeps the count at the cap', () => {
|
|
105
|
+
const next = getSheetStructureDesignAfterEdit(buildCapDesign(SHEET_MAX_ROW_COUNT), 'INSERT_ROW_ABOVE', 10);
|
|
106
|
+
expect(next.grid.rowCount).toBe(SHEET_MAX_ROW_COUNT);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('a merge reaching the dropped line blocks the insert', () => {
|
|
110
|
+
const design = buildCapDesign(SHEET_MAX_ROW_COUNT, 26, [
|
|
111
|
+
{
|
|
112
|
+
endColumnIndex: 3,
|
|
113
|
+
endRowIndex: SHEET_MAX_ROW_COUNT,
|
|
114
|
+
startColumnIndex: 2,
|
|
115
|
+
startRowIndex: SHEET_MAX_ROW_COUNT - 1,
|
|
116
|
+
},
|
|
117
|
+
]);
|
|
118
|
+
expect(sheetStructureMergesReachLine(design, 'INSERT_ROW_ABOVE', SHEET_MAX_ROW_COUNT)).toBe(true);
|
|
119
|
+
expect(sheetStructureMergesReachLine(design, 'INSERT_COLUMN_LEFT', 26)).toBe(false);
|
|
120
|
+
expect(
|
|
121
|
+
getSheetStructureInsertAtCapBlocker({
|
|
122
|
+
cellsByCoord: new Map(),
|
|
123
|
+
design,
|
|
124
|
+
index: 10,
|
|
125
|
+
operation: 'INSERT_ROW_ABOVE',
|
|
126
|
+
}),
|
|
127
|
+
).toBe('MERGES');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('only stored content makes a cell non-blank', () => {
|
|
131
|
+
expect(sheetStructureCellHasContent(null)).toBe(false);
|
|
132
|
+
expect(sheetStructureCellHasContent({})).toBe(false);
|
|
133
|
+
expect(sheetStructureCellHasContent({ formulaText: ' ' })).toBe(false);
|
|
134
|
+
expect(sheetStructureCellHasContent({ rawInput: 'x' })).toBe(true);
|
|
135
|
+
expect(sheetStructureCellHasContent({ rawInput: '' })).toBe(true);
|
|
136
|
+
expect(sheetStructureCellHasContent({ numberValue: 0 })).toBe(true);
|
|
137
|
+
expect(sheetStructureCellHasContent({ booleanValue: false })).toBe(true);
|
|
138
|
+
expect(sheetStructureCellHasContent({ formulaText: '=1+2' })).toBe(true);
|
|
139
|
+
expect(sheetStructureCellHasContent({ value: 'v' })).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('blocks on content on the dropped line, ignores format-only cells, and refuses a target beyond the grid', () => {
|
|
143
|
+
const design = buildCapDesign(SHEET_MAX_ROW_COUNT);
|
|
144
|
+
const lastRow = SHEET_MAX_ROW_COUNT;
|
|
145
|
+
const contentCell = { columnIndex: 4, rawInput: 'keep', rowIndex: lastRow };
|
|
146
|
+
const formatCell = { columnIndex: 5, format: '{}', rowIndex: lastRow };
|
|
147
|
+
const aboveCell = { columnIndex: 4, rawInput: 'x', rowIndex: lastRow - 1 };
|
|
148
|
+
|
|
149
|
+
expect(
|
|
150
|
+
getSheetStructureInsertAtCapBlocker({
|
|
151
|
+
cellsByCoord: new Map([['500:4', contentCell]]),
|
|
152
|
+
design,
|
|
153
|
+
index: 10,
|
|
154
|
+
operation: 'INSERT_ROW_ABOVE',
|
|
155
|
+
}),
|
|
156
|
+
).toBe('CELLS');
|
|
157
|
+
expect(
|
|
158
|
+
getSheetStructureInsertAtCapBlocker({
|
|
159
|
+
cellsByCoord: new Map([
|
|
160
|
+
['500:5', formatCell],
|
|
161
|
+
['499:4', aboveCell],
|
|
162
|
+
]),
|
|
163
|
+
design,
|
|
164
|
+
index: 10,
|
|
165
|
+
operation: 'INSERT_ROW_ABOVE',
|
|
166
|
+
}),
|
|
167
|
+
).toBeNull();
|
|
168
|
+
// Nothing can be inserted below the last line of a full grid.
|
|
169
|
+
expect(
|
|
170
|
+
getSheetStructureInsertAtCapBlocker({
|
|
171
|
+
cellsByCoord: new Map(),
|
|
172
|
+
design,
|
|
173
|
+
index: lastRow + 1,
|
|
174
|
+
operation: 'INSERT_ROW_ABOVE',
|
|
175
|
+
}),
|
|
176
|
+
).toBe('BEYOND_GRID');
|
|
177
|
+
// Below the cap the insert grows the grid: never blocked here.
|
|
178
|
+
expect(
|
|
179
|
+
getSheetStructureInsertAtCapBlocker({
|
|
180
|
+
cellsByCoord: new Map([['499:4', { ...contentCell, rowIndex: 499 }]]),
|
|
181
|
+
design: buildCapDesign(499),
|
|
182
|
+
index: 10,
|
|
183
|
+
operation: 'INSERT_ROW_ABOVE',
|
|
184
|
+
}),
|
|
185
|
+
).toBeNull();
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
/*
|
|
190
|
+
* Verify the inverse rule shared by the client paint and the server replay
|
|
191
|
+
* (browser-1c-r2 D6): the inverse of an edit restores the axis count the
|
|
192
|
+
* design held before it. Below the cap the opposite operation's own delta does
|
|
193
|
+
* that; an insert at the cap kept the count and dropped the free trailing
|
|
194
|
+
* line, so its inverse delete names the cap and re-appends that line.
|
|
195
|
+
*/
|
|
196
|
+
describe('sheet structure inverse edit', () => {
|
|
197
|
+
it('the inverse operation table is involutive', () => {
|
|
198
|
+
for (const operation of ['INSERT_ROW_ABOVE', 'DELETE_ROW', 'INSERT_COLUMN_LEFT', 'DELETE_COLUMN'] as const) {
|
|
199
|
+
expect(getSheetStructureInverseOperation(getSheetStructureInverseOperation(operation))).toBe(operation);
|
|
200
|
+
}
|
|
201
|
+
expect(getSheetStructureInverseOperation('INSERT_ROW_ABOVE')).toBe('DELETE_ROW');
|
|
202
|
+
expect(getSheetStructureInverseOperation('DELETE_COLUMN')).toBe('INSERT_COLUMN_LEFT');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('below the cap the inverse is the opposite operation alone, as is the inverse of a genuine delete on a full grid', () => {
|
|
206
|
+
expect(getSheetStructureInverseEdit(buildCapDesign(SHEET_MAX_ROW_COUNT - 1), 'INSERT_ROW_ABOVE', 10)).toEqual({
|
|
207
|
+
index: 10,
|
|
208
|
+
operation: 'DELETE_ROW',
|
|
209
|
+
});
|
|
210
|
+
expect(getSheetStructureInverseEdit(buildCapDesign(SHEET_MAX_ROW_COUNT), 'DELETE_ROW', 10)).toEqual({
|
|
211
|
+
index: 10,
|
|
212
|
+
operation: 'INSERT_ROW_ABOVE',
|
|
213
|
+
});
|
|
214
|
+
expect(getSheetStructureInverseEdit(buildCapDesign(20), 'INSERT_COLUMN_LEFT', 3)).toEqual({
|
|
215
|
+
index: 3,
|
|
216
|
+
operation: 'DELETE_COLUMN',
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('the inverse of an insert at the row cap deletes the inserted row AND re-appends the trailing line: the design round-trips exactly', () => {
|
|
221
|
+
const before = {
|
|
222
|
+
...buildCapDesign(SHEET_MAX_ROW_COUNT),
|
|
223
|
+
rows: { '12': { height: 40 } },
|
|
224
|
+
} as SheetDesignObj;
|
|
225
|
+
const after = getSheetStructureDesignAfterEdit(before, 'INSERT_ROW_ABOVE', 10);
|
|
226
|
+
expect(after.grid.rowCount).toBe(SHEET_MAX_ROW_COUNT);
|
|
227
|
+
expect(after.rows?.['13']?.height).toBe(40);
|
|
228
|
+
|
|
229
|
+
const inverse = getSheetStructureInverseEdit(before, 'INSERT_ROW_ABOVE', 10);
|
|
230
|
+
expect(inverse).toEqual({
|
|
231
|
+
axisCount: SHEET_MAX_ROW_COUNT,
|
|
232
|
+
index: 10,
|
|
233
|
+
operation: 'DELETE_ROW',
|
|
234
|
+
});
|
|
235
|
+
const restored = getSheetStructureDesignAfterEdit(after, inverse.operation, inverse.index, inverse.axisCount);
|
|
236
|
+
expect(restored.grid.rowCount).toBe(SHEET_MAX_ROW_COUNT);
|
|
237
|
+
expect(restored.rows).toEqual({ '12': { height: 40 } });
|
|
238
|
+
expect(restored.grid.columnCount).toBe(before.grid.columnCount);
|
|
239
|
+
// Without the count the delete shrinks the grid: the defect this rule fixes.
|
|
240
|
+
expect(getSheetStructureDesignAfterEdit(after, 'DELETE_ROW', 10).grid.rowCount).toBe(SHEET_MAX_ROW_COUNT - 1);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('the column axis follows the same rule at its cap and leaves the row count alone', () => {
|
|
244
|
+
const before = buildCapDesign(10, SHEET_MAX_COLUMN_COUNT);
|
|
245
|
+
const after = getSheetStructureDesignAfterEdit(before, 'INSERT_COLUMN_LEFT', 3);
|
|
246
|
+
expect(after.grid.columnCount).toBe(SHEET_MAX_COLUMN_COUNT);
|
|
247
|
+
|
|
248
|
+
const inverse = getSheetStructureInverseEdit(before, 'INSERT_COLUMN_LEFT', 3);
|
|
249
|
+
expect(inverse).toEqual({
|
|
250
|
+
axisCount: SHEET_MAX_COLUMN_COUNT,
|
|
251
|
+
index: 3,
|
|
252
|
+
operation: 'DELETE_COLUMN',
|
|
253
|
+
});
|
|
254
|
+
const restored = getSheetStructureDesignAfterEdit(after, inverse.operation, inverse.index, inverse.axisCount);
|
|
255
|
+
expect(restored.grid.columnCount).toBe(SHEET_MAX_COLUMN_COUNT);
|
|
256
|
+
expect(restored.grid.rowCount).toBe(10);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('a named axis count is clamped to [1, cap] and never touches the other axis', () => {
|
|
260
|
+
const design = buildCapDesign(SHEET_MAX_ROW_COUNT);
|
|
261
|
+
expect(getSheetStructureDesignAfterEdit(design, 'DELETE_ROW', 10, 9999).grid.rowCount).toBe(SHEET_MAX_ROW_COUNT);
|
|
262
|
+
expect(getSheetStructureDesignAfterEdit(design, 'DELETE_ROW', 10, 0).grid.rowCount).toBe(1);
|
|
263
|
+
expect(getSheetStructureDesignAfterEdit(design, 'DELETE_ROW', 10, SHEET_MAX_ROW_COUNT).grid.columnCount).toBe(26);
|
|
264
|
+
expect(getSheetStructureDesignAfterEdit(design, 'DELETE_ROW', 10, null).grid.rowCount).toBe(SHEET_MAX_ROW_COUNT - 1);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
/*
|
|
269
|
+
* Return one named range on rows [startRow, endRow] of columns B:C.
|
|
270
|
+
*/
|
|
271
|
+
function namedRows(name: string, startRow: number, endRow: number) {
|
|
272
|
+
return {
|
|
273
|
+
endColumnIndex: 3,
|
|
274
|
+
endRowIndex: endRow,
|
|
275
|
+
name,
|
|
276
|
+
startColumnIndex: 2,
|
|
277
|
+
startRowIndex: startRow,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/*
|
|
282
|
+
* Verify the span math named ranges and formula ranges share, and the named
|
|
283
|
+
* range shift/drop/restore cycle (decision D6: drop, restore on undo).
|
|
284
|
+
*/
|
|
285
|
+
describe('sheet structure named ranges', () => {
|
|
286
|
+
it.each([
|
|
287
|
+
['INSERT_ROW_ABOVE', 5, [3, 8], [3, 9], 'SHIFTED'],
|
|
288
|
+
['INSERT_ROW_ABOVE', 3, [3, 8], [4, 9], 'SHIFTED'],
|
|
289
|
+
['INSERT_ROW_ABOVE', 9, [3, 8], [3, 8], 'UNCHANGED'],
|
|
290
|
+
['INSERT_ROW_ABOVE', 1, [2, SHEET_MAX_ROW_COUNT], [3, SHEET_MAX_ROW_COUNT], 'CLAMPED'],
|
|
291
|
+
['INSERT_ROW_ABOVE', 1, [3, 1000], [4, 1000], 'SHIFTED'],
|
|
292
|
+
['INSERT_ROW_ABOVE', 1, [600, 700], [600, 700], 'UNCHANGED'],
|
|
293
|
+
['DELETE_ROW', 5, [3, 8], [3, 7], 'SHIFTED'],
|
|
294
|
+
['DELETE_ROW', 3, [3, 8], [3, 7], 'EDGE'],
|
|
295
|
+
['DELETE_ROW', 8, [3, 8], [3, 7], 'EDGE'],
|
|
296
|
+
['DELETE_ROW', 2, [3, 8], [2, 7], 'SHIFTED'],
|
|
297
|
+
['DELETE_ROW', 9, [3, 8], [3, 8], 'UNCHANGED'],
|
|
298
|
+
['DELETE_COLUMN', 4, [3, 3], [3, 3], 'UNCHANGED'],
|
|
299
|
+
] as Array<[SheetStructureOperationEnum, number, [number, number], [number, number], string]>)(
|
|
300
|
+
'%s %i maps span %j to %j (%s)',
|
|
301
|
+
(operation, index, span, expected, flag) => {
|
|
302
|
+
expect(getSheetStructureSpanAfterEdit(span[0], span[1], { index, operation })).toEqual({
|
|
303
|
+
end: expected[1],
|
|
304
|
+
flag,
|
|
305
|
+
start: expected[0],
|
|
306
|
+
});
|
|
307
|
+
},
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
it('drops spans whose every line is deleted or pushed past the cap', () => {
|
|
311
|
+
expect(
|
|
312
|
+
getSheetStructureSpanAfterEdit(4, 4, {
|
|
313
|
+
index: 4,
|
|
314
|
+
operation: 'DELETE_ROW',
|
|
315
|
+
}),
|
|
316
|
+
).toBeNull();
|
|
317
|
+
expect(
|
|
318
|
+
getSheetStructureSpanAfterEdit(SHEET_MAX_ROW_COUNT, SHEET_MAX_ROW_COUNT, {
|
|
319
|
+
index: 3,
|
|
320
|
+
operation: 'INSERT_ROW_ABOVE',
|
|
321
|
+
}),
|
|
322
|
+
).toBeNull();
|
|
323
|
+
expect(
|
|
324
|
+
getSheetStructureSpanAfterEdit(SHEET_MAX_ROW_COUNT, null, {
|
|
325
|
+
index: SHEET_MAX_ROW_COUNT,
|
|
326
|
+
operation: 'DELETE_ROW',
|
|
327
|
+
}),
|
|
328
|
+
).toBeNull();
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it('a re-appending delete keeps an end on the last line', () => {
|
|
332
|
+
expect(
|
|
333
|
+
getSheetStructureSpanAfterEdit(3, SHEET_MAX_ROW_COUNT, {
|
|
334
|
+
axisCount: SHEET_MAX_ROW_COUNT,
|
|
335
|
+
index: 1,
|
|
336
|
+
operation: 'DELETE_ROW',
|
|
337
|
+
}),
|
|
338
|
+
).toEqual({ end: SHEET_MAX_ROW_COUNT, flag: 'SHIFTED', start: 2 });
|
|
339
|
+
expect(
|
|
340
|
+
getSheetStructureSpanAfterEdit(3, SHEET_MAX_ROW_COUNT, {
|
|
341
|
+
axisCount: SHEET_MAX_ROW_COUNT - 1,
|
|
342
|
+
index: 1,
|
|
343
|
+
operation: 'DELETE_ROW',
|
|
344
|
+
}),
|
|
345
|
+
).toEqual({ end: SHEET_MAX_ROW_COUNT - 1, flag: 'SHIFTED', start: 2 });
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('keeps a single-cell named range unless its line is deleted', () => {
|
|
349
|
+
const single = { ...namedRows('one', 4, 4), endColumnIndex: 2 };
|
|
350
|
+
|
|
351
|
+
expect(
|
|
352
|
+
getSheetNamedRangeAfterStructureEdit(single, {
|
|
353
|
+
index: 2,
|
|
354
|
+
operation: 'DELETE_ROW',
|
|
355
|
+
}),
|
|
356
|
+
).toEqual({
|
|
357
|
+
...single,
|
|
358
|
+
endRowIndex: 3,
|
|
359
|
+
startRowIndex: 3,
|
|
360
|
+
});
|
|
361
|
+
expect(
|
|
362
|
+
getSheetNamedRangeAfterStructureEdit(single, {
|
|
363
|
+
index: 4,
|
|
364
|
+
operation: 'DELETE_ROW',
|
|
365
|
+
}),
|
|
366
|
+
).toBeNull();
|
|
367
|
+
expect(
|
|
368
|
+
getSheetNamedRangeAfterStructureEdit(single, {
|
|
369
|
+
index: 2,
|
|
370
|
+
operation: 'DELETE_COLUMN',
|
|
371
|
+
}),
|
|
372
|
+
).toBeNull();
|
|
373
|
+
expect(
|
|
374
|
+
getSheetNamedRangeAfterStructureEdit(single, {
|
|
375
|
+
index: 1,
|
|
376
|
+
operation: 'INSERT_COLUMN_LEFT',
|
|
377
|
+
}),
|
|
378
|
+
).toEqual({
|
|
379
|
+
...single,
|
|
380
|
+
endColumnIndex: 3,
|
|
381
|
+
startColumnIndex: 3,
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it('returns the unchanged object and leaves invalid coordinates alone', () => {
|
|
386
|
+
const range = namedRows('keep', 3, 8);
|
|
387
|
+
const invalid = { ...namedRows('bad', 8, 3) };
|
|
388
|
+
|
|
389
|
+
expect(
|
|
390
|
+
getSheetNamedRangeAfterStructureEdit(range, {
|
|
391
|
+
index: 20,
|
|
392
|
+
operation: 'DELETE_ROW',
|
|
393
|
+
}),
|
|
394
|
+
).toBe(range);
|
|
395
|
+
expect(
|
|
396
|
+
getSheetNamedRangeAfterStructureEdit(invalid, {
|
|
397
|
+
index: 1,
|
|
398
|
+
operation: 'DELETE_ROW',
|
|
399
|
+
}),
|
|
400
|
+
).toBe(invalid);
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it('records restores for dropped, edge-shrunk and clamped ranges only', () => {
|
|
404
|
+
const ranges = [
|
|
405
|
+
namedRows('gone', 5, 5),
|
|
406
|
+
namedRows('edge', 5, 9),
|
|
407
|
+
namedRows('inside', 2, 9),
|
|
408
|
+
namedRows('after', 7, 9),
|
|
409
|
+
namedRows('before', 1, 2),
|
|
410
|
+
];
|
|
411
|
+
const edit = { index: 5, operation: 'DELETE_ROW' as const };
|
|
412
|
+
const result = getSheetNamedRangesAfterStructureEdit(ranges, edit, {
|
|
413
|
+
inverseEdit: getSheetStructureInverseEditForAxisCount(edit, 40),
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
expect(result.namedRanges).toEqual([
|
|
417
|
+
namedRows('edge', 5, 8),
|
|
418
|
+
namedRows('inside', 2, 8),
|
|
419
|
+
namedRows('after', 6, 8),
|
|
420
|
+
namedRows('before', 1, 2),
|
|
421
|
+
]);
|
|
422
|
+
expect(result.restores).toEqual([
|
|
423
|
+
{ after: null, before: namedRows('gone', 5, 5), position: 0 },
|
|
424
|
+
{
|
|
425
|
+
after: namedRows('edge', 5, 8),
|
|
426
|
+
before: namedRows('edge', 5, 9),
|
|
427
|
+
position: 1,
|
|
428
|
+
},
|
|
429
|
+
]);
|
|
430
|
+
|
|
431
|
+
const undo = getSheetNamedRangesAfterStructureEdit(result.namedRanges, getSheetStructureInverseEditForAxisCount(edit, 40), {
|
|
432
|
+
inverseEdit: edit,
|
|
433
|
+
restores: result.restores,
|
|
434
|
+
});
|
|
435
|
+
expect(undo.namedRanges).toEqual(ranges);
|
|
436
|
+
// The redo of this undo reproduces the forward result by its own math
|
|
437
|
+
expect(undo.restores).toEqual([]);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it('an insert at the cap restores only the range that grew into the last line', () => {
|
|
441
|
+
const ranges = [namedRows('full', 2, SHEET_MAX_ROW_COUNT), namedRows('grew', 2, SHEET_MAX_ROW_COUNT - 1)];
|
|
442
|
+
const edit = { index: 1, operation: 'INSERT_ROW_ABOVE' as const };
|
|
443
|
+
const inverseEdit = getSheetStructureInverseEditForAxisCount(edit, SHEET_MAX_ROW_COUNT);
|
|
444
|
+
const result = getSheetNamedRangesAfterStructureEdit(ranges, edit, {
|
|
445
|
+
inverseEdit,
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
expect(result.namedRanges).toEqual([namedRows('full', 3, SHEET_MAX_ROW_COUNT), namedRows('grew', 3, SHEET_MAX_ROW_COUNT)]);
|
|
449
|
+
expect(result.restores).toEqual([
|
|
450
|
+
{
|
|
451
|
+
after: namedRows('grew', 3, SHEET_MAX_ROW_COUNT),
|
|
452
|
+
before: namedRows('grew', 2, SHEET_MAX_ROW_COUNT - 1),
|
|
453
|
+
position: 1,
|
|
454
|
+
},
|
|
455
|
+
]);
|
|
456
|
+
expect(
|
|
457
|
+
getSheetNamedRangesAfterStructureEdit(result.namedRanges, inverseEdit, {
|
|
458
|
+
restores: result.restores,
|
|
459
|
+
}).namedRanges,
|
|
460
|
+
).toEqual(ranges);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
it('does not bring back a dropped range whose name was taken since', () => {
|
|
464
|
+
const edit = { index: 5, operation: 'DELETE_ROW' as const };
|
|
465
|
+
const taken = namedRows('gone', 20, 21);
|
|
466
|
+
|
|
467
|
+
expect(
|
|
468
|
+
getSheetNamedRangesAfterStructureEdit([taken], getSheetStructureInverseEditForAxisCount(edit, 40), {
|
|
469
|
+
restores: [{ after: null, before: namedRows('gone', 5, 5), position: 0 }],
|
|
470
|
+
}).namedRanges,
|
|
471
|
+
).toEqual([namedRows('gone', 21, 22)]);
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
it('the design image shifts named ranges and a replay restores them', () => {
|
|
475
|
+
const design = {
|
|
476
|
+
...buildCapDesign(40),
|
|
477
|
+
namedRanges: [namedRows('gone', 5, 5), namedRows('total', 3, 9)],
|
|
478
|
+
} as SheetDesignObj;
|
|
479
|
+
const after = getSheetStructureDesignAfterEdit(design, 'DELETE_ROW', 5);
|
|
480
|
+
|
|
481
|
+
expect(after.namedRanges).toEqual([namedRows('total', 3, 8)]);
|
|
482
|
+
expect(
|
|
483
|
+
getSheetStructureDesignAfterEdit(after, 'INSERT_ROW_ABOVE', 5, 40, {
|
|
484
|
+
namedRangeRestores: [{ after: null, before: namedRows('gone', 5, 5), position: 0 }],
|
|
485
|
+
}).namedRanges,
|
|
486
|
+
).toEqual(design.namedRanges);
|
|
487
|
+
expect(getSheetStructureDesignAfterEdit(buildCapDesign(40), 'DELETE_ROW', 5).namedRanges).toEqual([]);
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
it('projects queued design patches through the edit', () => {
|
|
491
|
+
const patch = { namedRanges: [namedRows('total', 3, 9)] };
|
|
492
|
+
|
|
493
|
+
expect(applySheetStructureEditToDesignPatch(patch, 'INSERT_ROW_ABOVE', 1).namedRanges).toEqual([namedRows('total', 4, 10)]);
|
|
494
|
+
expect(applySheetStructureEditToDesignPatch({ rows: null }, 'INSERT_ROW_ABOVE', 1)).toEqual({ rows: null });
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
it('undo with the recorded restores rebuilds random named range lists exactly', () => {
|
|
498
|
+
let seed = 17;
|
|
499
|
+
const random = () => {
|
|
500
|
+
seed = (seed * 1103515245 + 12345) % 2147483648;
|
|
501
|
+
return seed / 2147483648;
|
|
502
|
+
};
|
|
503
|
+
const operations: SheetStructureOperationEnum[] = ['INSERT_ROW_ABOVE', 'INSERT_COLUMN_LEFT', 'DELETE_ROW', 'DELETE_COLUMN'];
|
|
504
|
+
|
|
505
|
+
for (let run = 0; run < 2000; run += 1) {
|
|
506
|
+
const operation = operations[Math.floor(random() * 4)];
|
|
507
|
+
const max = getSheetStructureEditAxisMax(operation);
|
|
508
|
+
const line = () => (random() < 0.3 ? [1, 2, max - 1, max][Math.floor(random() * 4)] : 1 + Math.floor(random() * max));
|
|
509
|
+
const ranges: SheetNamedRangeObj[] = Array.from({ length: 1 + Math.floor(random() * 5) }, (_item, index) => {
|
|
510
|
+
const startRowIndex = line();
|
|
511
|
+
const startColumnIndex = Math.min(line(), SHEET_MAX_COLUMN_COUNT);
|
|
512
|
+
return {
|
|
513
|
+
endColumnIndex: Math.min(startColumnIndex + Math.floor(random() * 3), SHEET_MAX_COLUMN_COUNT),
|
|
514
|
+
endRowIndex: Math.min(startRowIndex + Math.floor(random() * 3), SHEET_MAX_ROW_COUNT),
|
|
515
|
+
name: `r${index}`,
|
|
516
|
+
startColumnIndex,
|
|
517
|
+
startRowIndex,
|
|
518
|
+
};
|
|
519
|
+
});
|
|
520
|
+
const edit = { index: line(), operation };
|
|
521
|
+
const inverseEdit = getSheetStructureInverseEditForAxisCount(edit, random() < 0.5 ? max : line());
|
|
522
|
+
const forward = getSheetNamedRangesAfterStructureEdit(ranges, edit, {
|
|
523
|
+
inverseEdit,
|
|
524
|
+
});
|
|
525
|
+
const undone = getSheetNamedRangesAfterStructureEdit(forward.namedRanges, inverseEdit, {
|
|
526
|
+
inverseEdit: edit,
|
|
527
|
+
restores: forward.restores,
|
|
528
|
+
});
|
|
529
|
+
const redone = getSheetNamedRangesAfterStructureEdit(undone.namedRanges, edit, {
|
|
530
|
+
restores: undone.restores,
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
expect(undone.namedRanges, JSON.stringify({ edit, ranges })).toEqual(ranges);
|
|
534
|
+
expect(redone.namedRanges, JSON.stringify({ edit, ranges })).toEqual(forward.namedRanges);
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
});
|