foldkit-data-grid 0.3.2 → 0.5.0

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 (62) hide show
  1. package/README.md +10 -3
  2. package/dist/clipboard.d.ts +44 -0
  3. package/dist/clipboard.d.ts.map +1 -0
  4. package/dist/clipboard.js +109 -0
  5. package/dist/clipboard.js.map +1 -0
  6. package/dist/columnState.d.ts +53 -0
  7. package/dist/columnState.d.ts.map +1 -0
  8. package/dist/columnState.js +201 -0
  9. package/dist/columnState.js.map +1 -0
  10. package/dist/{rows-D8siEVqF.d.mts → columns.d.ts} +15 -81
  11. package/dist/columns.d.ts.map +1 -0
  12. package/dist/columns.js +73 -0
  13. package/dist/columns.js.map +1 -0
  14. package/dist/{crud.d.mts → crud.d.ts} +3 -2
  15. package/dist/{crud.d.mts.map → crud.d.ts.map} +1 -1
  16. package/dist/{crud.mjs → crud.js} +3 -2
  17. package/dist/crud.js.map +1 -0
  18. package/dist/fill.d.ts +49 -0
  19. package/dist/fill.d.ts.map +1 -0
  20. package/dist/fill.js +113 -0
  21. package/dist/fill.js.map +1 -0
  22. package/dist/focus.d.ts +119 -0
  23. package/dist/focus.d.ts.map +1 -0
  24. package/dist/focus.js +150 -0
  25. package/dist/focus.js.map +1 -0
  26. package/dist/{index.d.mts → grid.d.ts} +31 -569
  27. package/dist/grid.d.ts.map +1 -0
  28. package/dist/grid.js +986 -0
  29. package/dist/grid.js.map +1 -0
  30. package/dist/index.d.ts +13 -0
  31. package/dist/index.js +13 -0
  32. package/dist/layout.d.ts +20 -0
  33. package/dist/layout.d.ts.map +1 -0
  34. package/dist/layout.js +27 -0
  35. package/dist/layout.js.map +1 -0
  36. package/dist/projection.d.ts +87 -0
  37. package/dist/projection.d.ts.map +1 -0
  38. package/dist/projection.js +102 -0
  39. package/dist/projection.js.map +1 -0
  40. package/dist/rows.d.ts +70 -0
  41. package/dist/rows.d.ts.map +1 -0
  42. package/dist/{rows-Dy1HPpGX.mjs → rows.js} +3 -71
  43. package/dist/rows.js.map +1 -0
  44. package/dist/selection.d.ts +65 -0
  45. package/dist/selection.d.ts.map +1 -0
  46. package/dist/selection.js +137 -0
  47. package/dist/selection.js.map +1 -0
  48. package/dist/viewport.d.ts +74 -0
  49. package/dist/viewport.d.ts.map +1 -0
  50. package/dist/viewport.js +123 -0
  51. package/dist/viewport.js.map +1 -0
  52. package/dist/virtual.d.ts +73 -0
  53. package/dist/virtual.d.ts.map +1 -0
  54. package/dist/virtual.js +112 -0
  55. package/dist/virtual.js.map +1 -0
  56. package/package.json +16 -16
  57. package/dist/crud.mjs.map +0 -1
  58. package/dist/index.d.mts.map +0 -1
  59. package/dist/index.mjs +0 -1982
  60. package/dist/index.mjs.map +0 -1
  61. package/dist/rows-D8siEVqF.d.mts.map +0 -1
  62. package/dist/rows-Dy1HPpGX.mjs.map +0 -1
