@rowsncolumns/spreadsheet 10.19.3 → 10.19.4
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/dist/cjs/api/entry-selections.d.ts +85 -0
- package/dist/cjs/api/entry-selections.d.ts.map +1 -0
- package/dist/cjs/api/entry-selections.js +122 -0
- package/dist/cjs/atoms/entry-selections.atom.d.ts +11 -0
- package/dist/cjs/atoms/entry-selections.atom.d.ts.map +1 -0
- package/dist/cjs/atoms/entry-selections.atom.js +11 -0
- package/dist/cjs/components/canvas-grid/index.d.ts.map +1 -1
- package/dist/cjs/components/canvas-grid/index.js +193 -73
- package/dist/cjs/hooks/use-editable.d.ts +3 -2
- package/dist/cjs/hooks/use-editable.d.ts.map +1 -1
- package/dist/cjs/hooks/use-editor-change.d.ts +7 -3
- package/dist/cjs/hooks/use-editor-change.d.ts.map +1 -1
- package/dist/cjs/hooks/use-editor-change.js +12 -14
- package/dist/cjs/hooks/use-editor-submit.d.ts +4 -2
- package/dist/cjs/hooks/use-editor-submit.d.ts.map +1 -1
- package/dist/cjs/hooks/use-editor-submit.js +5 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/api/entry-selections.d.ts +85 -0
- package/dist/esm/api/entry-selections.d.ts.map +1 -0
- package/dist/esm/api/entry-selections.js +88 -0
- package/dist/esm/atoms/entry-selections.atom.d.ts +11 -0
- package/dist/esm/atoms/entry-selections.atom.d.ts.map +1 -0
- package/dist/esm/atoms/entry-selections.atom.js +8 -0
- package/dist/esm/components/canvas-grid/index.d.ts.map +1 -1
- package/dist/esm/components/canvas-grid/index.js +160 -41
- package/dist/esm/hooks/use-editable.d.ts +3 -2
- package/dist/esm/hooks/use-editable.d.ts.map +1 -1
- package/dist/esm/hooks/use-editor-change.d.ts +7 -3
- package/dist/esm/hooks/use-editor-change.d.ts.map +1 -1
- package/dist/esm/hooks/use-editor-change.js +10 -12
- package/dist/esm/hooks/use-editor-submit.d.ts +4 -2
- package/dist/esm/hooks/use-editor-submit.d.ts.map +1 -1
- package/dist/esm/hooks/use-editor-submit.js +5 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { SelectionArea } from "@rowsncolumns/grid";
|
|
2
|
+
import type { SelectionAttributes } from "../components/canvas-grid/typings";
|
|
3
|
+
/**
|
|
4
|
+
* A range picked for a formula (pointer or arrow keys) lives in the sheet's
|
|
5
|
+
* own selection until the entry ends: appended after it, or in its place (a
|
|
6
|
+
* heading click, Shift+Arrow as the first pick, a pick that replaces a typed
|
|
7
|
+
* reference, a table's edge). The entry itself acts on what the sheet has
|
|
8
|
+
* selected WITHOUT those ranges: the commit key moves the active cell inside
|
|
9
|
+
* it, Ctrl+Enter fills it, and the sheet gets it back when the entry ends.
|
|
10
|
+
*
|
|
11
|
+
* The host owns the selection. So what is kept here is only ever what the
|
|
12
|
+
* host last gave the grid for a sheet, with the entry's own picks taken out.
|
|
13
|
+
* A selection the host sets while the entry is open (a collaborator's row or
|
|
14
|
+
* column edit moves it) replaces what was kept: nothing the entry writes may
|
|
15
|
+
* land outside what the host has selected now.
|
|
16
|
+
*/
|
|
17
|
+
type Selections = SelectionArea<SelectionAttributes>[];
|
|
18
|
+
/** What one sheet has selected, as far as the open cell entry is concerned. */
|
|
19
|
+
export type EntrySheetSelections = {
|
|
20
|
+
/** What the host last gave the grid for the sheet, without the entry's picks. */
|
|
21
|
+
own: Selections;
|
|
22
|
+
/**
|
|
23
|
+
* The sheet's selection as a gesture on the grid last wrote it for the
|
|
24
|
+
* entry, picked ranges included. Absent while nothing is picked on the
|
|
25
|
+
* sheet.
|
|
26
|
+
*/
|
|
27
|
+
written?: Selections;
|
|
28
|
+
/** How many of `written`'s leading selections are the sheet's own; the rest are picks. */
|
|
29
|
+
ownCount: number;
|
|
30
|
+
/** The selection the host last handed the grid for the sheet. */
|
|
31
|
+
seen: Selections;
|
|
32
|
+
};
|
|
33
|
+
export type EntryCell = {
|
|
34
|
+
sheetId: number;
|
|
35
|
+
rowIndex: number;
|
|
36
|
+
columnIndex: number;
|
|
37
|
+
};
|
|
38
|
+
export type EntrySelections = {
|
|
39
|
+
/** The cell the entry is typed in: another cell is another entry. */
|
|
40
|
+
cell: EntryCell;
|
|
41
|
+
sheets: ReadonlyMap<number, EntrySheetSelections>;
|
|
42
|
+
};
|
|
43
|
+
export declare const isSameEntryCell: (a: EntryCell | undefined, b: EntryCell | undefined) => boolean;
|
|
44
|
+
/** How many leading selections of `a` and `b` cover the same ranges. */
|
|
45
|
+
export declare const leadingSameRanges: (a: Selections, b: Selections) => number;
|
|
46
|
+
/**
|
|
47
|
+
* Whether two selections cover the same ranges in the same order. A host may
|
|
48
|
+
* hand back other objects than the grid wrote, or a new array on every render,
|
|
49
|
+
* so identity says nothing about who chose a selection.
|
|
50
|
+
*/
|
|
51
|
+
export declare const sameRanges: (a: Selections, b: Selections) => boolean;
|
|
52
|
+
/** A sheet nothing is picked on, holding what the host gave for it. */
|
|
53
|
+
export declare const entrySheetSelections: (own: Selections, seen?: Selections) => EntrySheetSelections;
|
|
54
|
+
/**
|
|
55
|
+
* A gesture on the grid wrote `next` for the sheet while the entry takes
|
|
56
|
+
* picks. `current` is what the host has for the sheet now; it is what the
|
|
57
|
+
* sheet's own selection is when this is its first pick.
|
|
58
|
+
*
|
|
59
|
+
* The sheet's own selections are the leading ones a pick left as they were.
|
|
60
|
+
* An appended pick leaves them all; a pick that takes the selection's place
|
|
61
|
+
* leaves none, and from then on none of what is written is the sheet's own.
|
|
62
|
+
*/
|
|
63
|
+
export declare const afterPick: (sheet: EntrySheetSelections | undefined, current: Selections, next: Selections) => EntrySheetSelections;
|
|
64
|
+
/**
|
|
65
|
+
* The host handed the grid `given` for the sheet. Returns the same object when
|
|
66
|
+
* it is nothing new.
|
|
67
|
+
*
|
|
68
|
+
* It is the host's own choice only when it is neither what the grid last
|
|
69
|
+
* wrote nor what the host had handed over before: a host that applies a write
|
|
70
|
+
* a tick later, or builds a new array on every render, shows the old selection
|
|
71
|
+
* once more before the grid's write comes back.
|
|
72
|
+
*
|
|
73
|
+
* The host's choice replaces what was kept. When it has as many selections as
|
|
74
|
+
* the grid wrote, they are the same ones moved (a row or a column inserted or
|
|
75
|
+
* deleted above them), so the sheet's own are still the leading ones and the
|
|
76
|
+
* picks the rest. Otherwise the host chose something else altogether, and the
|
|
77
|
+
* sheet has that selected with nothing picked on it.
|
|
78
|
+
*/
|
|
79
|
+
export declare const afterHostGave: (sheet: EntrySheetSelections, given: Selections) => EntrySheetSelections;
|
|
80
|
+
/** Whether a range picked for the entry is in any sheet's selection. */
|
|
81
|
+
export declare const hasEntryPicks: (state: EntrySelections) => boolean;
|
|
82
|
+
/** The sheet once its picks are out of its selection again. */
|
|
83
|
+
export declare const afterPutBack: (sheet: EntrySheetSelections) => EntrySheetSelections;
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=entry-selections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-selections.d.ts","sourceRoot":"","sources":["../../../api/entry-selections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAE7E;;;;;;;;;;;;;GAaG;AAEH,KAAK,UAAU,GAAG,aAAa,CAAC,mBAAmB,CAAC,EAAE,CAAC;AAEvD,+EAA+E;AAC/E,MAAM,MAAM,oBAAoB,GAAG;IACjC,iFAAiF;IACjF,GAAG,EAAE,UAAU,CAAC;IAChB;;;;OAIG;IACH,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB,0FAA0F;IAC1F,QAAQ,EAAE,MAAM,CAAC;IACjB,iEAAiE;IACjE,IAAI,EAAE,UAAU,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,qEAAqE;IACrE,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;CACnD,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,GAAG,SAAS,GAAG,SAAS,EACxB,GAAG,SAAS,GAAG,SAAS,KACvB,OAK8B,CAAC;AAWlC,wEAAwE;AACxE,eAAO,MAAM,iBAAiB,GAAI,GAAG,UAAU,EAAE,GAAG,UAAU,KAAG,MAUhE,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,GAAG,UAAU,EAAE,GAAG,UAAU,KAAG,OACkB,CAAC;AAE7E,uEAAuE;AACvE,eAAO,MAAM,oBAAoB,GAC/B,KAAK,UAAU,EACf,OAAM,UAAgB,KACrB,oBAA6D,CAAC;AAEjE;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,GACpB,OAAO,oBAAoB,GAAG,SAAS,EACvC,SAAS,UAAU,EACnB,MAAM,UAAU,KACf,oBAWF,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,GACxB,OAAO,oBAAoB,EAC3B,OAAO,UAAU,KAChB,oBAgBF,CAAC;AAEF,wEAAwE;AACxE,eAAO,MAAM,aAAa,GAAI,OAAO,eAAe,KAAG,OAOtD,CAAC;AAEF,+DAA+D;AAC/D,eAAO,MAAM,YAAY,GACvB,OAAO,oBAAoB,KAC1B,oBAAmE,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.afterPutBack = exports.hasEntryPicks = exports.afterHostGave = exports.afterPick = exports.entrySheetSelections = exports.sameRanges = exports.leadingSameRanges = exports.isSameEntryCell = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var isSameEntryCell = function (a, b) {
|
|
6
|
+
return a !== undefined &&
|
|
7
|
+
b !== undefined &&
|
|
8
|
+
a.sheetId === b.sheetId &&
|
|
9
|
+
a.rowIndex === b.rowIndex &&
|
|
10
|
+
a.columnIndex === b.columnIndex;
|
|
11
|
+
};
|
|
12
|
+
exports.isSameEntryCell = isSameEntryCell;
|
|
13
|
+
var isSameRange = function (a, b) {
|
|
14
|
+
return a.range.startRowIndex === b.range.startRowIndex &&
|
|
15
|
+
a.range.endRowIndex === b.range.endRowIndex &&
|
|
16
|
+
a.range.startColumnIndex === b.range.startColumnIndex &&
|
|
17
|
+
a.range.endColumnIndex === b.range.endColumnIndex;
|
|
18
|
+
};
|
|
19
|
+
/** How many leading selections of `a` and `b` cover the same ranges. */
|
|
20
|
+
var leadingSameRanges = function (a, b) {
|
|
21
|
+
var count = 0;
|
|
22
|
+
while (count < a.length &&
|
|
23
|
+
count < b.length &&
|
|
24
|
+
isSameRange(a[count], b[count])) {
|
|
25
|
+
count++;
|
|
26
|
+
}
|
|
27
|
+
return count;
|
|
28
|
+
};
|
|
29
|
+
exports.leadingSameRanges = leadingSameRanges;
|
|
30
|
+
/**
|
|
31
|
+
* Whether two selections cover the same ranges in the same order. A host may
|
|
32
|
+
* hand back other objects than the grid wrote, or a new array on every render,
|
|
33
|
+
* so identity says nothing about who chose a selection.
|
|
34
|
+
*/
|
|
35
|
+
var sameRanges = function (a, b) {
|
|
36
|
+
return a === b || (a.length === b.length && (0, exports.leadingSameRanges)(a, b) === a.length);
|
|
37
|
+
};
|
|
38
|
+
exports.sameRanges = sameRanges;
|
|
39
|
+
/** A sheet nothing is picked on, holding what the host gave for it. */
|
|
40
|
+
var entrySheetSelections = function (own, seen) {
|
|
41
|
+
if (seen === void 0) { seen = own; }
|
|
42
|
+
return ({ own: own, ownCount: own.length, seen: seen });
|
|
43
|
+
};
|
|
44
|
+
exports.entrySheetSelections = entrySheetSelections;
|
|
45
|
+
/**
|
|
46
|
+
* A gesture on the grid wrote `next` for the sheet while the entry takes
|
|
47
|
+
* picks. `current` is what the host has for the sheet now; it is what the
|
|
48
|
+
* sheet's own selection is when this is its first pick.
|
|
49
|
+
*
|
|
50
|
+
* The sheet's own selections are the leading ones a pick left as they were.
|
|
51
|
+
* An appended pick leaves them all; a pick that takes the selection's place
|
|
52
|
+
* leaves none, and from then on none of what is written is the sheet's own.
|
|
53
|
+
*/
|
|
54
|
+
var afterPick = function (sheet, current, next) {
|
|
55
|
+
var _a;
|
|
56
|
+
var known = sheet !== null && sheet !== void 0 ? sheet : (0, exports.entrySheetSelections)(current);
|
|
57
|
+
return {
|
|
58
|
+
own: known.own,
|
|
59
|
+
written: next,
|
|
60
|
+
ownCount: Math.min(known.ownCount, (0, exports.leadingSameRanges)((_a = known.written) !== null && _a !== void 0 ? _a : known.own, next)),
|
|
61
|
+
seen: known.seen,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
exports.afterPick = afterPick;
|
|
65
|
+
/**
|
|
66
|
+
* The host handed the grid `given` for the sheet. Returns the same object when
|
|
67
|
+
* it is nothing new.
|
|
68
|
+
*
|
|
69
|
+
* It is the host's own choice only when it is neither what the grid last
|
|
70
|
+
* wrote nor what the host had handed over before: a host that applies a write
|
|
71
|
+
* a tick later, or builds a new array on every render, shows the old selection
|
|
72
|
+
* once more before the grid's write comes back.
|
|
73
|
+
*
|
|
74
|
+
* The host's choice replaces what was kept. When it has as many selections as
|
|
75
|
+
* the grid wrote, they are the same ones moved (a row or a column inserted or
|
|
76
|
+
* deleted above them), so the sheet's own are still the leading ones and the
|
|
77
|
+
* picks the rest. Otherwise the host chose something else altogether, and the
|
|
78
|
+
* sheet has that selected with nothing picked on it.
|
|
79
|
+
*/
|
|
80
|
+
var afterHostGave = function (sheet, given) {
|
|
81
|
+
var _a;
|
|
82
|
+
if ((0, exports.sameRanges)(given, sheet.seen)) {
|
|
83
|
+
return sheet;
|
|
84
|
+
}
|
|
85
|
+
if ((0, exports.sameRanges)(given, (_a = sheet.written) !== null && _a !== void 0 ? _a : sheet.own)) {
|
|
86
|
+
return tslib_1.__assign(tslib_1.__assign({}, sheet), { seen: given });
|
|
87
|
+
}
|
|
88
|
+
if (sheet.written && given.length === sheet.written.length) {
|
|
89
|
+
return {
|
|
90
|
+
own: given.slice(0, sheet.ownCount),
|
|
91
|
+
written: given,
|
|
92
|
+
ownCount: sheet.ownCount,
|
|
93
|
+
seen: given,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
return (0, exports.entrySheetSelections)(given);
|
|
97
|
+
};
|
|
98
|
+
exports.afterHostGave = afterHostGave;
|
|
99
|
+
/** Whether a range picked for the entry is in any sheet's selection. */
|
|
100
|
+
var hasEntryPicks = function (state) {
|
|
101
|
+
var e_1, _a;
|
|
102
|
+
try {
|
|
103
|
+
for (var _b = tslib_1.__values(state.sheets.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
104
|
+
var sheet = _c.value;
|
|
105
|
+
if (sheet.written) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
111
|
+
finally {
|
|
112
|
+
try {
|
|
113
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
114
|
+
}
|
|
115
|
+
finally { if (e_1) throw e_1.error; }
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
};
|
|
119
|
+
exports.hasEntryPicks = hasEntryPicks;
|
|
120
|
+
/** The sheet once its picks are out of its selection again. */
|
|
121
|
+
var afterPutBack = function (sheet) { return (0, exports.entrySheetSelections)(sheet.own, sheet.seen); };
|
|
122
|
+
exports.afterPutBack = afterPutBack;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EntrySelections } from "../api/entry-selections";
|
|
2
|
+
/**
|
|
3
|
+
* What each sheet has selected, as far as the cell entry now open is
|
|
4
|
+
* concerned (`api/entry-selections.ts`). It lives beside the editing cell so
|
|
5
|
+
* that it outlives a grid that remounts in the middle of an entry, as the
|
|
6
|
+
* editing cell does. Not part of the package's exports.
|
|
7
|
+
*/
|
|
8
|
+
export declare const entrySelectionsAtom: import("jotai").PrimitiveAtom<EntrySelections | undefined> & {
|
|
9
|
+
init: EntrySelections | undefined;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=entry-selections.atom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-selections.atom.d.ts","sourceRoot":"","sources":["../../../atoms/entry-selections.atom.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;;CAA+C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.entrySelectionsAtom = void 0;
|
|
4
|
+
var jotai_1 = require("jotai");
|
|
5
|
+
/**
|
|
6
|
+
* What each sheet has selected, as far as the cell entry now open is
|
|
7
|
+
* concerned (`api/entry-selections.ts`). It lives beside the editing cell so
|
|
8
|
+
* that it outlives a grid that remounts in the middle of an entry, as the
|
|
9
|
+
* editing cell does. Not part of the package's exports.
|
|
10
|
+
*/
|
|
11
|
+
exports.entrySelectionsAtom = (0, jotai_1.atom)(undefined);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/canvas-grid/index.tsx"],"names":[],"mappings":"AAqEA,OAAO,KASN,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/canvas-grid/index.tsx"],"names":[],"mappings":"AAqEA,OAAO,KASN,MAAM,OAAO,CAAC;AAmSf,OAAO,KAAK,EAGV,QAAQ,EAcT,MAAM,aAAa,CAAC;AA0DrB,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EAEhB,MAAM,WAAW,CAAC;AAm8QnB,eAAO,MAAM,UAAU,EAA4C,CACjE,CAAC,SAAS,QAAQ,CAAC,GAAG,CAAC,EAEvB,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GACvB,wBAAwB,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;CAAE,KAChE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC"}
|