@datalayer/cells 0.0.0-stage → 0.0.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 (96) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +55 -2
  3. package/lib/chrome/index.d.ts +7 -0
  4. package/lib/chrome/index.d.ts.map +1 -0
  5. package/lib/chrome/index.js +7 -0
  6. package/lib/chrome/index.js.map +1 -0
  7. package/lib/collab/index.d.ts +7 -0
  8. package/lib/collab/index.d.ts.map +1 -0
  9. package/lib/collab/index.js +7 -0
  10. package/lib/collab/index.js.map +1 -0
  11. package/lib/core/axis.d.ts +103 -0
  12. package/lib/core/axis.d.ts.map +1 -0
  13. package/lib/core/axis.js +470 -0
  14. package/lib/core/axis.js.map +1 -0
  15. package/lib/core/cells.d.ts +71 -0
  16. package/lib/core/cells.d.ts.map +1 -0
  17. package/lib/core/cells.js +285 -0
  18. package/lib/core/cells.js.map +1 -0
  19. package/lib/core/commands.d.ts +157 -0
  20. package/lib/core/commands.d.ts.map +1 -0
  21. package/lib/core/commands.js +620 -0
  22. package/lib/core/commands.js.map +1 -0
  23. package/lib/core/format.d.ts +52 -0
  24. package/lib/core/format.d.ts.map +1 -0
  25. package/lib/core/format.js +264 -0
  26. package/lib/core/format.js.map +1 -0
  27. package/lib/core/history.d.ts +42 -0
  28. package/lib/core/history.d.ts.map +1 -0
  29. package/lib/core/history.js +63 -0
  30. package/lib/core/history.js.map +1 -0
  31. package/lib/core/index.d.ts +23 -0
  32. package/lib/core/index.d.ts.map +1 -0
  33. package/lib/core/index.js +28 -0
  34. package/lib/core/index.js.map +1 -0
  35. package/lib/core/model.d.ts +116 -0
  36. package/lib/core/model.d.ts.map +1 -0
  37. package/lib/core/model.js +330 -0
  38. package/lib/core/model.js.map +1 -0
  39. package/lib/core/patches.d.ts +140 -0
  40. package/lib/core/patches.d.ts.map +1 -0
  41. package/lib/core/patches.js +272 -0
  42. package/lib/core/patches.js.map +1 -0
  43. package/lib/core/reactor.d.ts +24 -0
  44. package/lib/core/reactor.d.ts.map +1 -0
  45. package/lib/core/reactor.js +48 -0
  46. package/lib/core/reactor.js.map +1 -0
  47. package/lib/core/selection.d.ts +81 -0
  48. package/lib/core/selection.d.ts.map +1 -0
  49. package/lib/core/selection.js +175 -0
  50. package/lib/core/selection.js.map +1 -0
  51. package/lib/core/strings.d.ts +19 -0
  52. package/lib/core/strings.d.ts.map +1 -0
  53. package/lib/core/strings.js +61 -0
  54. package/lib/core/strings.js.map +1 -0
  55. package/lib/core/styles.d.ts +48 -0
  56. package/lib/core/styles.d.ts.map +1 -0
  57. package/lib/core/styles.js +102 -0
  58. package/lib/core/styles.js.map +1 -0
  59. package/lib/core/values.d.ts +20 -0
  60. package/lib/core/values.d.ts.map +1 -0
  61. package/lib/core/values.js +39 -0
  62. package/lib/core/values.js.map +1 -0
  63. package/lib/core/workbook.d.ts +59 -0
  64. package/lib/core/workbook.d.ts.map +1 -0
  65. package/lib/core/workbook.js +101 -0
  66. package/lib/core/workbook.js.map +1 -0
  67. package/lib/core/zone.d.ts +48 -0
  68. package/lib/core/zone.d.ts.map +1 -0
  69. package/lib/core/zone.js +89 -0
  70. package/lib/core/zone.js.map +1 -0
  71. package/lib/csv/index.d.ts +7 -0
  72. package/lib/csv/index.d.ts.map +1 -0
  73. package/lib/csv/index.js +7 -0
  74. package/lib/csv/index.js.map +1 -0
  75. package/lib/index.d.ts +8 -0
  76. package/lib/index.d.ts.map +1 -0
  77. package/lib/index.js +13 -0
  78. package/lib/index.js.map +1 -0
  79. package/lib/plugin/index.d.ts +7 -0
  80. package/lib/plugin/index.d.ts.map +1 -0
  81. package/lib/plugin/index.js +7 -0
  82. package/lib/plugin/index.js.map +1 -0
  83. package/lib/points/index.d.ts +154 -0
  84. package/lib/points/index.d.ts.map +1 -0
  85. package/lib/points/index.js +50 -0
  86. package/lib/points/index.js.map +1 -0
  87. package/lib/points/resolve.d.ts +56 -0
  88. package/lib/points/resolve.d.ts.map +1 -0
  89. package/lib/points/resolve.js +106 -0
  90. package/lib/points/resolve.js.map +1 -0
  91. package/lib/xlsx/index.d.ts +7 -0
  92. package/lib/xlsx/index.d.ts.map +1 -0
  93. package/lib/xlsx/index.js +7 -0
  94. package/lib/xlsx/index.js.map +1 -0
  95. package/package.json +116 -4
  96. package/style/cells.css +7 -0
