@bilig/headless 0.8.0 → 0.8.2

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.
Files changed (164) hide show
  1. package/README.md +15 -0
  2. package/dist/persistence.d.ts +1 -1
  3. package/dist/persistence.js +13 -11
  4. package/dist/persistence.js.map +1 -1
  5. package/dist/tracked-cell-index-changes.d.ts +1 -7
  6. package/dist/tracked-cell-index-changes.js +20 -434
  7. package/dist/tracked-cell-index-changes.js.map +1 -1
  8. package/dist/tracked-cell-lazy-physical-changes.d.ts +21 -0
  9. package/dist/tracked-cell-lazy-physical-changes.js +333 -0
  10. package/dist/tracked-cell-lazy-physical-changes.js.map +1 -0
  11. package/dist/tracked-cell-value-read.d.ts +18 -0
  12. package/dist/tracked-cell-value-read.js +46 -0
  13. package/dist/tracked-cell-value-read.js.map +1 -0
  14. package/dist/tracked-engine-event-refs.d.ts +1 -1
  15. package/dist/tracked-engine-event-refs.js +14 -4
  16. package/dist/tracked-engine-event-refs.js.map +1 -1
  17. package/dist/tracked-index-source-order.d.ts +5 -0
  18. package/dist/tracked-index-source-order.js +15 -0
  19. package/dist/tracked-index-source-order.js.map +1 -0
  20. package/dist/work-paper-address-format.d.ts +33 -0
  21. package/dist/work-paper-address-format.js +116 -0
  22. package/dist/work-paper-address-format.js.map +1 -0
  23. package/dist/work-paper-axis-helpers.d.ts +26 -0
  24. package/dist/work-paper-axis-helpers.js +104 -0
  25. package/dist/work-paper-axis-helpers.js.map +1 -0
  26. package/dist/work-paper-capability-checks.d.ts +17 -0
  27. package/dist/work-paper-capability-checks.js +101 -0
  28. package/dist/work-paper-capability-checks.js.map +1 -0
  29. package/dist/work-paper-capability-operations.d.ts +34 -0
  30. package/dist/work-paper-capability-operations.js +70 -0
  31. package/dist/work-paper-capability-operations.js.map +1 -0
  32. package/dist/work-paper-capability-surface.d.ts +97 -0
  33. package/dist/work-paper-capability-surface.js +236 -0
  34. package/dist/work-paper-capability-surface.js.map +1 -0
  35. package/dist/work-paper-cell-content-setter.d.ts +37 -0
  36. package/dist/work-paper-cell-content-setter.js +87 -0
  37. package/dist/work-paper-cell-content-setter.js.map +1 -0
  38. package/dist/work-paper-cell-mutation-refs.d.ts +23 -0
  39. package/dist/work-paper-cell-mutation-refs.js +50 -0
  40. package/dist/work-paper-cell-mutation-refs.js.map +1 -0
  41. package/dist/work-paper-cell-read.d.ts +41 -0
  42. package/dist/work-paper-cell-read.js +54 -0
  43. package/dist/work-paper-cell-read.js.map +1 -0
  44. package/dist/work-paper-clipboard-operations.d.ts +24 -0
  45. package/dist/work-paper-clipboard-operations.js +56 -0
  46. package/dist/work-paper-clipboard-operations.js.map +1 -0
  47. package/dist/work-paper-clipboard.d.ts +13 -0
  48. package/dist/work-paper-clipboard.js +19 -0
  49. package/dist/work-paper-clipboard.js.map +1 -0
  50. package/dist/work-paper-config.d.ts +11 -0
  51. package/dist/work-paper-config.js +247 -0
  52. package/dist/work-paper-config.js.map +1 -0
  53. package/dist/work-paper-date-time.d.ts +4 -0
  54. package/dist/work-paper-date-time.js +38 -0
  55. package/dist/work-paper-date-time.js.map +1 -0
  56. package/dist/work-paper-dependency-refs.d.ts +11 -0
  57. package/dist/work-paper-dependency-refs.js +74 -0
  58. package/dist/work-paper-dependency-refs.js.map +1 -0
  59. package/dist/work-paper-emitter.d.ts +22 -0
  60. package/dist/work-paper-emitter.js +130 -0
  61. package/dist/work-paper-emitter.js.map +1 -0
  62. package/dist/work-paper-engine-event-tracker.d.ts +24 -0
  63. package/dist/work-paper-engine-event-tracker.js +92 -0
  64. package/dist/work-paper-engine-event-tracker.js.map +1 -0
  65. package/dist/work-paper-errors.d.ts +4 -0
  66. package/dist/work-paper-errors.js +7 -0
  67. package/dist/work-paper-errors.js.map +1 -1
  68. package/dist/work-paper-existing-numeric-fast-path.d.ts +31 -0
  69. package/dist/work-paper-existing-numeric-fast-path.js +120 -0
  70. package/dist/work-paper-existing-numeric-fast-path.js.map +1 -0
  71. package/dist/work-paper-fill-helpers.d.ts +8 -0
  72. package/dist/work-paper-fill-helpers.js +34 -0
  73. package/dist/work-paper-fill-helpers.js.map +1 -0
  74. package/dist/work-paper-formula-analysis.d.ts +18 -0
  75. package/dist/work-paper-formula-analysis.js +54 -0
  76. package/dist/work-paper-formula-analysis.js.map +1 -0
  77. package/dist/work-paper-formula-rewrite.d.ts +22 -0
  78. package/dist/work-paper-formula-rewrite.js +71 -0
  79. package/dist/work-paper-formula-rewrite.js.map +1 -0
  80. package/dist/work-paper-function-registry.d.ts +39 -0
  81. package/dist/work-paper-function-registry.js +66 -0
  82. package/dist/work-paper-function-registry.js.map +1 -0
  83. package/dist/work-paper-history-operations.d.ts +15 -0
  84. package/dist/work-paper-history-operations.js +14 -0
  85. package/dist/work-paper-history-operations.js.map +1 -0
  86. package/dist/work-paper-history.d.ts +50 -0
  87. package/dist/work-paper-history.js +136 -0
  88. package/dist/work-paper-history.js.map +1 -0
  89. package/dist/work-paper-internals.d.ts +24 -0
  90. package/dist/work-paper-internals.js +59 -0
  91. package/dist/work-paper-internals.js.map +1 -0
  92. package/dist/work-paper-literal-mutation-queue.d.ts +18 -0
  93. package/dist/work-paper-literal-mutation-queue.js +40 -0
  94. package/dist/work-paper-literal-mutation-queue.js.map +1 -0
  95. package/dist/work-paper-matrix-application.d.ts +31 -0
  96. package/dist/work-paper-matrix-application.js +85 -0
  97. package/dist/work-paper-matrix-application.js.map +1 -0
  98. package/dist/work-paper-mutation-queues.d.ts +29 -0
  99. package/dist/work-paper-mutation-queues.js +72 -0
  100. package/dist/work-paper-mutation-queues.js.map +1 -0
  101. package/dist/work-paper-named-expression-fast-path.d.ts +37 -0
  102. package/dist/work-paper-named-expression-fast-path.js +100 -0
  103. package/dist/work-paper-named-expression-fast-path.js.map +1 -0
  104. package/dist/work-paper-named-expression-helpers.d.ts +54 -0
  105. package/dist/work-paper-named-expression-helpers.js +179 -0
  106. package/dist/work-paper-named-expression-helpers.js.map +1 -0
  107. package/dist/work-paper-named-expression-operations.d.ts +39 -0
  108. package/dist/work-paper-named-expression-operations.js +82 -0
  109. package/dist/work-paper-named-expression-operations.js.map +1 -0
  110. package/dist/work-paper-public-surface.d.ts +73 -0
  111. package/dist/work-paper-public-surface.js +165 -0
  112. package/dist/work-paper-public-surface.js.map +1 -0
  113. package/dist/work-paper-read-operations.d.ts +52 -0
  114. package/dist/work-paper-read-operations.js +185 -0
  115. package/dist/work-paper-read-operations.js.map +1 -0
  116. package/dist/work-paper-runtime-adapters.d.ts +144 -0
  117. package/dist/work-paper-runtime-adapters.js +256 -0
  118. package/dist/work-paper-runtime-adapters.js.map +1 -0
  119. package/dist/work-paper-runtime-helpers.d.ts +27 -0
  120. package/dist/work-paper-runtime-helpers.js +305 -0
  121. package/dist/work-paper-runtime-helpers.js.map +1 -0
  122. package/dist/work-paper-runtime-surface.d.ts +137 -0
  123. package/dist/work-paper-runtime-surface.js +702 -0
  124. package/dist/work-paper-runtime-surface.js.map +1 -0
  125. package/dist/work-paper-runtime.d.ts +56 -285
  126. package/dist/work-paper-runtime.js +403 -4809
  127. package/dist/work-paper-runtime.js.map +1 -1
  128. package/dist/work-paper-scratch-evaluator.js +29 -26
  129. package/dist/work-paper-scratch-evaluator.js.map +1 -1
  130. package/dist/work-paper-sheet-dimension-cache.d.ts +36 -0
  131. package/dist/work-paper-sheet-dimension-cache.js +158 -0
  132. package/dist/work-paper-sheet-dimension-cache.js.map +1 -0
  133. package/dist/work-paper-sheet-initialization.d.ts +19 -0
  134. package/dist/work-paper-sheet-initialization.js +93 -0
  135. package/dist/work-paper-sheet-initialization.js.map +1 -0
  136. package/dist/work-paper-sheet-inspection.d.ts +66 -0
  137. package/dist/work-paper-sheet-inspection.js +204 -0
  138. package/dist/work-paper-sheet-inspection.js.map +1 -0
  139. package/dist/work-paper-sheet-operations.d.ts +59 -0
  140. package/dist/work-paper-sheet-operations.js +104 -0
  141. package/dist/work-paper-sheet-operations.js.map +1 -0
  142. package/dist/work-paper-sheet-read.d.ts +21 -0
  143. package/dist/work-paper-sheet-read.js +32 -0
  144. package/dist/work-paper-sheet-read.js.map +1 -0
  145. package/dist/work-paper-sheet-rename-fast-path.d.ts +18 -0
  146. package/dist/work-paper-sheet-rename-fast-path.js +43 -0
  147. package/dist/work-paper-sheet-rename-fast-path.js.map +1 -0
  148. package/dist/work-paper-static-api.d.ts +18 -0
  149. package/dist/work-paper-static-api.js +44 -0
  150. package/dist/work-paper-static-api.js.map +1 -0
  151. package/dist/work-paper-static-registry.d.ts +21 -0
  152. package/dist/work-paper-static-registry.js +150 -0
  153. package/dist/work-paper-static-registry.js.map +1 -0
  154. package/dist/work-paper-tracked-change-reducer.d.ts +41 -0
  155. package/dist/work-paper-tracked-change-reducer.js +281 -0
  156. package/dist/work-paper-tracked-change-reducer.js.map +1 -0
  157. package/dist/work-paper-tracked-event-helpers.d.ts +89 -0
  158. package/dist/work-paper-tracked-event-helpers.js +366 -0
  159. package/dist/work-paper-tracked-event-helpers.js.map +1 -0
  160. package/dist/work-paper-types.d.ts +6 -5
  161. package/dist/work-paper-visibility-snapshot.d.ts +36 -0
  162. package/dist/work-paper-visibility-snapshot.js +62 -0
  163. package/dist/work-paper-visibility-snapshot.js.map +1 -0
  164. package/package.json +13 -5