package/README.md CHANGED
@@ -239,9 +239,16 @@ Grid.Message.Moved({
239
239
  - **`ColumnResized`**, **`ColumnHidden`**, **`ColumnShown`** and
240
240
  **`ColumnMoved`** change the column state (below).
241
241
  - **`ResizeStarted`**, **`ResizeMoved`** and **`ResizeEnded`** are a pointer
242
- drag on a resize handle. The grid records the width the drag began at, so
243
- each move is measured from there, not summed; a cancelled drag puts the
244
- width back. A column that does not resize starts no drag.
242
+ drag on a resize handle. `ResizeStarted` names the column by its header's
243
+ DOM id (`GridFocus.headerId`), since it comes from the page: an id that is
244
+ not a resizable column of this grid starts nothing. The grid records the
245
+ width the drag began at, so each move is measured from there, not summed;
246
+ a cancelled drag puts the width back.
247
+ - **`MountStarted`** changes nothing: the view's Mounts send it when they
248
+ start (its pointer listeners, and what holds focus in an open editor,
249
+ choice list or column menu), so a Scene test resolves them with what the
250
+ runtime sends (`foldkit-mixins-data-grid`'s `resolveMounts` and
251
+ `resolveOpened`).
245
252
 
246
253
  The Model is `{ focus, viewport, columns, resizing }` and encodes to plain
247
254
  data.
@@ -0,0 +1,44 @@
1
+ import { CellAddress, CellBox, GridProjection } from "./projection.js";
2
+ /** One cell's text in a paste, by identity: what the grid hands the application. */
3
+ export interface CellText<Id extends string> {
4
+ readonly row: string;
5
+ readonly column: Id;
6
+ readonly text: string;
7
+ }
8
+ /** A pasted cell, with the text it showed before, so an unchanged one is no edit. */
9
+ export interface PastedCell<Id extends string> extends CellText<Id> {
10
+ readonly from: string;
11
+ }
12
+ /** Rows of cells as tab-separated text, the form spreadsheets copy and paste. */
13
+ declare const toTsv: (rows: ReadonlyArray<ReadonlyArray<string>>) => string;
14
+ /**
15
+ * Tab-separated text as rows of cells. Quoted cells may hold tabs, line
16
+ * breaks and doubled quotes; `\r\n` and `\r` end a row as `\n` does; the line
17
+ * break a spreadsheet adds after the last row makes no empty row.
18
+ */
19
+ declare const parseTsv: (text: string) => ReadonlyArray<ReadonlyArray<string>>;
20
+ /**
21
+ * The text of the cells a box covers, row by row in the projection's order
22
+ * and column by column in display order. A row counted but not loaded copies
23
+ * as empty cells, so the shape is the box's.
24
+ */
25
+ declare const copy: <Row, Id extends string>(projection: GridProjection<Row, Id>, box: CellBox<Id>, textOf: (address: CellAddress<Id>) => string) => string;
26
+ /**
27
+ * Where pasted cells land: the matrix laid from `anchor` across rows in the
28
+ * projection's order and columns in display order. Cells past the grid's
29
+ * edges are dropped, as are those landing on a column that does not edit or
30
+ * a row not loaded; the rest keep their place, each with `from`, the text
31
+ * the cell showed (the text an edit of it would begin from).
32
+ */
33
+ declare const pasteAt: <Row, Id extends string>(projection: GridProjection<Row, Id>, anchor: CellAddress<Id>, matrix: ReadonlyArray<ReadonlyArray<string>>, cells: {
34
+ readonly editable: (column: Id) => boolean;
35
+ readonly from: (address: CellAddress<Id>) => string;
36
+ }) => ReadonlyArray<PastedCell<Id>>;
37
+ export declare const Clipboard: {
38
+ toTsv: typeof toTsv;
39
+ parseTsv: typeof parseTsv;
40
+ copy: typeof copy;
41
+ pasteAt: typeof pasteAt;
42
+ };
43
+ export {};
44
+ //# sourceMappingURL=clipboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clipboard.d.ts","names":[],"sources":["../src/clipboard.ts"],"mappings":";;iBAIiB,SAAS;WACf;WACA,QAAQ;WACR;;;iBAIM,WAAW,2BAA2B,SAAS;WACrD;;;cAWL,QAAK,MAAU,cAAc;;;;;;cAQ7B,WAAQ,iBAAmB,cAAc;;;;;;cA8CzC,OAAQ,KAAK,mBAAiB,YACtB,eAAe,KAAK,KAAG,KAC9B,QAAQ,KAAG,SACP,SAAS,YAAY;;;;;;;;cAqB1B,UAAW,KAAK,mBAAiB,YACzB,eAAe,KAAK,KAAG,QAC3B,YAAY,KAAG,QACf,cAAc,wBAAsB;WAEjC,WAAW,QAAQ;WACnB,OAAO,SAAS,YAAY;MAEtC,cAAc,WAAW;qBAoBf"}
@@ -0,0 +1,109 @@
1
+ import { Option } from "effect";
2
+ // src/clipboard.ts
3
+ const needsQuotes = /[\t\n\r"]/;
4
+ const quote = (cell) => needsQuotes.test(cell) ? `"${cell.replaceAll("\"", "\"\"")}"` : cell;
5
+ /** Rows of cells as tab-separated text, the form spreadsheets copy and paste. */
6
+ const toTsv = (rows) => rows.map((row) => row.map(quote).join(" ")).join("\n");
7
+ /**
8
+ * Tab-separated text as rows of cells. Quoted cells may hold tabs, line
9
+ * breaks and doubled quotes; `\r\n` and `\r` end a row as `\n` does; the line
10
+ * break a spreadsheet adds after the last row makes no empty row.
11
+ */
12
+ const parseTsv = (text) => {
13
+ const rows = [];
14
+ let row = [];
15
+ let cell = "";
16
+ let quoted = false;
17
+ let index = 0;
18
+ const endCell = () => {
19
+ row.push(cell);
20
+ cell = "";
21
+ };
22
+ const endRow = () => {
23
+ endCell();
24
+ rows.push(row);
25
+ row = [];
26
+ };
27
+ while (index < text.length) {
28
+ const char = text[index];
29
+ if (quoted) {
30
+ if (char === "\"" && text[index + 1] === "\"") {
31
+ cell += "\"";
32
+ index += 2;
33
+ continue;
34
+ }
35
+ if (char === "\"") quoted = false;
36
+ else cell += char;
37
+ index += 1;
38
+ continue;
39
+ }
40
+ if (char === "\"" && cell === "") quoted = true;
41
+ else if (char === " ") endCell();
42
+ else if (char === "\r" || char === "\n") {
43
+ endRow();
44
+ if (char === "\r" && text[index + 1] === "\n") index += 1;
45
+ } else cell += char;
46
+ index += 1;
47
+ }
48
+ if (cell !== "" || row.length > 0) endRow();
49
+ return rows;
50
+ };
51
+ /**
52
+ * The text of the cells a box covers, row by row in the projection's order
53
+ * and column by column in display order. A row counted but not loaded copies
54
+ * as empty cells, so the shape is the box's.
55
+ */
56
+ const copy = (projection, box, textOf) => {
57
+ const rows = [];
58
+ for (let index = box.rows.start; index < box.rows.end; index++) {
59
+ const key = projection.rows.keyAt(index);
60
+ rows.push(box.columns.map((column) => Option.match(key, {
61
+ onNone: () => "",
62
+ onSome: (row) => textOf({
63
+ row,
64
+ column
65
+ })
66
+ })));
67
+ }
68
+ return toTsv(rows);
69
+ };
70
+ /**
71
+ * Where pasted cells land: the matrix laid from `anchor` across rows in the
72
+ * projection's order and columns in display order. Cells past the grid's
73
+ * edges are dropped, as are those landing on a column that does not edit or
74
+ * a row not loaded; the rest keep their place, each with `from`, the text
75
+ * the cell showed (the text an edit of it would begin from).
76
+ */
77
+ const pasteAt = (projection, anchor, matrix, cells) => Option.match(projection.positionOf(anchor), {
78
+ onNone: () => [],
79
+ onSome: (start) => {
80
+ const landed = [];
81
+ matrix.forEach((texts, down) => {
82
+ const key = projection.rows.keyAt(start.row + down);
83
+ if (Option.isNone(key)) return;
84
+ const row = key.value;
85
+ texts.forEach((text, across) => {
86
+ const column = projection.columns[start.column + across];
87
+ if (column !== void 0 && cells.editable(column)) landed.push({
88
+ row,
89
+ column,
90
+ text,
91
+ from: cells.from({
92
+ row,
93
+ column
94
+ })
95
+ });
96
+ });
97
+ });
98
+ return landed;
99
+ }
100
+ });
101
+ const Clipboard = {
102
+ toTsv,
103
+ parseTsv,
104
+ copy,
105
+ pasteAt
106
+ };
107
+ export { Clipboard };
108
+
109
+ //# sourceMappingURL=clipboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clipboard.js","names":[],"sources":["../src/clipboard.ts"],"sourcesContent":["import { Option } from 'effect'\nimport type { CellAddress, CellBox, GridProjection } from './projection.js'\n\n/** One cell's text in a paste, by identity: what the grid hands the application. */\nexport interface CellText<Id extends string> {\n readonly row: string\n readonly column: Id\n readonly text: string\n}\n\n/** A pasted cell, with the text it showed before, so an unchanged one is no edit. */\nexport interface PastedCell<Id extends string> extends CellText<Id> {\n readonly from: string\n}\n\n// A cell holding a tab, a line break or a quote is quoted, its quotes doubled,\n// as spreadsheets write and read tab-separated text.\nconst needsQuotes = /[\\t\\n\\r\"]/\n\nconst quote = (cell: string): string =>\n needsQuotes.test(cell) ? `\"${cell.replaceAll('\"', '\"\"')}\"` : cell\n\n/** Rows of cells as tab-separated text, the form spreadsheets copy and paste. */\nconst toTsv = (rows: ReadonlyArray<ReadonlyArray<string>>): string =>\n rows.map(row => row.map(quote).join('\\t')).join('\\n')\n\n/**\n * Tab-separated text as rows of cells. Quoted cells may hold tabs, line\n * breaks and doubled quotes; `\\r\\n` and `\\r` end a row as `\\n` does; the line\n * break a spreadsheet adds after the last row makes no empty row.\n */\nconst parseTsv = (text: string): ReadonlyArray<ReadonlyArray<string>> => {\n const rows: Array<Array<string>> = []\n let row: Array<string> = []\n let cell = ''\n let quoted = false\n let index = 0\n const endCell = () => {\n row.push(cell)\n cell = ''\n }\n const endRow = () => {\n endCell()\n rows.push(row)\n row = []\n }\n while (index < text.length) {\n const char = text[index]!\n if (quoted) {\n if (char === '\"' && text[index + 1] === '\"') {\n cell += '\"'\n index += 2\n continue\n }\n if (char === '\"') quoted = false\n else cell += char\n index += 1\n continue\n }\n if (char === '\"' && cell === '') quoted = true\n else if (char === '\\t') endCell()\n else if (char === '\\r' || char === '\\n') {\n endRow()\n if (char === '\\r' && text[index + 1] === '\\n') index += 1\n } else cell += char\n index += 1\n }\n // Text that ends in a line break has said all its rows.\n if (cell !== '' || row.length > 0) endRow()\n return rows\n}\n\n/**\n * The text of the cells a box covers, row by row in the projection's order\n * and column by column in display order. A row counted but not loaded copies\n * as empty cells, so the shape is the box's.\n */\nconst copy = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n box: CellBox<Id>,\n textOf: (address: CellAddress<Id>) => string,\n): string => {\n const rows: Array<ReadonlyArray<string>> = []\n for (let index = box.rows.start; index < box.rows.end; index++) {\n const key = projection.rows.keyAt(index)\n rows.push(\n box.columns.map(column =>\n Option.match(key, { onNone: () => '', onSome: row => textOf({ row, column }) }),\n ),\n )\n }\n return toTsv(rows)\n}\n\n/**\n * Where pasted cells land: the matrix laid from `anchor` across rows in the\n * projection's order and columns in display order. Cells past the grid's\n * edges are dropped, as are those landing on a column that does not edit or\n * a row not loaded; the rest keep their place, each with `from`, the text\n * the cell showed (the text an edit of it would begin from).\n */\nconst pasteAt = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n anchor: CellAddress<Id>,\n matrix: ReadonlyArray<ReadonlyArray<string>>,\n cells: {\n readonly editable: (column: Id) => boolean\n readonly from: (address: CellAddress<Id>) => string\n },\n): ReadonlyArray<PastedCell<Id>> =>\n Option.match(projection.positionOf(anchor), {\n onNone: () => [],\n onSome: start => {\n const landed: Array<PastedCell<Id>> = []\n matrix.forEach((texts, down) => {\n const key = projection.rows.keyAt(start.row + down)\n if (Option.isNone(key)) return\n const row = key.value\n texts.forEach((text, across) => {\n const column = projection.columns[start.column + across]\n if (column !== undefined && cells.editable(column)) {\n landed.push({ row, column, text, from: cells.from({ row, column }) })\n }\n })\n })\n return landed\n },\n })\n\nexport const Clipboard = { toTsv, parseTsv, copy, pasteAt }\n"],"mappings":";;AAiBA,MAAM,cAAc;AAEpB,MAAM,SAAS,SACb,YAAY,KAAK,IAAI,IAAI,IAAI,KAAK,WAAW,MAAK,MAAI,EAAE,KAAK;;AAG/D,MAAM,SAAS,SACb,KAAK,KAAI,QAAO,IAAI,IAAI,KAAK,CAAC,CAAC,KAAK,G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AAW,MAAM,GAAG;CAC1C,cAAc,CAAC;CACf,SAAQ,UAAS;EACf,MAAM,SAAgC,CAAC;EACvC,OAAO,SAAS,OAAO,SAAS;GAC9B,MAAM,MAAM,WAAW,KAAK,MAAM,MAAM,MAAM,IAAI;GAClD,IAAI,OAAO,OAAO,GAAG,GAAG;GACxB,MAAM,MAAM,IAAI;GAChB,MAAM,SAAS,MAAM,WAAW;IAC9B,MAAM,SAAS,WAAW,QAAQ,MAAM,SAAS;IACjD,IAAI,WAAW,KAAA,KAAa,MAAM,SAAS,MAAM,GAC/C,OAAO,KAAK;KAAE;KAAK;KAAQ;KAAM,MAAM,MAAM,KAAK;MAAE;MAAK;KAAO,CAAC;IAAE,CAAC;GAExE,CAAC;EACH,CAAC;EACD,OAAO;CACT;AACF,CAAC;AAEH,MAAa,YAAY;CAAE;CAAO;CAAU;CAAM;AAAQ"}
@@ -0,0 +1,53 @@
1
+ import { Schema } from "effect";
2
+ import { ColumnSpec, Columns } from "./columns.js";
3
+ import { ColumnLayout } from "./layout.js";
4
+ export type Region = 'start' | 'center' | 'end';
5
+ /**
6
+ * Where each column stands and how wide the resized ones are. Widths list only
7
+ * the columns resized; the rest take their spec's. The grid owns it, and it is
8
+ * plain data, so an application can save it and restore it.
9
+ */
10
+ export interface ColumnState<Id extends string> extends ColumnLayout<Id> {
11
+ readonly widths: ReadonlyArray<{
12
+ readonly column: Id;
13
+ readonly width: number;
14
+ }>;
15
+ }
16
+ /** What `restore` made of a saved state: the state, and the ids it had to drop. */
17
+ export interface Restored<Id extends string> {
18
+ readonly state: ColumnState<Id>;
19
+ /** Ids the saved state named that these columns do not define, or named twice. */
20
+ readonly dropped: ReadonlyArray<string>;
21
+ }
22
+ /**
23
+ * Column state for one grid's columns: its Schema, which decodes only these
24
+ * columns' ids, and the operations a grid's Messages run. Every operation
25
+ * returns the state it was given when it changes nothing, so a no-op draws
26
+ * nothing.
27
+ */
28
+ declare const make: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(columns: Columns<Row, Specs>) => {
29
+ Model: Schema.Struct<{
30
+ readonly start: Schema.$Array<Schema.Literals<readonly (keyof Specs & string)[]>>;
31
+ readonly center: Schema.$Array<Schema.Literals<readonly (keyof Specs & string)[]>>;
32
+ readonly end: Schema.$Array<Schema.Literals<readonly (keyof Specs & string)[]>>;
33
+ readonly hidden: Schema.$Array<Schema.Literals<readonly (keyof Specs & string)[]>>;
34
+ readonly widths: Schema.$Array<Schema.Struct<{
35
+ readonly column: Schema.Literals<readonly (keyof Specs & string)[]>;
36
+ readonly width: Schema.Number;
37
+ }>>;
38
+ }>;
39
+ initial: () => ColumnState<keyof Specs & string>;
40
+ widthOf: (state: ColumnState<keyof Specs & string>) => ((id: keyof Specs & string) => number);
41
+ regionOf: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string) => Region;
42
+ resize: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string, width: number) => ColumnState<keyof Specs & string>;
43
+ hide: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string) => ColumnState<keyof Specs & string>;
44
+ show: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string) => ColumnState<keyof Specs & string>;
45
+ move: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string, region: Region, index: number) => ColumnState<keyof Specs & string>;
46
+ dropAt: (state: ColumnState<keyof Specs & string>, id: keyof Specs & string, delta: number) => number;
47
+ restore: (saved: unknown) => Restored<keyof Specs & string>;
48
+ };
49
+ export declare const ColumnState: {
50
+ make: typeof make;
51
+ };
52
+ export {};
53
+ //# sourceMappingURL=columnState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"columnState.d.ts","names":[],"sources":["../src/columnState.ts"],"mappings":";;;YAIY;;;;;;iBASK,YAAY,2BAA2B,aAAa;WAC1D,QAAQ;aAAyB,QAAQ;aAAa;;;;iBAIhD,SAAS;WACf,OAAO,YAAY;;WAEnB,SAAS;;;;;;;;cAoBd,OAAQ,KAAK,cAAc,eAAe,WAAW,gBAAc,SAC9D,QAAQ,KAAK;;;;;;;;;;;;EAuBU,UAAA,OAAA,kBAAA,sBAAE,UAAE;EAKK,WAAA,OAAA,kBAAA,iBAAA,UAAA,mBAAA;EAII,SAAA,OAAA,kBAAA,iBAAA,UAAA,gBAAA,kBAAM,kBAAA;;;EAoCP,OAAA,OAAA,kBAAA,iBAAA,UAAA,gBAAA,QAAA,QAAM,kBAAe,kBAAA;EAgBpB,SAAA,OAAA,kBAAA,iBAAA,UAAA,gBAAA;EAmCrB,UAAA,mBAAU,eAAQ;;qBA+C/B"}
@@ -0,0 +1,201 @@
1
+ import { Option, Schema } from "effect";
2
+ import { Columns } from "./columns.js";
3
+ import { ColumnLayout } from "./layout.js";
4
+ // src/columnState.ts
5
+ const regions = [
6
+ "start",
7
+ "center",
8
+ "end"
9
+ ];
10
+ const Saved = Schema.Struct({
11
+ start: Schema.Array(Schema.String),
12
+ center: Schema.Array(Schema.String),
13
+ end: Schema.Array(Schema.String),
14
+ hidden: Schema.Array(Schema.String),
15
+ widths: Schema.Array(Schema.Struct({
16
+ column: Schema.String,
17
+ width: Schema.Number
18
+ }))
19
+ });
20
+ const without = (ids, id) => ids.filter((each) => each !== id);
21
+ /**
22
+ * Column state for one grid's columns: its Schema, which decodes only these
23
+ * columns' ids, and the operations a grid's Messages run. Every operation
24
+ * returns the state it was given when it changes nothing, so a no-op draws
25
+ * nothing.
26
+ */
27
+ const make = (columns) => {
28
+ const Ids = Schema.Literals(columns.ids);
29
+ const Model = Schema.Struct({
30
+ start: Schema.Array(Ids),
31
+ center: Schema.Array(Ids),
32
+ end: Schema.Array(Ids),
33
+ hidden: Schema.Array(Ids),
34
+ widths: Schema.Array(Schema.Struct({
35
+ column: Ids,
36
+ width: Schema.Number
37
+ }))
38
+ });
39
+ const spec = (id) => columns.byId[id];
40
+ const isColumn = (id) => Object.hasOwn(columns.byId, id);
41
+ const clampWidth = (id, width) => {
42
+ const { minWidth = Columns.minWidth, maxWidth = Number.POSITIVE_INFINITY } = spec(id);
43
+ return Math.min(Math.max(width, minWidth), maxWidth);
44
+ };
45
+ const initial = () => ({
46
+ ...ColumnLayout.initial(columns),
47
+ widths: []
48
+ });
49
+ /** The width each column is drawn at: its resize, else its spec's. Call once per state. */
50
+ const widthOf = (state) => {
51
+ const resized = new Map(state.widths.map((entry) => [entry.column, entry.width]));
52
+ return (id) => resized.get(id) ?? spec(id).width ?? Columns.defaultWidth;
53
+ };
54
+ const regionOf = (state, id) => regions.find((region) => state[region].includes(id)) ?? "center";
55
+ /** Resizes a resizable column, within its `minWidth` and `maxWidth`. */
56
+ const resize = (state, id, width) => {
57
+ if (spec(id).resizable === false || !Number.isFinite(width)) return state;
58
+ const clamped = clampWidth(id, width);
59
+ if (clamped === widthOf(state)(id)) return state;
60
+ return {
61
+ ...state,
62
+ widths: [...state.widths.filter((entry) => entry.column !== id), {
63
+ column: id,
64
+ width: clamped
65
+ }]
66
+ };
67
+ };
68
+ const visibleCount = (state) => {
69
+ const hidden = new Set(state.hidden);
70
+ return regions.reduce((count, region) => count + state[region].filter((id) => !hidden.has(id)).length, 0);
71
+ };
72
+ /** Hides a hideable column; the last one shown stays, so the grid keeps a cell to focus. */
73
+ const hide = (state, id) => {
74
+ if (spec(id).hideable === false || state.hidden.includes(id) || visibleCount(state) <= 1) return state;
75
+ return {
76
+ ...state,
77
+ hidden: [...state.hidden, id]
78
+ };
79
+ };
80
+ const show = (state, id) => state.hidden.includes(id) ? {
81
+ ...state,
82
+ hidden: without(state.hidden, id)
83
+ } : state;
84
+ /**
85
+ * Moves a column to `index` among the columns of `region`, counted with it
86
+ * removed: a reorder within its region, or a pin or an unpin across them.
87
+ */
88
+ const move = (state, id, region, index) => {
89
+ const from = regionOf(state, id);
90
+ const target = without(state[region], id);
91
+ const at = Math.min(Math.max(0, Math.trunc(index)), target.length);
92
+ if (from === region && state[region].indexOf(id) === at) return state;
93
+ const placed = [
94
+ ...target.slice(0, at),
95
+ id,
96
+ ...target.slice(at)
97
+ ];
98
+ return {
99
+ ...state,
100
+ [from]: without(state[from], id),
101
+ [region]: placed
102
+ };
103
+ };
104
+ /**
105
+ * Where a column dragged `delta` pixels toward its region's end lands, as
106
+ * the index `move` takes in that region: past the middle of each shown
107
+ * neighbour it crossed. A column that crosses none stays where it is, so
108
+ * hidden columns keep their places; so do a hidden column and a delta that
109
+ * is not a number.
110
+ */
111
+ const dropAt = (state, id, delta) => {
112
+ const order = state[regionOf(state, id)];
113
+ const here = order.indexOf(id);
114
+ const hidden = new Set(state.hidden);
115
+ if (hidden.has(id) || !Number.isFinite(delta)) return here;
116
+ const width = widthOf(state);
117
+ const shown = [];
118
+ let dragged = 0;
119
+ let before = 0;
120
+ let edge = 0;
121
+ for (const each of order) {
122
+ if (hidden.has(each)) continue;
123
+ const middle = edge + width(each) / 2;
124
+ if (each === id) {
125
+ dragged = middle + delta;
126
+ before = shown.length;
127
+ } else shown.push({
128
+ id: each,
129
+ middle
130
+ });
131
+ edge += width(each);
132
+ }
133
+ const passed = shown.filter((other) => other.middle <= dragged).length;
134
+ if (passed === before) return here;
135
+ const others = without(order, id);
136
+ return passed < shown.length ? others.indexOf(shown[passed].id) : others.indexOf(shown[passed - 1].id) + 1;
137
+ };
138
+ /**
139
+ * A saved state read back leniently: an id these columns no longer define,
140
+ * or one named twice, is dropped and listed; a column the save predates
141
+ * takes its initial place; a width is clamped to its column's limits.
142
+ * Input that is not a saved state at all is the initial state, with nothing
143
+ * dropped, since nothing was read.
144
+ */
145
+ const restore = (saved) => Option.match(Schema.decodeUnknownOption(Saved)(saved), {
146
+ onNone: () => ({
147
+ state: initial(),
148
+ dropped: []
149
+ }),
150
+ onSome: (value) => {
151
+ const dropped = [];
152
+ const saved = /* @__PURE__ */ new Set();
153
+ const keep = (ids) => ids.filter((id) => {
154
+ if (!isColumn(id) || saved.has(id)) {
155
+ dropped.push(id);
156
+ return false;
157
+ }
158
+ saved.add(id);
159
+ return true;
160
+ });
161
+ const placed = {
162
+ start: keep(value.start),
163
+ center: keep(value.center),
164
+ end: keep(value.end)
165
+ };
166
+ const fresh = initial();
167
+ for (const region of regions) for (const id of fresh[region]) if (!saved.has(id)) placed[region].push(id);
168
+ const hidden = new Set(fresh.hidden.filter((id) => !saved.has(id)));
169
+ for (const id of value.hidden) if (isColumn(id)) hidden.add(id);
170
+ const widths = /* @__PURE__ */ new Map();
171
+ for (const entry of value.widths) if (isColumn(entry.column) && Number.isFinite(entry.width)) widths.set(entry.column, clampWidth(entry.column, entry.width));
172
+ return {
173
+ state: {
174
+ ...placed,
175
+ hidden: [...hidden],
176
+ widths: [...widths].map(([column, width]) => ({
177
+ column,
178
+ width
179
+ }))
180
+ },
181
+ dropped
182
+ };
183
+ }
184
+ });
185
+ return {
186
+ Model,
187
+ initial,
188
+ widthOf,
189
+ regionOf,
190
+ resize,
191
+ hide,
192
+ show,
193
+ move,
194
+ dropAt,
195
+ restore
196
+ };
197
+ };
198
+ const ColumnState = { make };
199
+ export { ColumnState };
200
+
201
+ //# sourceMappingURL=columnState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"columnState.js","names":[],"sources":["../src/columnState.ts"],"sourcesContent":["import { Option, Schema } from 'effect'\nimport { Columns, type ColumnSpec } from './columns.js'\nimport { ColumnLayout } from './layout.js'\n\nexport type Region = 'start' | 'center' | 'end'\n\nconst regions: ReadonlyArray<Region> = ['start', 'center', 'end']\n\n/**\n * Where each column stands and how wide the resized ones are. Widths list only\n * the columns resized; the rest take their spec's. The grid owns it, and it is\n * plain data, so an application can save it and restore it.\n */\nexport interface ColumnState<Id extends string> extends ColumnLayout<Id> {\n readonly widths: ReadonlyArray<{ readonly column: Id; readonly width: number }>\n}\n\n/** What `restore` made of a saved state: the state, and the ids it had to drop. */\nexport interface Restored<Id extends string> {\n readonly state: ColumnState<Id>\n /** Ids the saved state named that these columns do not define, or named twice. */\n readonly dropped: ReadonlyArray<string>\n}\n\nconst Saved = Schema.Struct({\n start: Schema.Array(Schema.String),\n center: Schema.Array(Schema.String),\n end: Schema.Array(Schema.String),\n hidden: Schema.Array(Schema.String),\n widths: Schema.Array(Schema.Struct({ column: Schema.String, width: Schema.Number })),\n})\n\nconst without = <Id extends string>(ids: ReadonlyArray<Id>, id: Id): ReadonlyArray<Id> =>\n ids.filter(each => each !== id)\n\n/**\n * Column state for one grid's columns: its Schema, which decodes only these\n * columns' ids, and the operations a grid's Messages run. Every operation\n * returns the state it was given when it changes nothing, so a no-op draws\n * nothing.\n */\nconst make = <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(\n columns: Columns<Row, Specs>,\n) => {\n type Id = keyof Specs & string\n type State = ColumnState<Id>\n const Ids = Schema.Literals(columns.ids)\n const Model = Schema.Struct({\n start: Schema.Array(Ids),\n center: Schema.Array(Ids),\n end: Schema.Array(Ids),\n hidden: Schema.Array(Ids),\n widths: Schema.Array(Schema.Struct({ column: Ids, width: Schema.Number })),\n })\n\n const spec = (id: Id) => columns.byId[id]\n const isColumn = (id: string): id is Id => Object.hasOwn(columns.byId, id)\n const clampWidth = (id: Id, width: number): number => {\n const { minWidth = Columns.minWidth, maxWidth = Number.POSITIVE_INFINITY } = spec(id)\n return Math.min(Math.max(width, minWidth), maxWidth)\n }\n\n const initial = (): State => ({ ...ColumnLayout.initial(columns), widths: [] })\n\n /** The width each column is drawn at: its resize, else its spec's. Call once per state. */\n const widthOf = (state: State): ((id: Id) => number) => {\n const resized = new Map(state.widths.map(entry => [entry.column, entry.width]))\n return id => resized.get(id) ?? spec(id).width ?? Columns.defaultWidth\n }\n\n const regionOf = (state: State, id: Id): Region =>\n regions.find(region => state[region].includes(id)) ?? 'center'\n\n /** Resizes a resizable column, within its `minWidth` and `maxWidth`. */\n const resize = (state: State, id: Id, width: number): State => {\n if (spec(id).resizable === false || !Number.isFinite(width)) return state\n const clamped = clampWidth(id, width)\n if (clamped === widthOf(state)(id)) return state\n return {\n ...state,\n widths: [\n ...state.widths.filter(entry => entry.column !== id),\n { column: id, width: clamped },\n ],\n }\n }\n\n const visibleCount = (state: State): number => {\n const hidden = new Set(state.hidden)\n return regions.reduce(\n (count, region) => count + state[region].filter(id => !hidden.has(id)).length,\n 0,\n )\n }\n\n /** Hides a hideable column; the last one shown stays, so the grid keeps a cell to focus. */\n const hide = (state: State, id: Id): State => {\n if (spec(id).hideable === false || state.hidden.includes(id) || visibleCount(state) <= 1) {\n return state\n }\n return { ...state, hidden: [...state.hidden, id] }\n }\n\n const show = (state: State, id: Id): State =>\n state.hidden.includes(id) ? { ...state, hidden: without(state.hidden, id) } : state\n\n /**\n * Moves a column to `index` among the columns of `region`, counted with it\n * removed: a reorder within its region, or a pin or an unpin across them.\n */\n const move = (state: State, id: Id, region: Region, index: number): State => {\n const from = regionOf(state, id)\n const target = without(state[region], id)\n const at = Math.min(Math.max(0, Math.trunc(index)), target.length)\n if (from === region && state[region].indexOf(id) === at) return state\n const placed = [...target.slice(0, at), id, ...target.slice(at)]\n return { ...state, [from]: without(state[from], id), [region]: placed }\n }\n\n /**\n * Where a column dragged `delta` pixels toward its region's end lands, as\n * the index `move` takes in that region: past the middle of each shown\n * neighbour it crossed. A column that crosses none stays where it is, so\n * hidden columns keep their places; so do a hidden column and a delta that\n * is not a number.\n */\n const dropAt = (state: State, id: Id, delta: number): number => {\n const order = state[regionOf(state, id)]\n const here = order.indexOf(id)\n const hidden = new Set(state.hidden)\n if (hidden.has(id) || !Number.isFinite(delta)) return here\n const width = widthOf(state)\n const shown: Array<{ readonly id: Id; readonly middle: number }> = []\n let dragged = 0\n let before = 0\n let edge = 0\n for (const each of order) {\n if (hidden.has(each)) continue\n const middle = edge + width(each) / 2\n if (each === id) {\n dragged = middle + delta\n before = shown.length\n } else shown.push({ id: each, middle })\n edge += width(each)\n }\n // How many shown neighbours end up before it, in middle order.\n const passed = shown.filter(other => other.middle <= dragged).length\n if (passed === before) return here\n const others = without(order, id)\n return passed < shown.length\n ? others.indexOf(shown[passed]!.id)\n : others.indexOf(shown[passed - 1]!.id) + 1\n }\n\n /**\n * A saved state read back leniently: an id these columns no longer define,\n * or one named twice, is dropped and listed; a column the save predates\n * takes its initial place; a width is clamped to its column's limits.\n * Input that is not a saved state at all is the initial state, with nothing\n * dropped, since nothing was read.\n */\n const restore = (saved: unknown): Restored<Id> =>\n Option.match(Schema.decodeUnknownOption(Saved)(saved), {\n onNone: () => ({ state: initial(), dropped: [] }),\n onSome: value => {\n const dropped: Array<string> = []\n const saved = new Set<Id>()\n const keep = (ids: ReadonlyArray<string>): Array<Id> =>\n ids.filter((id): id is Id => {\n if (!isColumn(id) || saved.has(id)) {\n dropped.push(id)\n return false\n }\n saved.add(id)\n return true\n })\n const placed = {\n start: keep(value.start),\n center: keep(value.center),\n end: keep(value.end),\n }\n // A column the save predates takes its initial region and visibility.\n const fresh = initial()\n for (const region of regions) {\n for (const id of fresh[region]) if (!saved.has(id)) placed[region].push(id)\n }\n const hidden = new Set<Id>(fresh.hidden.filter(id => !saved.has(id)))\n for (const id of value.hidden) if (isColumn(id)) hidden.add(id)\n const widths = new Map<Id, number>()\n for (const entry of value.widths) {\n if (isColumn(entry.column) && Number.isFinite(entry.width)) {\n widths.set(entry.column, clampWidth(entry.column, entry.width))\n }\n }\n return {\n state: {\n ...placed,\n hidden: [...hidden],\n widths: [...widths].map(([column, width]) => ({ column, width })),\n },\n dropped,\n }\n },\n })\n\n return { Model, initial, widthOf, regionOf, resize, hide, show, move, dropAt, restore }\n}\n\nexport const ColumnState = { make }\n"],"mappings":";;;;AAMA,MAAM,UAAiC;CAAC;CAAS;CAAU;AAAK;AAkBhE,MAAM,QAAQ,OAAO,OAAO;CAC1B,OAAO,OAAO,MAAM,OAAO,MAAM;CACjC,QAAQ,OAAO,MAAM,OAAO,MAAM;CAClC,KAAK,OAAO,MAAM,OAAO,MAAM;CAC/B,QAAQ,OAAO,MAAM,OAAO,MAAM;CAClC,QAAQ,OAAO,MAAM,OAAO,OAAO;EAAE,QAAQ,OAAO;EAAQ,OAAO,OAAO;CAAO,CAAC,CAAC;AACrF,CAAC;AAED,MAAM,WAA8B,K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,OAAO;GACT,CAAC;GACH,MAAM,SAAS;IACb,OAAO,KAAK,MAAM,KAAK;IACvB,QAAQ,KAAK,MAAM,MAAM;IACzB,KAAK,KAAK,MAAM,GAAG;GACrB;GAEA,MAAM,QAAQ,QAAQ;GACtB,KAAK,MAAM,UAAU,SACnB,KAAK,MAAM,MAAM,MAAM,SAAS,IAAI,CAAC,MAAM,IAAI,EAAE,GAAG,OAAO,OAAO,CAAC,KAAK,EAAE;GAE5E,MAAM,SAAS,IAAI,IAAQ,MAAM,OAAO,QAAO,OAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;GACpE,KAAK,MAAM,MAAM,MAAM,QAAQ,IAAI,SAAS,EAAE,GAAG,OAAO,IAAI,EAAE;GAC9D,MAAM,yBAAS,IAAI,IAAgB;GACnC,KAAK,MAAM,SAAS,MAAM,QACxB,IAAI,SAAS,MAAM,MAAM,KAAK,OAAO,SAAS,MAAM,KAAK,GACvD,OAAO,IAAI,MAAM,QAAQ,WAAW,MAAM,QAAQ,MAAM,KAAK,CAAC;GAGlE,OAAO;IACL,OAAO;KACL,GAAG;KACH,QAAQ,CAAC,GAAG,MAAM;KAClB,QAAQ,CAAC,GAAG,MAAM,CAAC,CAAC,KAAK,CAAC,QAAQ,YAAY;MAAE;MAAQ;KAAM,EAAE;IAClE;IACA;GACF;EACF;CACF,CAAC;CAEH,OAAO;EAAE;EAAO;EAAS;EAAS;EAAU;EAAQ;EAAM;EAAM;EAAM;EAAQ;CAAQ;AACxF;AAEA,MAAa,cAAc,EAAE,KAAK"}
@@ -1,6 +1,6 @@
1
- import { Option, Schema } from "effect";
1
+ import { Schema } from "effect";
2
2
  /** What a column shows and where it starts out. Its id is its key in `Columns.define`. */