@@ -0,0 +1,330 @@
1
+ /*
2
+ * Copyright (c) 2022-2026 Datalayer, Inc.
3
+ *
4
+ * MIT License
5
+ */
6
+ import { CellsCommands, CellsEditGate, CellsPatchOps, PointTable, } from '../points/index.js';
7
+ import { OK, refuse } from './commands.js';
8
+ import { DEFAULT_HISTORY_LIMITS, LocalHistory } from './history.js';
9
+ import { buildCellsReactor, CELLS_CORE_PLUGIN } from './reactor.js';
10
+ import { initialSelection } from './selection.js';
11
+ import { loadInto, toJSON } from './format.js';
12
+ import { cellError } from './values.js';
13
+ import { DEFAULT_LIMITS, Workbook } from './workbook.js';
14
+ export class CellsModel {
15
+ reactor;
16
+ workbook;
17
+ readOnly;
18
+ #commands;
19
+ #patchOps;
20
+ #history;
21
+ #listeners = new Set();
22
+ #selectionListeners = new Set();
23
+ #revision = 0;
24
+ #selection;
25
+ /** The open transaction, while `transact` runs. */
26
+ #open = null;
27
+ constructor(options = {}) {
28
+ if (options.reactor !== undefined && options.plugins !== undefined) {
29
+ throw new Error('Pass a Reactor platform or plugins to build one from, not both.');
30
+ }
31
+ if (options.reactor !== undefined && !options.reactor.hasPlugin(CELLS_CORE_PLUGIN)) {
32
+ throw new Error(`The Reactor platform has no ${CELLS_CORE_PLUGIN}: add CellsCorePlugin to its plugins.`);
33
+ }
34
+ this.reactor = options.reactor ?? buildCellsReactor(options.plugins ?? []);
35
+ this.readOnly = options.readOnly ?? false;
36
+ this.workbook = new Workbook({ ...DEFAULT_LIMITS, ...options.limits });
37
+ this.#history = new LocalHistory({ ...DEFAULT_HISTORY_LIMITS, ...options.history });
38
+ this.#commands = new PointTable(this.reactor, CellsCommands, {
39
+ label: 'command',
40
+ key: (h) => h.type,
41
+ check: (h) => {
42
+ if (typeof h.type !== 'string' || h.type === '')
43
+ throw new Error('a command handler has a type');
44
+ if (typeof h.apply !== 'function')
45
+ throw new Error(`the command ${h.type} has no apply`);
46
+ },
47
+ });
48
+ this.#patchOps = new PointTable(this.reactor, CellsPatchOps, {
49
+ label: 'patch op',
50
+ key: (op) => op.op,
51
+ check: (op) => {
52
+ for (const f of ['apply', 'invert', 'example']) {
53
+ if (typeof op[f] !== 'function')
54
+ throw new Error(`the patch op '${op.op}' has no ${f}`);
55
+ }
56
+ },
57
+ });
58
+ if (options.data !== undefined)
59
+ loadInto(this.workbook, options.data);
60
+ else
61
+ this.workbook.sheets.push(this.workbook.createSheet('Sheet1'));
62
+ if (this.workbook.sheets.length === 0)
63
+ throw new Error('A workbook holds at least one sheet.');
64
+ this.#selection = initialSelection(this.workbook.sheets[0].id);
65
+ }
66
+ // ---------------------------------------------------------------- writing
67
+ /** Run a command: refused with reasons, or applied as one undo step (or into the open transaction). */
68
+ dispatch(command) {
69
+ if (this.readOnly)
70
+ return refuse('ReadOnly', 'The workbook is read-only.');
71
+ const handler = this.#commands.get(command.type);
72
+ if (handler === undefined) {
73
+ return refuse('UnknownCommand', `No plugin handles the command '${command.type}'.`);
74
+ }
75
+ const context = { workbook: this.workbook };
76
+ const allowed = handler.value.allow ? handler.value.allow(context, command) : OK;
77
+ if (!allowed.ok)
78
+ return allowed;
79
+ const verdict = this.reactor.checkGate(CellsEditGate, { command, context });
80
+ if (!verdict.allowed) {
81
+ return refuse('Gate', verdict.reason ?? `${verdict.blockedBy ?? 'A plugin'} refused ${command.type}.`);
82
+ }
83
+ const patches = handler.value.apply(context, command);
84
+ this.#applyAll(patches);
85
+ if (this.#open) {
86
+ this.#open.commands.push(command);
87
+ this.#open.patches.push(...patches);
88
+ }
89
+ else {
90
+ this.#commit(command.type, [command], patches, this.#selection);
91
+ }
92
+ return OK;
93
+ }
94
+ /**
95
+ * Group every command `fn` dispatches into one undo step and one change
96
+ * event. If `fn` throws, what it applied is rolled back and the error rethrown.
97
+ * A refused command inside does not stop the others; `fn` decides.
98
+ */
99
+ transact(label, fn) {
100
+ if (this.#open)
101
+ return fn(); // nested: part of the outer transaction
102
+ this.#open = { label, commands: [], patches: [], selectionBefore: this.#selection };
103
+ let result;
104
+ try {
105
+ result = fn();
106
+ }
107
+ catch (error) {
108
+ const open = this.#open;
109
+ this.#open = null;
110
+ this.#applyAll(this.#inverses(open.patches));
111
+ throw error;
112
+ }
113
+ const open = this.#open;
114
+ this.#open = null;
115
+ if (open.patches.length > 0)
116
+ this.#commit(label, open.commands, open.patches, open.selectionBefore);
117
+ return result;
118
+ }
119
+ undo() {
120
+ if (this.#open)
121
+ throw new Error('Cannot undo inside a transaction.');
122
+ const step = this.#history.popUndo();
123
+ if (step === undefined)
124
+ return false;
125
+ const inverses = this.#inverses(step.patches);
126
+ this.#applyAll(inverses);
127
+ this.#setSelection(this.#validSelection(step.selectionBefore));
128
+ this.#emit({ label: step.label, commands: [], patches: inverses, origin: 'undo' });
129
+ return true;
130
+ }
131
+ redo() {
132
+ if (this.#open)
133
+ throw new Error('Cannot redo inside a transaction.');
134
+ const step = this.#history.popRedo();
135
+ if (step === undefined)
136
+ return false;
137
+ this.#applyAll(step.patches);
138
+ this.#setSelection(this.#validSelection(step.selectionAfter));
139
+ this.#emit({ label: step.label, commands: [], patches: step.patches, origin: 'redo' });
140
+ return true;
141
+ }
142
+ get canUndo() {
143
+ return this.#history.canUndo;
144
+ }
145
+ get canRedo() {
146
+ return this.#history.canRedo;
147
+ }
148
+ /** The labels of the steps undo and redo would take. */
149
+ get historyLabels() {
150
+ return { undo: this.#history.undoLabel, redo: this.#history.redoLabel };
151
+ }
152
+ /**
153
+ * Apply patches that did not come from a local command (a remote peer's),
154
+ * without history. The binding (`./collab`) is the caller.
155
+ */
156
+ applyRemote(patches, label = 'remote') {
157
+ this.#applyAll(patches);
158
+ this.#emit({ label, commands: [], patches, origin: 'remote' });
159
+ }
160
+ // ---------------------------------------------------------------- listening
161
+ /** Called after every committed change; returns the unsubscriber. */
162
+ subscribe(listener) {
163
+ this.#listeners.add(listener);
164
+ return () => this.#listeners.delete(listener);
165
+ }
166
+ /** The selection stream: called on every selection change. */
167
+ subscribeSelection(listener) {
168
+ this.#selectionListeners.add(listener);
169
+ return () => this.#selectionListeners.delete(listener);
170
+ }
171
+ /** Grows on every change: what `useSyncExternalStore` compares. */
172
+ get revision() {
173
+ return this.#revision;
174
+ }
175
+ // ---------------------------------------------------------------- selection
176
+ get selection() {
177
+ return this.#selection;
178
+ }
179
+ /** Set the selection (view state: never undone, never synced). */
180
+ select(selection) {
181
+ if (!this.workbook.hasSheet(selection.sheet))
182
+ throw new Error(`No sheet '${selection.sheet}' to select in.`);
183
+ if (selection.zones.length === 0)
184
+ throw new Error('A selection holds at least one zone.');
185
+ this.#setSelection(selection);
186
+ }
187
+ // ---------------------------------------------------------------- reading
188
+ get sheets() {
189
+ return this.workbook.sheets;
190
+ }
191
+ sheet(id) {
192
+ return this.workbook.sheet(id);
193
+ }
194
+ /** What a cell holds, or `null`. */
195
+ content(sheet, row, col) {
196
+ return this.workbook.sheet(sheet).cells.get(row, col);
197
+ }
198
+ /**
199
+ * What a cell shows: its value, or a formula's last computed value. Until
200
+ * the formula engine evaluates it, a formula with no cached value is `#NAME?`.
201
+ */
202
+ value(sheet, row, col) {
203
+ const c = this.content(sheet, row, col);
204
+ if (c === null)
205
+ return null;
206
+ if (c.formula !== undefined && c.value === null)
207
+ return cellError('#NAME?', 'Not evaluated yet.');
208
+ return c.value;
209
+ }
210
+ style(sheet, row, col) {
211
+ const c = this.content(sheet, row, col);
212
+ return this.workbook.styles.get(c?.style ?? 0);
213
+ }
214
+ /** The workbook as `CellsWorkbook` JSON. */
215
+ toJSON() {
216
+ return toJSON(this.workbook);
217
+ }
218
+ /** The values a zone shows, as rows (empty cells are `null`). */
219
+ toRows(zone, sheet = this.#selection.sheet) {
220
+ const s = this.workbook.sheet(sheet);
221
+ if (zone.bottom >= s.rows.count ||
222
+ zone.right >= s.cols.count ||
223
+ zone.top < 0 ||
224
+ zone.left < 0) {
225
+ throw new Error(`The zone reaches outside sheet '${sheet}'.`);
226
+ }
227
+ const rows = [];
228
+ for (let r = zone.top; r <= zone.bottom; r += 1) {
229
+ const row = [];
230
+ for (let c = zone.left; c <= zone.right; c += 1)
231
+ row.push(this.value(sheet, r, c));
232
+ rows.push(row);
233
+ }
234
+ return rows;
235
+ }
236
+ /** Counters for the debug overlay and `useCellsStats`. */
237
+ stats() {
238
+ let cells = 0;
239
+ let chunks = 0;
240
+ for (const s of this.workbook.sheets) {
241
+ cells += s.cells.filled;
242
+ chunks += s.cells.chunkCount;
243
+ }
244
+ return {
245
+ revision: this.#revision,
246
+ sheets: this.workbook.sheets.length,
247
+ cells,
248
+ chunks,
249
+ strings: this.workbook.strings.size,
250
+ styles: this.workbook.styles.size,
251
+ formulas: this.workbook.formulas.size,
252
+ history: this.#history.size,
253
+ };
254
+ }
255
+ /** The handler of a command type, for hosts that list what can be dispatched. */
256
+ commandTypes() {
257
+ return [...this.#commands.keys()];
258
+ }
259
+ /** The patch op of a type; the forcing test reads it. */
260
+ patchOp(op) {
261
+ return this.#patchOps.get(op)?.value;
262
+ }
263
+ patchOpNames() {
264
+ return [...this.#patchOps.keys()];
265
+ }
266
+ // ---------------------------------------------------------------- internals
267
+ #applyAll(patches) {
268
+ const applied = [];
269
+ try {
270
+ for (const p of patches) {
271
+ const op = this.#patchOps.get(p.op);
272
+ if (op === undefined)
273
+ throw new Error(`No plugin registers the patch op '${p.op}'.`);
274
+ op.value.apply(this.workbook, p);
275
+ applied.push(p);
276
+ }
277
+ }
278
+ catch (error) {
279
+ // Leave the workbook as it was: undo what this batch applied, then fail loudly.
280
+ for (const p of this.#inverses(applied))
281
+ this.#patchOps.get(p.op).value.apply(this.workbook, p);
282
+ throw error;
283
+ }
284
+ }
285
+ /** The inverses of patches, in reverse order. */
286
+ #inverses(patches) {
287
+ const out = [];
288
+ for (let i = patches.length - 1; i >= 0; i -= 1) {
289
+ const op = this.#patchOps.get(patches[i].op);
290
+ if (op === undefined)
291
+ throw new Error(`No plugin registers the patch op '${patches[i].op}'.`);
292
+ out.push(op.value.invert(patches[i]));
293
+ }
294
+ return out;
295
+ }
296
+ #commit(label, commands, patches, selectionBefore) {
297
+ if (patches.length === 0)
298
+ return;
299
+ const selectionAfter = this.#validSelection(this.#selection);
300
+ if (selectionAfter !== this.#selection)
301
+ this.#setSelection(selectionAfter);
302
+ let bytes = 0;
303
+ for (const p of patches)
304
+ bytes += this.#patchOps.get(p.op)?.value.bytes?.(p) ?? 256;
305
+ this.#history.push({ label, patches, bytes, selectionBefore, selectionAfter });
306
+ this.#emit({ label, commands, patches, origin: 'local' });
307
+ }
308
+ /** A selection still valid after a change: its sheet may have gone. */
309
+ #validSelection(s) {
310
+ return this.workbook.hasSheet(s.sheet) ? s : initialSelection(this.workbook.sheets[0].id);
311
+ }
312
+ #setSelection(s) {
313
+ if (s === this.#selection)
314
+ return;
315
+ this.#selection = s;
316
+ this.#revision += 1;
317
+ for (const l of [...this.#selectionListeners])
318
+ l(s);
319
+ }
320
+ #emit(tx) {
321
+ this.#revision += 1;
322
+ for (const l of [...this.#listeners])
323
+ l(tx);
324
+ }
325
+ }
326
+ /** A model: from `data` (a `CellsWorkbook`), or one empty sheet. */
327
+ export function createCellsModel(options = {}) {
328
+ return new CellsModel(options);
329
+ }
330
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/core/model.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH,OAAO,EACL,aAAa,EACb,aAAa,EAEb,aAAa,EACb,UAAU,GACX,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAyD,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAClG,OAAO,EAAE,sBAAsB,EAAsB,YAAY,EAAE,MAAM,cAAc,CAA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AAO;QAClC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;QACpB,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC;QACpB,KAAK,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,mBAAmB,CAAC;YAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,EAAe;QACnB,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC;QACpB,KAAK,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC;YAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAC;CACF;AAED,oEAAoE;AACpE,MAAM,UAAU,gBAAgB,CAAC,UAA6B,EAAE;IAC9D,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Patches: the only writes to a workbook. A command produces patches; undo
3
+ * applies their inverses in reverse order, redo the patches again. Every
4
+ * patch op declares `apply`, `invert` and an `example` (what the forcing test
5
+ * inverts twice); a plugin's own op does the same through the
6
+ * `datalayer.cells.patchOp` point.
7
+ *
8
+ * Patches are position-addressed: they live in memory, never on the wire.
9
+ *
10
+ * @module core/patches
11
+ */
12
+ import type { AxisSegment } from './axis.js';
13
+ import type { CellContent } from './cells.js';
14
+ import type { CellValue } from './values.js';
15
+ import type { Frozen, Sheet, Workbook } from './workbook.js';
16
+ import type { Zone } from './zone.js';
17
+ export type AxisName = 'rows' | 'cols';
18
+ /**
19
+ * The populated cells of a zone, columnar. Strings are held by value (not
20
+ * pool indexes, which are reference-counted); styles by table index, which
21
+ * is stable.
22
+ */
23
+ export interface Snapshot {
24
+ readonly rows: Int32Array;
25
+ readonly cols: Int32Array;
26
+ readonly values: readonly CellValue[];
27
+ readonly formulas: readonly (string | undefined)[];
28
+ readonly styles: Uint16Array;
29
+ }
30
+ export interface CellsPatch {
31
+ readonly op: 'cells';
32
+ readonly sheet: string;
33
+ readonly zone: Zone;
34
+ readonly before: Snapshot;
35
+ readonly after: Snapshot;
36
+ }
37
+ export interface AxisInsertPatch {
38
+ readonly op: 'axis-insert';
39
+ readonly sheet: string;
40
+ readonly axis: AxisName;
41
+ readonly at: number;
42
+ readonly n: number;
43
+ /** What is inserted (`ids` always; sizes and hidden flags when not default). */
44
+ readonly inserted: AxisSegment;
45
+ /** What falls off the end, brought back by the inverse; absent when it was implicit. */
46
+ readonly dropped?: AxisSegment;
47
+ }
48
+ export interface AxisDeletePatch {
49
+ readonly op: 'axis-delete';
50
+ readonly sheet: string;
51
+ readonly axis: AxisName;
52
+ readonly at: number;
53
+ readonly n: number;
54
+ readonly removed: AxisSegment;
55
+ /** What appears at the end; absent: the implicit indexes the axis derives. */
56
+ readonly tail?: AxisSegment;
57
+ }
58
+ export interface AxisMovePatch {
59
+ readonly op: 'axis-move';
60
+ readonly sheet: string;
61
+ readonly axis: AxisName;
62
+ readonly at: number;
63
+ readonly n: number;
64
+ /** Before this index, in the coordinates before the move. */
65
+ readonly to: number;
66
+ }
67
+ export interface AxisSizesPatch {
68
+ readonly op: 'axis-sizes';
69
+ readonly sheet: string;
70
+ readonly axis: AxisName;
71
+ readonly at: number;
72
+ readonly n: number;
73
+ readonly before: {
74
+ readonly sizes: Float64Array | null;
75
+ readonly hidden: Uint8Array | null;
76
+ };
77
+ readonly after: {
78
+ readonly sizes: Float64Array | null;
79
+ readonly hidden: Uint8Array | null;
80
+ };
81
+ }
82
+ export interface MergesPatch {
83
+ readonly op: 'merges';
84
+ readonly sheet: string;
85
+ readonly before: readonly Zone[];
86
+ readonly after: readonly Zone[];
87
+ }
88
+ export interface SheetAddPatch {
89
+ readonly op: 'sheet-add';
90
+ readonly index: number;
91
+ /** The sheet itself: a deleted sheet comes back as the same object, ids and all. */
92
+ readonly sheet: Sheet;
93
+ }
94
+ export interface SheetDeletePatch {
95
+ readonly op: 'sheet-delete';
96
+ readonly index: number;
97
+ readonly sheet: Sheet;
98
+ }
99
+ export interface SheetRenamePatch {
100
+ readonly op: 'sheet-rename';
101
+ readonly sheet: string;
102
+ readonly before: string;
103
+ readonly after: string;
104
+ }
105
+ export interface SheetMovePatch {
106
+ readonly op: 'sheet-move';
107
+ readonly from: number;
108
+ readonly to: number;
109
+ }
110
+ export interface FrozenPatch {
111
+ readonly op: 'frozen';
112
+ readonly sheet: string;
113
+ readonly before: Frozen;
114
+ readonly after: Frozen;
115
+ }
116
+ /** The core patches. A plugin's patch is any object with an `op` its plugin registered. */
117
+ export type CorePatch = CellsPatch | AxisInsertPatch | AxisDeletePatch | AxisMovePatch | AxisSizesPatch | MergesPatch | SheetAddPatch | SheetDeletePatch | SheetRenamePatch | SheetMovePatch | FrozenPatch;
118
+ export interface Patch {
119
+ readonly op: string;
120
+ }
121
+ /** A patch op, as the `datalayer.cells.patchOp` point takes it. */
122
+ export interface PatchOp<P extends Patch = Patch> {
123
+ readonly op: P['op'];
124
+ apply(workbook: Workbook, patch: P): void;
125
+ /** The patch that undoes this one; it may be of another op (an insert's is a delete). */
126
+ invert(patch: P): Patch;
127
+ /** A sample patch for the forcing test, valid on a workbook holding one empty sheet `s1`. */
128
+ example(workbook: Workbook): P;
129
+ /** An estimate of the patch's memory, for the history's cap. */
130
+ bytes?(patch: P): number;
131
+ }
132
+ export declare const EMPTY_SNAPSHOT: Snapshot;
133
+ /** The populated cells of a zone. */
134
+ export declare function snapshot(sheet: Sheet, zone: Zone): Snapshot;
135
+ /** A snapshot from contents listed by position. */
136
+ export declare function snapshotOf(cells: readonly (readonly [number, number, CellContent])[]): Snapshot;
137
+ export declare function snapshotEntries(s: Snapshot): [number, number, CellContent][];
138
+ /** The core patch ops, contributed by `CellsCorePlugin`. */
139
+ export declare const CORE_PATCH_OPS: readonly PatchOp<any>[];
140
+ //# sourceMappingURL=patches.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patches.d.ts","sourceRoot":"","sources":["../../src/core/patches.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AAE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