@@ -0,0 +1,85 @@
1
+ import { translateFormulaReferences } from '@bilig/formula';
2
+ import { buildMatrixMutationPlan } from './matrix-mutation-plan.js';
3
+ import { matrixContainsFormulaContent, stripLeadingEquals } from './work-paper-runtime-helpers.js';
4
+ export function applyWorkPaperSerializedMatrix(input) {
5
+ const { serialized, sourceAnchor, targetLeftCorner } = input;
6
+ input.flushPendingBatchOps();
7
+ if (matrixContainsFormulaContent(serialized)) {
8
+ serialized.forEach((row, rowOffset) => {
9
+ row.forEach((raw, columnOffset) => {
10
+ const destination = {
11
+ sheet: targetLeftCorner.sheet,
12
+ row: targetLeftCorner.row + rowOffset,
13
+ col: targetLeftCorner.col + columnOffset,
14
+ };
15
+ let nextValue = raw;
16
+ if (typeof raw === 'string' && raw.startsWith('=')) {
17
+ nextValue = `=${translateFormulaReferences(raw.slice(1), destination.row - (sourceAnchor.row + rowOffset), destination.col - (sourceAnchor.col + columnOffset))}`;
18
+ }
19
+ input.applyRawContent(destination, nextValue);
20
+ });
21
+ });
22
+ return;
23
+ }
24
+ const { refs, potentialNewCells } = buildMatrixMutationPlan({
25
+ target: targetLeftCorner,
26
+ content: serialized,
27
+ rewriteFormula: (formula, destination, rowOffset, columnOffset) => input.rewriteFormulaForStorage(translateFormulaReferences(stripLeadingEquals(formula), destination.row - (sourceAnchor.row + rowOffset), destination.col - (sourceAnchor.col + columnOffset)), destination.sheet),
28
+ });
29
+ if (refs.length === 0) {
30
+ return;
31
+ }
32
+ input.applyCellMutationRefs(refs, {
33
+ captureUndo: true,
34
+ potentialNewCells,
35
+ source: 'local',
36
+ returnUndoOps: false,
37
+ reuseRefs: true,
38
+ });
39
+ }
40
+ export function applyWorkPaperMatrixContents(input) {
41
+ const options = input.options ?? {};
42
+ input.flushPendingBatchOps();
43
+ const planInput = {
44
+ target: input.address,
45
+ content: input.content,
46
+ rewriteFormula: (formula, destination) => input.rewriteFormulaForStorage(stripLeadingEquals(formula), destination.sheet),
47
+ };
48
+ if (options.deferLiteralAddresses !== undefined) {
49
+ planInput.deferLiteralAddresses = options.deferLiteralAddresses;
50
+ }
51
+ if (options.skipNulls !== undefined) {
52
+ planInput.skipNulls = options.skipNulls;
53
+ }
54
+ const { leadingRefs, formulaRefs, refs, potentialNewCells, trailingLiteralRefs } = buildMatrixMutationPlan(planInput);
55
+ if (refs.length === 0) {
56
+ return;
57
+ }
58
+ const applyPlannedRefs = (phaseRefs, applyOptions) => {
59
+ if (phaseRefs.length === 0) {
60
+ return;
61
+ }
62
+ input.applyCellMutationRefs(phaseRefs, applyOptions);
63
+ };
64
+ const phaseSource = options.captureUndo === false ? 'restore' : 'local';
65
+ const createApplyOptions = () => {
66
+ const applyOptions = {
67
+ potentialNewCells,
68
+ source: phaseSource,
69
+ returnUndoOps: false,
70
+ reuseRefs: true,
71
+ };
72
+ if (options.captureUndo !== undefined) {
73
+ applyOptions.captureUndo = options.captureUndo;
74
+ }
75
+ return applyOptions;
76
+ };
77
+ if (formulaRefs.length === 0) {
78
+ applyPlannedRefs(refs, createApplyOptions());
79
+ return;
80
+ }
81
+ applyPlannedRefs(leadingRefs, createApplyOptions());
82
+ applyPlannedRefs(formulaRefs, createApplyOptions());
83
+ applyPlannedRefs(trailingLiteralRefs, createApplyOptions());
84
+ }
85
+ //# sourceMappingURL=work-paper-matrix-application.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"work-paper-matrix-application.js","sourceRoot":"","sources":["../src/work-paper-matrix-application.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAE,4BAA4B,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAA;AAmBlG,MAAM,UAAU,8BAA8B,CAAC,KAQ9C;IACC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAA;IAC5D,KAAK,CAAC,oBAAoB,EAAE,CAAA;IAC5B,IAAI,4BAA4B,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7C,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE;YACpC,GAAG,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE;gBAChC,MAAM,WAAW,GAAG;oBAClB,KAAK,EAAE,gBAAgB,CAAC,KAAK;oBAC7B,GAAG,EAAE,gBAAgB,CAAC,GAAG,GAAG,SAAS;oBACrC,GAAG,EAAE,gBAAgB,CAAC,GAAG,GAAG,YAAY;iBACzC,CAAA;gBACD,IAAI,SAAS,GAAG,GAAG,CAAA;gBACnB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,UAAU,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QACD,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YACtC,YAAY,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAA;QAChD,CAAC;QACD,OAAO,YAAY,CAAA;IACrB,CAAC,CAAA;IAED,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC7B,gBAAgB,CAAC,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAA;QAC5C,OAAM;IACR,CAAC;IAED,gBAAgB,CAAC,WAAW,EAAE,kBAAkB,EAAE,CAAC,CAAA;IACnD,gBAAgB,CAAC,WAAW,EAAE,kBAAkB,EAAE,CAAC,CAAA;IACnD,gBAAgB,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC,CAAA;AAC7D,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type { EngineCellMutationRef } from '@bilig/core';
2
+ import { type WorkPaperCellMutationApplyOptions } from './work-paper-cell-mutation-refs.js';
3
+ import type { RawCellContent } from './work-paper-types.js';
4
+ export interface WorkPaperMutationQueuesRuntime {
5
+ readonly applyCellMutationsAtWithOptions: (refs: readonly EngineCellMutationRef[], options: WorkPaperCellMutationApplyOptions) => void;
6
+ readonly updateSheetDimensionsAfterCellMutationRefs: (refs: readonly EngineCellMutationRef[]) => void;
7
+ }
8
+ export interface WorkPaperLiteralMutationQueueInput {
9
+ readonly sheetId: number;
10
+ readonly row: number;
11
+ readonly col: number;
12
+ readonly content: RawCellContent;
13
+ readonly cellIndex: number | undefined;
14
+ }
15
+ export declare class WorkPaperMutationQueues {
16
+ private readonly runtime;
17
+ private pendingBatchOps;
18
+ private pendingBatchPotentialNewCells;
19
+ private suspendedCellMutationRefs;
20
+ private suspendedCellMutationPotentialNewCells;
21
+ constructor(runtime: WorkPaperMutationQueuesRuntime);
22
+ hasPendingBatchOps(): boolean;
23
+ appendSuspendedCellMutationRefs(refs: readonly EngineCellMutationRef[]): void;
24
+ addSuspendedCellMutationPotentialNewCells(amount: number): void;
25
+ flushPendingBatchOps(): void;
26
+ flushSuspendedCellMutations(): void;
27
+ enqueueSuspendedLiteralMutation(input: WorkPaperLiteralMutationQueueInput): boolean;
28
+ enqueueDeferredBatchLiteral(input: WorkPaperLiteralMutationQueueInput): boolean;
29
+ }
@@ -0,0 +1,72 @@
1
+ import { applyQueuedWorkPaperCellMutationRefs } from './work-paper-cell-mutation-refs.js';
2
+ import { tryEnqueueWorkPaperLiteralMutation } from './work-paper-literal-mutation-queue.js';
3
+ export class WorkPaperMutationQueues {
4
+ runtime;
5
+ pendingBatchOps = [];
6
+ pendingBatchPotentialNewCells = 0;
7
+ suspendedCellMutationRefs = [];
8
+ suspendedCellMutationPotentialNewCells = 0;
9
+ constructor(runtime) {
10
+ this.runtime = runtime;
11
+ }
12
+ hasPendingBatchOps() {
13
+ return this.pendingBatchOps.length > 0;
14
+ }
15
+ appendSuspendedCellMutationRefs(refs) {
16
+ this.suspendedCellMutationRefs.push(...refs);
17
+ }
18
+ addSuspendedCellMutationPotentialNewCells(amount) {
19
+ this.suspendedCellMutationPotentialNewCells += amount;
20
+ }
21
+ flushPendingBatchOps() {
22
+ if (this.pendingBatchOps.length === 0) {
23
+ return;
24
+ }
25
+ const refs = this.pendingBatchOps;
26
+ const potentialNewCells = this.pendingBatchPotentialNewCells;
27
+ this.pendingBatchOps = [];
28
+ this.pendingBatchPotentialNewCells = 0;
29
+ applyQueuedWorkPaperCellMutationRefs({
30
+ refs,
31
+ potentialNewCells,
32
+ applyCellMutationsAtWithOptions: this.runtime.applyCellMutationsAtWithOptions,
33
+ updateSheetDimensionsAfterCellMutationRefs: this.runtime.updateSheetDimensionsAfterCellMutationRefs,
34
+ });
35
+ }
36
+ flushSuspendedCellMutations() {
37
+ if (this.suspendedCellMutationRefs.length === 0) {
38
+ return;
39
+ }
40
+ const refs = this.suspendedCellMutationRefs;
41
+ const potentialNewCells = this.suspendedCellMutationPotentialNewCells;
42
+ this.suspendedCellMutationRefs = [];
43
+ this.suspendedCellMutationPotentialNewCells = 0;
44
+ applyQueuedWorkPaperCellMutationRefs({
45
+ refs,
46
+ potentialNewCells,
47
+ applyCellMutationsAtWithOptions: this.runtime.applyCellMutationsAtWithOptions,
48
+ updateSheetDimensionsAfterCellMutationRefs: this.runtime.updateSheetDimensionsAfterCellMutationRefs,
49
+ });
50
+ }
51
+ enqueueSuspendedLiteralMutation(input) {
52
+ return tryEnqueueWorkPaperLiteralMutation({
53
+ enabled: true,
54
+ queue: this.suspendedCellMutationRefs,
55
+ ...input,
56
+ addPotentialNewCell: () => {
57
+ this.suspendedCellMutationPotentialNewCells += 1;
58
+ },
59
+ });
60
+ }
61
+ enqueueDeferredBatchLiteral(input) {
62
+ return tryEnqueueWorkPaperLiteralMutation({
63
+ enabled: true,
64
+ queue: this.pendingBatchOps,
65
+ ...input,
66
+ addPotentialNewCell: () => {
67
+ this.pendingBatchPotentialNewCells += 1;
68
+ },
69
+ });
70
+ }
71
+ }
72
+ //# sourceMappingURL=work-paper-mutation-queues.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"work-paper-mutation-queues.js","sourceRoot":"","sources":["../src/work-paper-mutation-queues.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oCAAoC,EAA0C,MAAM,oCAAoC,CAAA;AACjI,OAAO,EAAE,kCAAkC,EAAE,MAAM,wCAAwC,CAAA;AAgB3F,MAAM,OAAO,uBAAuB;IAML;IALrB,eAAe,GAA4B,EAAE,CAAA;IAC7C,6BAA6B,GAAG,CAAC,CAAA;IACjC,yBAAyB,GAA4B,EAAE,CAAA;IACvD,sCAAsC,GAAG,CAAC,CAAA;IAElD,YAA6B,OAAuC;QAAvC,YAAO,GAAP,OAAO,CAAgC;IAAG,CAAC;IAExE,kBAAkB;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,CAAA;IACxC,CAAC;IAED,+BAA+B,CAAC,IAAsC;QACpE,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC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AI,CAAC,sCAAsC,IAAI,CAAC,CAAA;YAClD,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;IAED,2BAA2B,CAAC,KAAyC;QACnE,OAAO,kCAAkC,CAAC;YACxC,OAAO,EAAE,IAAI;YACb,KAAK,EAAE,IAAI,CAAC,eAAe;YAC3B,GAAG,KAAK;YACR,mBAAmB,EAAE,GAAG,EAAE;gBACxB,IAAI,CAAC,6BAA6B,IAAI,CAAC,CAAA;YACzC,CAAC;SACF,CAAC,CAAA;IACJ,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ import { type CellValue, type WorkbookDefinedNameValueSnapshot } from '@bilig/protocol';
2
+ import { type InternalNamedExpression } from './work-paper-named-expression-helpers.js';
3
+ import type { TrackedEngineEvent } from './tracked-engine-event-refs.js';
4
+ import type { RawCellContent, SerializedWorkPaperNamedExpression, WorkPaperCellChange, WorkPaperChange } from './work-paper-types.js';
5
+ type NamedExpressionValue = CellValue | CellValue[][];
6
+ export interface WorkPaperNamedExpressionFastPathRuntime {
7
+ readonly canUseNamedExpressionChangeFastPath: () => boolean;
8
+ readonly assertNotDisposed: () => void;
9
+ readonly materializePendingLazyTrackedChanges: () => void;
10
+ readonly downgradeTrackedBatchFastPath: () => void;
11
+ readonly getCachedNamedExpressionValue: (key: string) => NamedExpressionValue | undefined;
12
+ readonly setCachedNamedExpressionValue: (key: string, value: NamedExpressionValue) => void;
13
+ readonly evaluateNamedExpression: (expression: InternalNamedExpression) => NamedExpressionValue;
14
+ readonly hasAnyListeners: () => boolean;
15
+ readonly toDefinedNameSnapshot: (expression: RawCellContent, scope: number | undefined) => WorkbookDefinedNameValueSnapshot;
16
+ readonly upsertNumericDefinedNameFast: (name: string, value: WorkbookDefinedNameValueSnapshot, numericValue: number) => readonly number[] | null;
17
+ readonly setNamedExpressionRecord: (key: string, record: InternalNamedExpression) => void;
18
+ readonly readSingleTrackedCellChange: (cellIndex: number) => WorkPaperCellChange | undefined;
19
+ readonly orderCellChanges: (changes: WorkPaperCellChange[], explicitChangedCount: number | undefined) => WorkPaperChange[];
20
+ readonly drainTrackedEngineEvents: () => readonly TrackedEngineEvent[];
21
+ readonly withRetainedTrackedEngineEventIndices: (callback: () => void) => void;
22
+ readonly upsertNamedExpressionInternal: (expression: SerializedWorkPaperNamedExpression) => void;
23
+ readonly namedExpressionRecord: (name: string, scope: number | undefined) => InternalNamedExpression;
24
+ readonly computeTrackedChangesWithoutVisibilityCache: (events: readonly TrackedEngineEvent[], options: {
25
+ readonly preferLazyPublicChanges?: boolean;
26
+ }) => WorkPaperChange[];
27
+ readonly messageOf: (error: unknown, fallback: string) => string;
28
+ }
29
+ export interface WorkPaperNamedExpressionFastPathRequest {
30
+ readonly existing: InternalNamedExpression;
31
+ readonly expressionName: string;
32
+ readonly expression: RawCellContent;
33
+ readonly scope?: number;
34
+ readonly options?: Record<string, string | number | boolean>;
35
+ }
36
+ export declare function tryCaptureWorkPaperNamedExpressionChangeWithoutSnapshots(runtime: WorkPaperNamedExpressionFastPathRuntime, request: WorkPaperNamedExpressionFastPathRequest): WorkPaperChange[] | null;
37
+ export {};
@@ -0,0 +1,100 @@
1
+ import { ValueTag } from '@bilig/protocol';
2
+ import { WORKPAPER_PUBLIC_ERROR_NAMES } from './work-paper-config.js';
3
+ import { WorkPaperOperationError } from './work-paper-errors.js';
4
+ import { cloneNamedExpressionValue, createInternalNamedExpressionRecord, createSerializedWorkPaperNamedExpression, createWorkPaperNamedExpressionChange, } from './work-paper-named-expression-helpers.js';
5
+ import { makeNamedExpressionKey, matrixValuesEqual, tryEvaluateSimpleNamedExpression } from './work-paper-runtime-helpers.js';
6
+ export function tryCaptureWorkPaperNamedExpressionChangeWithoutSnapshots(runtime, request) {
7
+ if (!runtime.canUseNamedExpressionChangeFastPath()) {
8
+ return null;
9
+ }
10
+ runtime.assertNotDisposed();
11
+ runtime.materializePendingLazyTrackedChanges();
12
+ runtime.downgradeTrackedBatchFastPath();
13
+ if (!runtime.canUseNamedExpressionChangeFastPath()) {
14
+ return null;
15
+ }
16
+ const key = makeNamedExpressionKey(request.existing.publicName, request.existing.scope);
17
+ const cachedBeforeValue = runtime.getCachedNamedExpressionValue(key);
18
+ const beforeValue = cachedBeforeValue ?? runtime.evaluateNamedExpression(request.existing);
19
+ const afterScalarValue = tryEvaluateSimpleNamedExpression(request.expression);
20
+ if (afterScalarValue?.tag === ValueTag.Number && !runtime.hasAnyListeners()) {
21
+ const directChanges = tryCaptureNumericNamedExpressionChange(runtime, request, key, beforeValue, afterScalarValue.value);
22
+ if (directChanges) {
23
+ return directChanges;
24
+ }
25
+ }
26
+ runtime.drainTrackedEngineEvents();
27
+ try {
28
+ runtime.withRetainedTrackedEngineEventIndices(() => {
29
+ runtime.upsertNamedExpressionInternal({
30
+ ...createSerializedWorkPaperNamedExpression({
31
+ name: request.expressionName,
32
+ expression: request.expression,
33
+ scope: request.scope,
34
+ options: request.options,
35
+ }),
36
+ });
37
+ });
38
+ }
39
+ catch (error) {
40
+ throw publicOrOperationError(runtime, error);
41
+ }
42
+ const updated = runtime.namedExpressionRecord(request.expressionName, request.scope);
43
+ const afterValue = cloneNamedExpressionValue(runtime.evaluateNamedExpression(updated));
44
+ runtime.setCachedNamedExpressionValue(key, cloneNamedExpressionValue(afterValue));
45
+ const cellChanges = runtime.computeTrackedChangesWithoutVisibilityCache(runtime.drainTrackedEngineEvents(), {
46
+ preferLazyPublicChanges: !runtime.hasAnyListeners(),
47
+ });
48
+ if (matrixValuesEqual(beforeValue, afterValue)) {
49
+ return cellChanges;
50
+ }
51
+ return [
52
+ ...cellChanges,
53
+ createWorkPaperNamedExpressionChange({
54
+ name: updated.publicName,
55
+ scope: updated.scope,
56
+ newValue: cloneNamedExpressionValue(afterValue),
57
+ }),
58
+ ];
59
+ }
60
+ function tryCaptureNumericNamedExpressionChange(runtime, request, cacheKey, beforeValue, afterValue) {
61
+ const record = createInternalNamedExpressionRecord(createSerializedWorkPaperNamedExpression({
62
+ name: request.expressionName,
63
+ expression: request.expression,
64
+ scope: request.scope,
65
+ options: request.options,
66
+ }));
67
+ const definedNameSnapshot = runtime.toDefinedNameSnapshot(request.expression, request.scope);
68
+ try {
69
+ const changedCellIndices = runtime.upsertNumericDefinedNameFast(record.internalName, definedNameSnapshot, afterValue);
70
+ if (changedCellIndices) {
71
+ runtime.setNamedExpressionRecord(makeNamedExpressionKey(record.publicName, record.scope), record);
72
+ runtime.setCachedNamedExpressionValue(cacheKey, cloneNamedExpressionValue({ tag: ValueTag.Number, value: afterValue }));
73
+ const cellChanges = changedCellIndices
74
+ .map((cellIndex) => runtime.readSingleTrackedCellChange(cellIndex))
75
+ .filter((change) => change !== undefined);
76
+ const orderedCellChanges = cellChanges.length > 1 ? runtime.orderCellChanges(cellChanges, cellChanges.length) : cellChanges;
77
+ return matrixValuesEqual(beforeValue, { tag: ValueTag.Number, value: afterValue })
78
+ ? orderedCellChanges
79
+ : [
80
+ ...orderedCellChanges,
81
+ createWorkPaperNamedExpressionChange({
82
+ name: record.publicName,
83
+ scope: record.scope,
84
+ newValue: cloneNamedExpressionValue({ tag: ValueTag.Number, value: afterValue }),
85
+ }),
86
+ ];
87
+ }
88
+ }
89
+ catch (error) {
90
+ throw publicOrOperationError(runtime, error);
91
+ }
92
+ return null;
93
+ }
94
+ function publicOrOperationError(runtime, error) {
95
+ if (error instanceof Error && WORKPAPER_PUBLIC_ERROR_NAMES.has(error.name)) {
96
+ return error;
97
+ }
98
+ return new WorkPaperOperationError(runtime.messageOf(error, 'Mutation failed'));
99
+ }
100
+ //# sourceMappingURL=work-paper-named-expression-fast-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"work-paper-named-expression-fast-path.js","sourceRoot":"","sources":["../src/work-paper-named-expression-fast-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,QAAQ,EAAyC,MAAM,iBAAiB,CAAA;AACjG,OAAO,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAw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,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;gBAChF,CAAC,CAAC,kBAAkB;gBACpB,CAAC,CAAC;oBACE,GAAG,kBAAkB;oBACrB,oCAAoC,CAAC;wBACnC,IAAI,EAAE,MAAM,CAAC,UAAU;wBACvB,KAAK,EAAE,MAAM,CAAC,KAAK;wBACnB,QAAQ,EAAE,yBAAyB,CAAC,EAAE,GAAG,EAAE,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;qBACjF,CAAC;iBACH,CAAA;QACP,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,sBAAsB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC9C,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC;AAED,SAAS,sBAAsB,CAAC,OAAgD,EAAE,KAAc;IAC9F,IAAI,KAAK,YAAY,KAAK,IAAI,4BAA4B,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3E,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAA;AACjF,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { type CellSnapshot, type CellValue, type WorkbookDefinedNameValueSnapshot } from '@bilig/protocol';
2
+ import type { RawCellContent, SerializedWorkPaperNamedExpression, WorkPaperChange, WorkPaperNamedExpression } from './work-paper-types.js';
3
+ export interface InternalNamedExpression {
4
+ publicName: string;
5
+ normalizedName: string;
6
+ internalName: string;
7
+ scope?: number;
8
+ expression: RawCellContent;
9
+ options?: Record<string, string | number | boolean>;
10
+ }
11
+ export type WorkPaperNamedExpressionValue = CellValue | CellValue[][];
12
+ export type WorkPaperNamedExpressionValueSnapshot = Map<string, WorkPaperNamedExpressionValue>;
13
+ export declare function cloneNamedExpressionValue(value: CellValue | CellValue[][]): CellValue | CellValue[][];
14
+ export declare function captureWorkPaperNamedExpressionValueSnapshot(expressions: Iterable<InternalNamedExpression>, evaluateExpression: (expression: InternalNamedExpression) => WorkPaperNamedExpressionValue): WorkPaperNamedExpressionValueSnapshot;
15
+ export declare function compareWorkPaperNamedExpressionChanges(left: WorkPaperChange, right: WorkPaperChange): number;
16
+ export declare function createWorkPaperNamedExpressionChange(args: {
17
+ readonly name: string;
18
+ readonly scope: number | undefined;
19
+ readonly newValue: CellValue | CellValue[][];
20
+ }): WorkPaperChange;
21
+ export declare function createSerializedWorkPaperNamedExpression(args: {
22
+ readonly name: string;
23
+ readonly expression: RawCellContent;
24
+ readonly scope: number | undefined;
25
+ readonly options: Record<string, string | number | boolean> | undefined;
26
+ }): SerializedWorkPaperNamedExpression;
27
+ export declare function publicWorkPaperNamedExpressionFromInternal(expression: InternalNamedExpression): WorkPaperNamedExpression;
28
+ export declare function computeWorkPaperNamedExpressionChanges(args: {
29
+ readonly beforeNames: WorkPaperNamedExpressionValueSnapshot;
30
+ readonly afterNames: WorkPaperNamedExpressionValueSnapshot;
31
+ readonly expressionsByKey: ReadonlyMap<string, InternalNamedExpression>;
32
+ }): WorkPaperChange[];
33
+ export declare function validateWorkPaperNamedExpression(args: {
34
+ readonly expressionName: string;
35
+ readonly expression: RawCellContent;
36
+ readonly scope?: number;
37
+ readonly requireScope: (scope: number) => void;
38
+ readonly messageOf: (error: unknown, fallback: string) => string;
39
+ }): void;
40
+ export declare function createInternalNamedExpressionRecord(expression: SerializedWorkPaperNamedExpression): InternalNamedExpression;
41
+ export declare function listWorkPaperNamedExpressions(expressions: Iterable<InternalNamedExpression>, scope?: number): string[];
42
+ export declare function serializeWorkPaperNamedExpressions(expressions: Iterable<InternalNamedExpression>): SerializedWorkPaperNamedExpression[];
43
+ export declare function workPaperNamedExpressionToDefinedNameSnapshot(args: {
44
+ readonly expression: RawCellContent;
45
+ readonly scope?: number;
46
+ readonly defaultScopeId: number;
47
+ readonly rewriteFormulaForStorage: (formula: string, ownerSheetId: number) => string;
48
+ }): WorkbookDefinedNameValueSnapshot;
49
+ export declare function evaluateWorkPaperNamedExpression(expression: InternalNamedExpression, calculateFormula: (formula: string, scope?: number) => CellValue | CellValue[][]): CellValue | CellValue[][];
50
+ export declare function workPaperCellSnapshotToRawContent(args: {
51
+ readonly cell: CellSnapshot;
52
+ readonly ownerSheetId: number;
53
+ readonly restorePublicFormula: (formula: string, ownerSheetId: number) => string;
54
+ }): RawCellContent;
@@ -0,0 +1,179 @@
1
+ import { isCellReferenceText, parseFormula } from '@bilig/formula';
2
+ import { ValueTag } from '@bilig/protocol';
3
+ import { WorkPaperNamedExpressionNameIsInvalidError, WorkPaperNoRelativeAddressesAllowedError, WorkPaperUnableToParseError, } from './work-paper-errors.js';
4
+ import { cloneCellValue, formulaHasRelativeReferences, isFormulaContent, makeInternalScopedName, makeNamedExpressionKey, matrixValuesEqual, normalizeName, scalarValueFromLiteral, stripLeadingEquals, tryEvaluateSimpleNamedExpression, tryEvaluateSimpleScalarFormulaBody, tryReadSimpleScalarFormulaBody, } from './work-paper-runtime-helpers.js';
5
+ import { compareSheetNames } from './work-paper-sheet-inspection.js';
6
+ export function cloneNamedExpressionValue(value) {
7
+ if (!Array.isArray(value)) {
8
+ return cloneCellValue(value);
9
+ }
10
+ return value.map((row) => row.map((cell) => cloneCellValue(cell)));
11
+ }
12
+ export function captureWorkPaperNamedExpressionValueSnapshot(expressions, evaluateExpression) {
13
+ const snapshot = new Map();
14
+ [...expressions].forEach((expression) => {
15
+ snapshot.set(makeNamedExpressionKey(expression.publicName, expression.scope), cloneNamedExpressionValue(evaluateExpression(expression)));
16
+ });
17
+ return snapshot;
18
+ }
19
+ export function compareWorkPaperNamedExpressionChanges(left, right) {
20
+ if (left.kind !== 'named-expression' || right.kind !== 'named-expression') {
21
+ return 0;
22
+ }
23
+ return (left.scope ?? -1) - (right.scope ?? -1) || left.name.localeCompare(right.name);
24
+ }
25
+ export function createWorkPaperNamedExpressionChange(args) {
26
+ const change = {
27
+ kind: 'named-expression',
28
+ name: args.name,
29
+ newValue: args.newValue,
30
+ };
31
+ if (args.scope !== undefined) {
32
+ change.scope = args.scope;
33
+ }
34
+ return change;
35
+ }
36
+ export function createSerializedWorkPaperNamedExpression(args) {
37
+ const expression = {
38
+ name: args.name,
39
+ expression: args.expression,
40
+ };
41
+ if (args.scope !== undefined) {
42
+ expression.scope = args.scope;
43
+ }
44
+ if (args.options !== undefined) {
45
+ expression.options = structuredClone(args.options);
46
+ }
47
+ return expression;
48
+ }
49
+ export function publicWorkPaperNamedExpressionFromInternal(expression) {
50
+ return createSerializedWorkPaperNamedExpression({
51
+ name: expression.publicName,
52
+ expression: expression.expression,
53
+ scope: expression.scope,
54
+ options: expression.options,
55
+ });
56
+ }
57
+ export function computeWorkPaperNamedExpressionChanges(args) {
58
+ const namedExpressionChanges = [];
59
+ args.afterNames.forEach((afterValue, key) => {
60
+ const beforeValue = args.beforeNames.get(key);
61
+ if (matrixValuesEqual(beforeValue, afterValue)) {
62
+ return;
63
+ }
64
+ const expression = args.expressionsByKey.get(key);
65
+ if (!expression) {
66
+ return;
67
+ }
68
+ namedExpressionChanges.push(createWorkPaperNamedExpressionChange({
69
+ name: expression.publicName,
70
+ scope: expression.scope,
71
+ newValue: cloneNamedExpressionValue(afterValue),
72
+ }));
73
+ });
74
+ return namedExpressionChanges.toSorted(compareWorkPaperNamedExpressionChanges);
75
+ }
76
+ export function validateWorkPaperNamedExpression(args) {
77
+ const trimmed = args.expressionName.trim();
78
+ if (!/^[A-Za-z_][A-Za-z0-9_.]*$/.test(trimmed) || isCellReferenceText(trimmed)) {
79
+ throw new WorkPaperNamedExpressionNameIsInvalidError(args.expressionName);
80
+ }
81
+ if (args.scope !== undefined) {
82
+ args.requireScope(args.scope);
83
+ }
84
+ if (isFormulaContent(args.expression)) {
85
+ const simpleBody = tryReadSimpleScalarFormulaBody(args.expression);
86
+ if (simpleBody !== undefined && tryEvaluateSimpleScalarFormulaBody(simpleBody) !== undefined) {
87
+ return;
88
+ }
89
+ try {
90
+ const parsed = parseFormula(stripLeadingEquals(args.expression));
91
+ if (formulaHasRelativeReferences(parsed)) {
92
+ throw new WorkPaperNoRelativeAddressesAllowedError();
93
+ }
94
+ }
95
+ catch (error) {
96
+ if (error instanceof WorkPaperNoRelativeAddressesAllowedError) {
97
+ throw error;
98
+ }
99
+ throw new WorkPaperUnableToParseError({
100
+ expressionName: args.expressionName,
101
+ reason: args.messageOf(error, `Invalid named expression formula for '${args.expressionName}'`),
102
+ });
103
+ }
104
+ }
105
+ }
106
+ export function createInternalNamedExpressionRecord(expression) {
107
+ const trimmed = expression.name.trim();
108
+ const record = {
109
+ publicName: trimmed,
110
+ normalizedName: normalizeName(trimmed),
111
+ internalName: expression.scope === undefined ? trimmed : makeInternalScopedName(expression.scope, trimmed),
112
+ expression: expression.expression,
113
+ };
114
+ if (expression.scope !== undefined) {
115
+ record.scope = expression.scope;
116
+ }
117
+ if (expression.options !== undefined) {
118
+ record.options = structuredClone(expression.options);
119
+ }
120
+ return record;
121
+ }
122
+ export function listWorkPaperNamedExpressions(expressions, scope) {
123
+ return [...expressions]
124
+ .filter((expression) => expression.scope === scope)
125
+ .map((expression) => expression.publicName)
126
+ .toSorted(compareSheetNames);
127
+ }
128
+ export function serializeWorkPaperNamedExpressions(expressions) {
129
+ return [...expressions]
130
+ .map((expression) => publicWorkPaperNamedExpressionFromInternal(expression))
131
+ .toSorted((left, right) => (left.scope ?? -1) - (right.scope ?? -1) || left.name.localeCompare(right.name));
132
+ }
133
+ export function workPaperNamedExpressionToDefinedNameSnapshot(args) {
134
+ if (args.expression === null || typeof args.expression === 'number' || typeof args.expression === 'boolean') {
135
+ return args.expression;
136
+ }
137
+ if (typeof args.expression === 'string' && args.expression.trim().startsWith('=')) {
138
+ const simpleBody = tryReadSimpleScalarFormulaBody(args.expression);
139
+ if (simpleBody !== undefined && tryEvaluateSimpleScalarFormulaBody(simpleBody) !== undefined) {
140
+ return {
141
+ kind: 'formula',
142
+ formula: `=${simpleBody}`,
143
+ };
144
+ }
145
+ return {
146
+ kind: 'formula',
147
+ formula: `=${args.rewriteFormulaForStorage(stripLeadingEquals(args.expression), args.scope ?? args.defaultScopeId)}`,
148
+ };
149
+ }
150
+ return args.expression;
151
+ }
152
+ export function evaluateWorkPaperNamedExpression(expression, calculateFormula) {
153
+ const raw = expression.expression;
154
+ const simpleValue = tryEvaluateSimpleNamedExpression(raw);
155
+ if (simpleValue !== undefined) {
156
+ return simpleValue;
157
+ }
158
+ return typeof raw === 'string' ? calculateFormula(raw, expression.scope) : scalarValueFromLiteral(raw);
159
+ }
160
+ export function workPaperCellSnapshotToRawContent(args) {
161
+ if (args.cell.formula) {
162
+ return `=${args.restorePublicFormula(args.cell.formula, args.ownerSheetId)}`;
163
+ }
164
+ if (args.cell.input !== undefined) {
165
+ return args.cell.input;
166
+ }
167
+ switch (args.cell.value.tag) {
168
+ case ValueTag.Empty:
169
+ case ValueTag.Error:
170
+ return null;
171
+ case ValueTag.Number:
172
+ return args.cell.value.value;
173
+ case ValueTag.Boolean:
174
+ return args.cell.value.value;
175
+ case ValueTag.String:
176
+ return args.cell.value.value;
177
+ }
178
+ }
179
+ //# sourceMappingURL=work-paper-named-expression-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"work-paper-named-expression-helpers.js","sourceRoot":"","sources":["../src/work-paper-named-expression-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAClE,OAAO,EAAE,QAAQ,EAA4E,MAAM,iBAAiB,CAAA;AACpH,OAAO,EACL,0CAA0C,EAC1C,wCAAwC,EACxC,2BAA2B,GAC5B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,cAAc,EACd,4BAA4B,EAC5B,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EACjB,aAAa,EACb,sBAAsB,EACtB,kBAAkB,EAClB,gCAAgC,EAChC,kCAAkC,EA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,CAAC,KAAK,CAAA;QAC9B,KAAK,QAAQ,CAAC,OAAO;YACnB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAA;QAC9B,KAAK,QAAQ,CAAC,MAAM;YAClB,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAA;IAChC,CAAC;AACH,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { CellValue } from '@bilig/protocol';
2
+ import { type InternalNamedExpression } from './work-paper-named-expression-helpers.js';
3
+ import type { RawCellContent, SerializedWorkPaperNamedExpression, WorkPaperChange, WorkPaperDetailedEventMap, WorkPaperNamedExpression } from './work-paper-types.js';
4
+ type NamedExpressionEvent = {
5
+ readonly eventName: 'namedExpressionAdded';
6
+ readonly payload: WorkPaperDetailedEventMap['namedExpressionAdded'];
7
+ } | {
8
+ readonly eventName: 'namedExpressionRemoved';
9
+ readonly payload: WorkPaperDetailedEventMap['namedExpressionRemoved'];
10
+ };
11
+ export interface WorkPaperNamedExpressionOperationsRuntime {
12
+ readonly assertReadable: () => void;
13
+ readonly getNamedExpression: (name: string, scope?: number) => InternalNamedExpression | undefined;
14
+ readonly getNamedExpressionValues: () => Iterable<InternalNamedExpression>;
15
+ readonly evaluateNamedExpression: (expression: InternalNamedExpression) => CellValue | CellValue[][];
16
+ readonly isItPossibleToAddNamedExpression: (expressionName: string, expression: RawCellContent, scope?: number) => boolean;
17
+ readonly isItPossibleToRemoveNamedExpression: (expressionName: string, scope?: number) => boolean;
18
+ readonly validateNamedExpression: (expressionName: string, expression: RawCellContent, scope?: number) => void;
19
+ readonly tryCaptureNamedExpressionChangeWithoutSnapshots: (existing: InternalNamedExpression, expressionName: string, expression: RawCellContent, scope?: number, options?: Record<string, string | number | boolean>) => WorkPaperChange[] | null;
20
+ readonly captureChanges: (event: NamedExpressionEvent | undefined, mutate: () => void) => WorkPaperChange[];
21
+ readonly upsertNamedExpressionInternal: (expression: SerializedWorkPaperNamedExpression, options: {
22
+ readonly duringInitialization: boolean;
23
+ readonly skipValidation?: boolean;
24
+ }) => void;
25
+ readonly deleteNamedExpressionRecord: (name: string, scope?: number) => void;
26
+ readonly deleteDefinedName: (internalName: string) => void;
27
+ }
28
+ export interface WorkPaperNamedExpressionOperations {
29
+ readonly getNamedExpressionValue: (name: string, scope?: number) => CellValue | CellValue[][] | undefined;
30
+ readonly getNamedExpressionFormula: (name: string, scope?: number) => string | undefined;
31
+ readonly getNamedExpression: (name: string, scope?: number) => WorkPaperNamedExpression | undefined;
32
+ readonly addNamedExpression: (expressionName: string, expression: RawCellContent, scope?: number, options?: Record<string, string | number | boolean>) => WorkPaperChange[];
33
+ readonly changeNamedExpression: (expressionName: string, expression: RawCellContent, scope?: number, options?: Record<string, string | number | boolean>) => WorkPaperChange[];
34
+ readonly removeNamedExpression: (expressionName: string, scope?: number) => WorkPaperChange[];
35
+ readonly listNamedExpressions: (scope?: number) => string[];
36
+ readonly getAllNamedExpressionsSerialized: () => SerializedWorkPaperNamedExpression[];
37
+ }
38
+ export declare function createWorkPaperNamedExpressionOperations(runtime: WorkPaperNamedExpressionOperationsRuntime): WorkPaperNamedExpressionOperations;
39
+ export {};