3
- interface ColumnSpec<Row, Value> {
3
+ export interface ColumnSpec<Row, Value> {
4
4
  readonly header: string;
5
5
  readonly value: (row: Row) => Value;
6
6
  /** The region the column starts in; `ColumnLayout.initial` reads it. */
@@ -25,7 +25,7 @@ interface ColumnSpec<Row, Value> {
25
25
  */
26
26
  readonly edit?: ColumnEdit<Row, unknown>;
27
27
  }
28
- interface ColumnEdit<Row, Value = string> {
28
+ export interface ColumnEdit<Row, Value = string> {
29
29
  /** The text an edit of a row's cell begins with. Default the value as a string. */
30
30
  readonly draft?: (row: Row) => string;
31
31
  /**
@@ -40,7 +40,7 @@ interface ColumnEdit<Row, Value = string> {
40
40
  * How a cell's edit is drawn, read from its column's schema: a choice of the
41
41
  * literals its text may be, a number typed, or text.
42
42
  */
43
- declare const CellEditor: import("foldkit/schema").TaggedUnion<{
43
+ export declare const CellEditor: import("foldkit/schema").TaggedUnion<{
44
44
  readonly Text: {};
45
45
  /** The schema decodes to a number: typed with a decimal keypad on touch. */
46
46
  readonly Number: {};
@@ -51,28 +51,30 @@ declare const CellEditor: import("foldkit/schema").TaggedUnion<{
51
51
  /** The schema decodes to a date: a native date field over the draft text. */
52
52
  readonly Date: {};
53
53
  }>;
54
- type CellEditor = typeof CellEditor.Type;
54
+ export type CellEditor = typeof CellEditor.Type;
55
+ /** A column's editor, from its schema; a column with none edits text. */
56
+ export declare const editorOf: (schema: Schema.Top | undefined) => CellEditor;
55
57
  /** The ids of the columns that edit. */
56
- type EditableId<Specs> = { [K in keyof Specs]: Specs[K] extends {
58
+ export type EditableId<Specs> = { [K in keyof Specs]: Specs[K] extends {
57
59
  readonly edit: object;
58
60
  } ? K : never; }[keyof Specs] & string;
59
61
  /** What an editable column's text decodes to: its schema's value, or the text. */
60
- type EditValue<Spec> = Spec extends {
62
+ export type EditValue<Spec> = Spec extends {
61
63
  readonly edit: {
62
64
  readonly schema: Schema.Codec<infer Value, string>;
63
65
  };
64
66
  } ? Value : string;
65
- interface Column<Row, Id extends string, Value> extends ColumnSpec<Row, Value> {
67
+ export interface Column<Row, Id extends string, Value> extends ColumnSpec<Row, Value> {
66
68
  readonly id: Id;
67
69
  }
68
70
  type ValueOf<Spec> = Spec extends ColumnSpec<never, infer Value> ? Value : never;
69
- type ColumnId<C> = C extends Columns<never, infer Specs> ? keyof Specs & string : never;
71
+ export type ColumnId<C> = C extends Columns<never, infer Specs> ? keyof Specs & string : never;
70
72
  /**
71
73
  * A grid's columns, keyed by stable id. Order, visibility and pinning live in
72
74
  * a `ColumnLayout`, so every reference to a column (focus, a selected range,
73
75
  * a saved width) names its id and survives a reorder.
74
76
  */
75
- interface Columns<Row, Specs extends Record<string, ColumnSpec<Row, unknown>>> {
77
+ export interface Columns<Row, Specs extends Record<string, ColumnSpec<Row, unknown>>> {
76
78
  /** In definition order: the order `ColumnLayout.initial` starts from. */
77
79
  readonly ids: ReadonlyArray<keyof Specs & string>;
78
80
  readonly byId: { readonly [Id in keyof Specs & string]: Column<Row, Id, ValueOf<Specs[Id]>>; };
@@ -82,7 +84,7 @@ interface Columns<Row, Specs extends Record<string, ColumnSpec<Row, unknown>>> {
82
84
  */
83
85
  readonly Specs?: Specs;
84
86
  }
85
- declare const Columns: {
87
+ export declare const Columns: {
86
88
  /** The width of a column that names none. */
87
89
  defaultWidth: number;
88
90
  /** The narrowest a column with no `minWidth` resizes to. */
@@ -96,73 +98,5 @@ declare const Columns: {
96
98
  */
97
99
  define: <Row>() => <Specs extends Record<string, ColumnSpec<Row, unknown>>>(specs: Specs) => NoInfer<Columns<Row, Specs>>;
98
100
  };
99
- /**
100
- * How many rows a grid can address. A local array, or a server that reports
101
- * its total, is `Known`; a cursor that has not reached its end is `Unknown`,
102
- * with the rows seen so far as a lower bound.
103
- */
104
- declare const RowCount: import("foldkit/schema").TaggedUnion<{
105
- /** Exactly `total` rows, loaded or not. */
106
- readonly Known: {
107
- total: Schema.Number;
108
- };
109
- /** At least `atLeast` rows; more may follow. */
110
- readonly Unknown: {
111
- atLeast: Schema.Number;
112
- };
113
- }>;
114
- type RowCount = typeof RowCount.Type;
115
- /**
116
- * Where the rows' source stands, for a view to say: `Loading` before any
117
- * answer, `Refreshing` while a newer one is on its way and the rows shown are
118
- * the last good ones, `Failed` with what went wrong. The grid holds no
119
- * loading state of its own; the source's owner (Remote, a store) says this.
120
- */
121
- declare const RowStatus: import("foldkit/schema").TaggedUnion<{
122
- readonly Ready: {};
123
- readonly Loading: {};
124
- readonly Refreshing: {};
125
- readonly Failed: {
126
- message: Schema.String;
127
- };
128
- }>;
129
- type RowStatus = typeof RowStatus.Type;
130
- /** The number of row indexes a grid may address: the total, or the lower bound. */
131
- declare const addressableRows: (value: {
132
- readonly _tag: "Known";
133
- readonly total: number;
134
- } | {
135
- readonly _tag: "Unknown";
136
- readonly atLeast: number;
137
- }) => number;
138
- /**
139
- * Logical row space: rows by index, each with a stable key, whatever stores
140
- * or fetches them. Indexes follow the order the application supplies, so a
141
- * sorted or filtered result is the application's, not the grid's. An index
142
- * that is in range may still have no row yet (a page not loaded), so every
143
- * lookup is an `Option`.
144
- */
145
- interface RowModel<Row> {
146
- readonly count: RowCount;
147
- rowAt(index: number): Option.Option<Row>;
148
- keyAt(index: number): Option.Option<string>;
149
- indexOf(key: string): Option.Option<number>;
150
- }
151
- declare const RowModel: {
152
- /**
153
- * Rows held in memory, in the order given. Throws when two rows share a
154
- * key, since focus and selection would then name two rows at once.
155
- */
156
- fromArray: <Row>(rows: ReadonlyArray<Row>, key: (row: Row) => string) => RowModel<Row>;
157
- /**
158
- * The rows with each one transformed as it is read: a local edit laid over
159
- * a row a server sent, say. `make` turns `input` into the per-row function,
160
- * once per `rows` and `input`, so a lookup it builds is built once; the
161
- * result is the same model while both are, and a new one when either
162
- * changes. Keys, count and order are `rows`' own, so `make`'s function must
163
- * keep each row's key.
164
- */
165
- map: <Row, Mapped, Input extends object>(rows: RowModel<Row>, input: Input, make: (input: Input) => (row: Row) => Mapped) => RowModel<Mapped>;
166
- };
167
- export { CellEditor as a, ColumnId as c, EditValue as d, EditableId as f, addressableRows as i, ColumnSpec as l, RowModel as n, Column as o, RowStatus as r, ColumnEdit as s, RowCount as t, Columns as u };
168
- //# sourceMappingURL=rows-D8siEVqF.d.mts.map
101
+ export {};
102
+ //# sourceMappingURL=columns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"columns.d.ts","names":[],"sources":["../src/columns.ts"],"mappings":";;iBAGiB,WAAW,KAAK;WACtB;WACA,QAAQ,KAAK,QAAQ;;WAErB;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;WAOA,OAAO,WAAW;;iBAGZ,WAAW,KAAK;;WAEtB,SAAS,KAAK;;;;;;;WAOd,SAAS,OAAO,MAAM;;;;;;qBAOpB,qCAAU;;;;;;IAKX,SAAO,OAAA,OAAA,OAAA;;;;;YAIP,oBAAoB,WAAW;;qBAsB9B,WAAQ,QAAY,OAAO,oBAAkB;;YAgB9C,WAAW,YACpB,WAAW,QAAQ,MAAM;WAAsB;IAAiB,mBAC3D;;YAII,UAAU,QAAQ;WACnB;aAAiB,QAAQ,OAAO,YAAY;;IAEnD;iBAGa,OAAO,KAAK,mBAAmB,eAAe,WAAW,KAAK;WACpE,IAAI;;KAGV,QAAQ,QAAQ,aAAa,wBAAwB,SAAS;YAEvD,SAAS,KAAK,UAAU,qBAAqB,eAAe;;;;;;iBAOvD,QAAQ,KAAK,cAAc,eAAe,WAAW;;WAE3D,KAAK,oBAAoB;WACzB,kBACG,YAAY,iBAAiB,OAAO,KAAK,IAAI,QAAQ,MAAM;;;;;WAM9D,QAAQ;;qBAON;;EAEX;;EAEA;;EAEA,SAAM;;;;;;EAMN,SACG,WACA,cAAc,eAAe,WAAW,gBAAc,OAC9C,UACN,QAAQ,QAAQ,KAAK"}