foldkit-data-grid 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +497 -2
- package/dist/crud.d.mts +19 -0
- package/dist/crud.d.mts.map +1 -0
- package/dist/crud.mjs +80 -0
- package/dist/crud.mjs.map +1 -0
- package/dist/index.d.mts +2228 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1949 -0
- package/dist/index.mjs.map +1 -0
- package/dist/rows-82I91peS.mjs +146 -0
- package/dist/rows-82I91peS.mjs.map +1 -0
- package/dist/rows-Dz9f6hWJ.d.mts +170 -0
- package/dist/rows-Dz9f6hWJ.d.mts.map +1 -0
- package/package.json +72 -3
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { Option, Schema } from "effect";
|
|
2
|
+
//#region src/columns.d.ts
|
|
3
|
+
/** What a column shows and where it starts out. Its id is its key in `Columns.define`. */
|
|
4
|
+
interface ColumnSpec<Row, Value> {
|
|
5
|
+
readonly header: string;
|
|
6
|
+
readonly value: (row: Row) => Value;
|
|
7
|
+
/** The region the column starts in; `ColumnLayout.initial` reads it. */
|
|
8
|
+
readonly pinned?: 'start' | 'end';
|
|
9
|
+
/** Whether the column starts hidden; `ColumnLayout.initial` reads it. */
|
|
10
|
+
readonly hidden?: boolean;
|
|
11
|
+
/** Its width in pixels until resized. Default `Columns.defaultWidth`. */
|
|
12
|
+
readonly width?: number;
|
|
13
|
+
/** The narrowest a resize makes it. Default `Columns.minWidth`. */
|
|
14
|
+
readonly minWidth?: number;
|
|
15
|
+
/** The widest a resize makes it. Default no limit. */
|
|
16
|
+
readonly maxWidth?: number;
|
|
17
|
+
/** Whether it can be resized. Default `true`. */
|
|
18
|
+
readonly resizable?: boolean;
|
|
19
|
+
/** Whether it can be hidden. Default `true`. */
|
|
20
|
+
readonly hideable?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Makes the column's cells editable as text. The grid holds the draft,
|
|
23
|
+
* commits it only when the column's schema decodes it, and reports the
|
|
24
|
+
* committed text as an `Edited` OutMessage; `matchEdit` reads its value
|
|
25
|
+
* back, and writing it is the application's.
|
|
26
|
+
*/
|
|
27
|
+
readonly edit?: ColumnEdit<Row, unknown>;
|
|
28
|
+
}
|
|
29
|
+
interface ColumnEdit<Row, Value = string> {
|
|
30
|
+
/** The text an edit of a row's cell begins with. Default the value as a string. */
|
|
31
|
+
readonly draft?: (row: Row) => string;
|
|
32
|
+
/**
|
|
33
|
+
* What the text means: from the text typed to the column's value. A draft
|
|
34
|
+
* is committed only when it decodes, and the failure's message is the
|
|
35
|
+
* cell's error, so a check's own `message` is what a person reads. Default
|
|
36
|
+
* any text, as itself.
|
|
37
|
+
*/
|
|
38
|
+
readonly schema?: Schema.Codec<Value, string>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* How a cell's edit is drawn, read from its column's schema: a choice of the
|
|
42
|
+
* literals its text may be, a number typed, or text.
|
|
43
|
+
*/
|
|
44
|
+
declare const CellEditor: import("foldkit/schema").TaggedUnion<{
|
|
45
|
+
readonly Text: {};
|
|
46
|
+
/** The schema decodes to a number: typed with a decimal keypad on touch. */
|
|
47
|
+
readonly Number: {};
|
|
48
|
+
/** The schema's text is one of these, offered in order. */
|
|
49
|
+
readonly Choice: {
|
|
50
|
+
readonly options: Schema.$Array<Schema.String>;
|
|
51
|
+
};
|
|
52
|
+
}>;
|
|
53
|
+
type CellEditor = typeof CellEditor.Type;
|
|
54
|
+
/** The ids of the columns that edit. */
|
|
55
|
+
type EditableId<Specs> = { [K in keyof Specs]: Specs[K] extends {
|
|
56
|
+
readonly edit: object;
|
|
57
|
+
} ? K : never; }[keyof Specs] & string;
|
|
58
|
+
/** What an editable column's text decodes to: its schema's value, or the text. */
|
|
59
|
+
type EditValue<Spec> = Spec extends {
|
|
60
|
+
readonly edit: {
|
|
61
|
+
readonly schema: Schema.Codec<infer Value, string>;
|
|
62
|
+
};
|
|
63
|
+
} ? Value : string;
|
|
64
|
+
interface Column<Row, Id extends string, Value> extends ColumnSpec<Row, Value> {
|
|
65
|
+
readonly id: Id;
|
|
66
|
+
}
|
|
67
|
+
type ValueOf<Spec> = Spec extends ColumnSpec<never, infer Value> ? Value : never;
|
|
68
|
+
type ColumnId<C> = C extends Columns<never, infer Specs> ? keyof Specs & string : never;
|
|
69
|
+
/**
|
|
70
|
+
* A grid's columns, keyed by stable id. Order, visibility and pinning live in
|
|
71
|
+
* a `ColumnLayout`, so every reference to a column (focus, a selected range,
|
|
72
|
+
* a saved width) names its id and survives a reorder.
|
|
73
|
+
*/
|
|
74
|
+
interface Columns<Row, Specs extends Record<string, ColumnSpec<Row, unknown>>> {
|
|
75
|
+
/** In definition order: the order `ColumnLayout.initial` starts from. */
|
|
76
|
+
readonly ids: ReadonlyArray<keyof Specs & string>;
|
|
77
|
+
readonly byId: { readonly [Id in keyof Specs & string]: Column<Row, Id, ValueOf<Specs[Id]>>; };
|
|
78
|
+
/**
|
|
79
|
+
* Type-only: the specs as written, so a grid made from these columns infers
|
|
80
|
+
* each one exactly, its edit's schema included. Never set.
|
|
81
|
+
*/
|
|
82
|
+
readonly Specs?: Specs;
|
|
83
|
+
}
|
|
84
|
+
declare const Columns: {
|
|
85
|
+
/** The width of a column that names none. */
|
|
86
|
+
defaultWidth: number;
|
|
87
|
+
/** The narrowest a column with no `minWidth` resizes to. */
|
|
88
|
+
minWidth: number;
|
|
89
|
+
/** A value as a cell shows it: nothing for `null` or `undefined`. */
|
|
90
|
+
textOf: (value: unknown) => string;
|
|
91
|
+
/**
|
|
92
|
+
* Declares a grid's columns over `Row`. Call it twice, once with the row
|
|
93
|
+
* type and once with the specs, so the ids and values are inferred:
|
|
94
|
+
* `Columns.define<Product>()({ sku: { header: 'SKU', value: p => p.sku } })`.
|
|
95
|
+
*/
|
|
96
|
+
define: <Row>() => <Specs extends Record<string, ColumnSpec<Row, unknown>>>(specs: Specs) => NoInfer<Columns<Row, Specs>>;
|
|
97
|
+
};
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/rows.d.ts
|
|
100
|
+
/**
|
|
101
|
+
* How many rows a grid can address. A local array, or a server that reports
|
|
102
|
+
* its total, is `Known`; a cursor that has not reached its end is `Unknown`,
|
|
103
|
+
* with the rows seen so far as a lower bound.
|
|
104
|
+
*/
|
|
105
|
+
declare const RowCount: import("foldkit/schema").TaggedUnion<{
|
|
106
|
+
/** Exactly `total` rows, loaded or not. */
|
|
107
|
+
readonly Known: {
|
|
108
|
+
readonly total: Schema.Number;
|
|
109
|
+
};
|
|
110
|
+
/** At least `atLeast` rows; more may follow. */
|
|
111
|
+
readonly Unknown: {
|
|
112
|
+
readonly atLeast: Schema.Number;
|
|
113
|
+
};
|
|
114
|
+
}>;
|
|
115
|
+
type RowCount = typeof RowCount.Type;
|
|
116
|
+
/**
|
|
117
|
+
* Where the rows' source stands, for a view to say: `Loading` before any
|
|
118
|
+
* answer, `Refreshing` while a newer one is on its way and the rows shown are
|
|
119
|
+
* the last good ones, `Failed` with what went wrong. The grid holds no
|
|
120
|
+
* loading state of its own; the source's owner (Remote, a store) says this.
|
|
121
|
+
*/
|
|
122
|
+
declare const RowStatus: import("foldkit/schema").TaggedUnion<{
|
|
123
|
+
readonly Ready: {};
|
|
124
|
+
readonly Loading: {};
|
|
125
|
+
readonly Refreshing: {};
|
|
126
|
+
readonly Failed: {
|
|
127
|
+
readonly message: Schema.String;
|
|
128
|
+
};
|
|
129
|
+
}>;
|
|
130
|
+
type RowStatus = typeof RowStatus.Type;
|
|
131
|
+
/** The number of row indexes a grid may address: the total, or the lower bound. */
|
|
132
|
+
declare const addressableRows: (value: {
|
|
133
|
+
readonly _tag: "Known";
|
|
134
|
+
readonly total: number;
|
|
135
|
+
} | {
|
|
136
|
+
readonly _tag: "Unknown";
|
|
137
|
+
readonly atLeast: number;
|
|
138
|
+
}) => number;
|
|
139
|
+
/**
|
|
140
|
+
* Logical row space: rows by index, each with a stable key, whatever stores
|
|
141
|
+
* or fetches them. Indexes follow the order the application supplies, so a
|
|
142
|
+
* sorted or filtered result is the application's, not the grid's. An index
|
|
143
|
+
* that is in range may still have no row yet (a page not loaded), so every
|
|
144
|
+
* lookup is an `Option`.
|
|
145
|
+
*/
|
|
146
|
+
interface RowModel<Row> {
|
|
147
|
+
readonly count: RowCount;
|
|
148
|
+
rowAt(index: number): Option.Option<Row>;
|
|
149
|
+
keyAt(index: number): Option.Option<string>;
|
|
150
|
+
indexOf(key: string): Option.Option<number>;
|
|
151
|
+
}
|
|
152
|
+
declare const RowModel: {
|
|
153
|
+
/**
|
|
154
|
+
* Rows held in memory, in the order given. Throws when two rows share a
|
|
155
|
+
* key, since focus and selection would then name two rows at once.
|
|
156
|
+
*/
|
|
157
|
+
fromArray: <Row>(rows: ReadonlyArray<Row>, key: (row: Row) => string) => RowModel<Row>;
|
|
158
|
+
/**
|
|
159
|
+
* The rows with each one transformed as it is read: a local edit laid over
|
|
160
|
+
* a row a server sent, say. `make` turns `input` into the per-row function,
|
|
161
|
+
* once per `rows` and `input`, so a lookup it builds is built once; the
|
|
162
|
+
* result is the same model while both are, and a new one when either
|
|
163
|
+
* changes. Keys, count and order are `rows`' own, so `make`'s function must
|
|
164
|
+
* keep each row's key.
|
|
165
|
+
*/
|
|
166
|
+
map: <Row, Mapped, Input extends object>(rows: RowModel<Row>, input: Input, make: (input: Input) => (row: Row) => Mapped) => RowModel<Mapped>;
|
|
167
|
+
};
|
|
168
|
+
//#endregion
|
|
169
|
+
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 };
|
|
170
|
+
//# sourceMappingURL=rows-Dz9f6hWJ.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rows-Dz9f6hWJ.d.mts","names":[],"sources":["../src/columns.ts","../src/rows.ts"],"mappings":";;;UAGiB,WAAW,KAAK;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,75 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "foldkit-data-grid",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A Foldkit-native data grid: the grid owns interaction state and geometry, the application owns the records.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"foldkit",
|
|
7
|
+
"data-grid",
|
|
8
|
+
"table",
|
|
9
|
+
"spreadsheet",
|
|
10
|
+
"typescript"
|
|
11
|
+
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Patrick Glenn <doeixd@gmail.com>",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/doeixd/foldkit-plus.git",
|
|
18
|
+
"directory": "packages/data-grid"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/doeixd/foldkit-plus/tree/main/packages/data-grid#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/doeixd/foldkit-plus/issues"
|
|
23
|
+
},
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"exports": {
|
|
29
|
+
"./crud": {
|
|
30
|
+
"foldkit-plus:source": "./src/crud.ts",
|
|
31
|
+
"types": "./dist/crud.d.mts",
|
|
32
|
+
"import": "./dist/crud.mjs"
|
|
33
|
+
},
|
|
34
|
+
".": {
|
|
35
|
+
"foldkit-plus:source": "./src/index.ts",
|
|
36
|
+
"types": "./dist/index.d.mts",
|
|
37
|
+
"import": "./dist/index.mjs"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"README.md",
|
|
43
|
+
"LICENSE"
|
|
44
|
+
],
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"foldkit-bundle": "0.5.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"effect": "^4.0.0",
|
|
50
|
+
"foldkit": "^0.165.0",
|
|
51
|
+
"foldkit-crud": "0.6.1",
|
|
52
|
+
"foldkit-remote": "0.13.0"
|
|
53
|
+
},
|
|
54
|
+
"peerDependenciesMeta": {
|
|
55
|
+
"foldkit-crud": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"foldkit-remote": {
|
|
59
|
+
"optional": true
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"effect": "4.0.0",
|
|
64
|
+
"foldkit": "0.165.0",
|
|
65
|
+
"tsdown": "^0.23.0",
|
|
66
|
+
"typescript": "5.9.3",
|
|
67
|
+
"foldkit-entity": "0.7.0",
|
|
68
|
+
"foldkit-crud": "0.6.1",
|
|
69
|
+
"foldkit-remote": "0.13.0"
|
|
70
|
+
},
|
|
71
|
+
"scripts": {
|
|
72
|
+
"build": "tsdown",
|
|
73
|
+
"typecheck": "tsc -b"
|
|
74
|
+
}
|
|
6
75
|
}
|