foldkit-data-grid 0.6.0 → 0.7.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.
package/README.md CHANGED
@@ -26,7 +26,9 @@ records and domain mutations.**
26
26
  | which cells exist and where they stand | `GridProjection`, derived from the three above |
27
27
 
28
28
  The grid never sorts, filters or fetches. A sorted result is the order the
29
- application hands it.
29
+ application hands it. A column can draw a filter control
30
+ ([Filtering from a column](#filtering-from-a-column)), but the value it sets is
31
+ the application's, and so is applying it.
30
32
 
31
33
  Use this package for an interactive grid: keyboard movement between cells,
32
34
  ranges, editing. A readable, sortable list of records is
@@ -264,6 +266,8 @@ Selection is the grid's and opt-in: `DataGrid.make({ id, columns, rowSelection:
264
266
  Messages change nothing.
265
267
 
266
268
  ```ts
269
+ import { GridSelection } from 'foldkit-data-grid'
270
+
267
271
  const Picking = DataGrid.make({ id: 'picking', columns, rowSelection: 'multiple' })
268
272
  const start = Picking.bundle.init(undefined).model
269
273
  const picked = Picking.bundle.update(start, Picking.Message.RowSelected({ row: 'p1' }), undefined).model
@@ -306,6 +310,8 @@ the field on the wrong one. A column `draft` that returns a string still
306
310
  wins. Committing decodes the field's text through the schema.
307
311
 
308
312
  ```ts
313
+ import { Schema, SchemaGetter } from 'effect'
314
+
309
315
  // Dollars as typed, with at most two decimals, and the number they mean.
310
316
  const Price = Schema.String.check(
311
317
  Schema.isPattern(/^\d+(\.\d{1,2})?$/, { message: 'A price, like 4.99' }),
@@ -363,6 +369,57 @@ const repriced = (cell: Extract<Out, { _tag: 'Edited' }>) =>
363
369
  - **A click on another cell commits first;** a refused draft keeps the edit
364
370
  and the click waits. Hiding the edited column ends the edit.
365
371
 
372
+ ### Checkboxes
373
+
374
+ A column whose `schema` decodes to a boolean is `CellEditor.Checkbox`: its
375
+ cells are checkboxes drawn from the column's value, toggled in place, and no
376
+ draft opens. `Columns.checkbox` is that schema for the text `true` and
377
+ `false`, which is what a boolean shows as; any schema from text to a boolean
378
+ works the same way.
379
+
380
+ ```ts
381
+ interface Task {
382
+ readonly id: string
383
+ readonly title: string
384
+ readonly done: boolean
385
+ }
386
+ const tasks = Columns.define<Task>()({
387
+ title: { header: 'Title', value: task => task.title },
388
+ done: { header: 'Done', value: task => task.done, edit: { schema: Columns.checkbox } },
389
+ })
390
+ const Tasks = DataGrid.make({ id: 'tasks', columns: tasks })
391
+
392
+ // In `onOut`, as any edit: the text read back as a boolean.
393
+ const checked = (cell: Extract<typeof Tasks.Out.Type, { _tag: 'Edited' }>) =>
394
+ Tasks.matchEdit(cell, { done: ({ row, value }) => ({ row, done: value }) })
395
+ ```
396
+
397
+ - **`EditToggled({ cell, checked, by })`** commits the column's text for the
398
+ other value at once and reports `Out.Edited`, as a commit does; the
399
+ application writes the row. `cell` is the cell's DOM id and `checked` the
400
+ value as drawn. The view sends it for a press on the box
401
+ (`by: Grid.Toggle.Press()`) and for Space or Enter on the cell holding the
402
+ grid's tab stop (`by: Grid.Toggle.Key({ drawn })`, `drawn` the focus that
403
+ frame was drawn from). Before anything is focused the tab stop is the
404
+ first cell, so a keyboard user who tabs in can toggle it at once.
405
+ - **`update` refuses it,** changing nothing, on a cell whose column does not
406
+ edit or is no checkbox, while an edit is open, and for a key whose `drawn`
407
+ is no longer the Model's focus: the key's frame was drawn before focus
408
+ moved, and it would toggle the cell focus left. `EditStarted` and
409
+ `EditTyped` on a checkbox change nothing.
410
+ - **The value must be a boolean.** The checkbox is drawn from it, so
411
+ `Columns.define` refuses a column with `Columns.checkbox` whose `value`
412
+ returns anything else, at the `value`. `GridCrud.columns` refuses a
413
+ checkbox outright: a listed member's value is its text.
414
+ - **Paste and fill** judge its text by the schema, as on any column: `true`
415
+ and `false` pass. A cut or Delete leaves a checkbox as it is, since it has
416
+ no empty value, and clears the other cells in its range.
417
+ - **Every toggle sends the opposite of the value drawn,** so until the
418
+ application's write of the last one is drawn, each further press or key
419
+ sends the same value again. Where the row changes only when a server
420
+ answers, every toggle before the answer asks for the same value, and a
421
+ second press does not take the first one back.
422
+
366
423
  ## The clipboard
367
424
 
368
425
  Copy and paste speak the tab-separated text spreadsheets do. `Clipboard` is
@@ -370,6 +427,8 @@ pure: it writes and reads that text and lays a paste onto the grid; the view
370
427
  wires it to the browser's copy, cut and paste events.
371
428
 
372
429
  ```ts
430
+ import { Clipboard } from 'foldkit-data-grid'
431
+
373
432
  Clipboard.toTsv([['SKU', 'Price'], ['A-1', '9']]) // 'SKU\tPrice\nA-1\t9'
374
433
  Clipboard.parseTsv('a\t"b\tc"\r\n') // [['a', 'b\tc']]
375
434
  ```
@@ -416,6 +475,24 @@ Clipboard.parseTsv('a\t"b\tc"\r\n') // [['a', 'b\tc']]
416
475
  the grid's terms. Remote still owns the page, its loading, its retries and
417
476
  its next page; this subpath fetches nothing and holds nothing.
418
477
 
478
+ <!-- docs-check standalone
479
+ import { Schema } from 'effect'
480
+ import { Display, Crud } from 'foldkit-crud'
481
+ import { DataGrid } from 'foldkit-data-grid'
482
+ import { Entity } from 'foldkit-entity'
483
+ import { Query, type Page, type RemoteData } from 'foldkit-remote'
484
+ const Post = Entity.define(
485
+ 'Post',
486
+ Schema.Struct({ id: Schema.String, title: Schema.String, cents: Schema.Number }),
487
+ )
488
+ const PostRow = Entity.select(Post, { id: true, title: true, cents: true })
489
+ const Posts = Crud.list('Posts', {
490
+ query: Query.make('Posts', { Input: {}, Result: Query.connection(Post) }),
491
+ selection: PostRow,
492
+ })
493
+ type Row = typeof PostRow.schema.Type
494
+ declare const page: RemoteData<Page<Row>>
495
+ -->
419
496
  ```ts
420
497
  import { GridCrud } from 'foldkit-data-grid/crud'
421
498
 
@@ -460,6 +537,19 @@ The grid owns where its columns stand and how wide they are: a
460
537
  how it starts and what it allows: `width`, `minWidth`, `maxWidth`,
461
538
  `resizable` and `hideable`.
462
539
 
540
+ <!-- docs-check standalone
541
+ import { Columns, DataGrid } from 'foldkit-data-grid'
542
+ interface Product {
543
+ readonly id: string
544
+ readonly sku: string
545
+ readonly price: number
546
+ }
547
+ const columns = Columns.define<Product>()({
548
+ sku: { header: 'SKU', value: product => product.sku },
549
+ price: { header: 'Price', value: product => product.price },
550
+ })
551
+ const Grid = DataGrid.make({ id: 'products', columns })
552
+ -->
463
553
  ```ts
464
554
  const State = Grid.columnState
465
555
 
@@ -509,8 +599,127 @@ A projection built from a hand-written layout is lenient too: a column the
509
599
  layout omits joins the center, an unknown id is dropped, and an id named
510
600
  twice keeps its first place.
511
601
 
602
+ ## Filtering from a column
603
+
604
+ A column with `filter` draws a filter form on its header
605
+ (`foldkit-mixins-data-grid`). The grid holds only the form while it is open;
606
+ the filter value is the application's, as a sort or a search is, and the
607
+ grid reports each change for the application to store and apply.
608
+
609
+ ```text
610
+ header form (grid) -> Out.Filtered({ change }) -> application Model (filters)
611
+ -> held rows: Grid.keeps
612
+ -> Remote: the query's input
613
+ ```
614
+
615
+ ```ts
616
+ import { Schema } from 'effect'
617
+ import { CellEditor } from 'foldkit-data-grid'
618
+
619
+ interface Job {
620
+ readonly id: string
621
+ readonly title: string
622
+ readonly status: 'Open' | 'Done'
623
+ readonly hours: number
624
+ }
625
+ const Status = Schema.Literals(['Open', 'Done'])
626
+ const jobColumns = Columns.define<Job>()({
627
+ title: { header: 'Title', value: job => job.title, filter: true },
628
+ status: { header: 'Status', value: job => job.status, edit: { schema: Status }, filter: true },
629
+ // Shown as text, filtered as a number: a range.
630
+ hours: { header: 'Hours', value: job => job.hours.toFixed(1), filter: CellEditor.Number() },
631
+ })
632
+ const JobGrid = DataGrid.make({ id: 'jobs', columns: jobColumns })
633
+
634
+ // The application's value, stored as `JobGrid.Filters` (`JobGrid.noFilters` to start).
635
+ type JobFilters = typeof JobGrid.Filters.Type
636
+ // In `onOut`: one column's change written in.
637
+ const filtered = (filters: JobFilters, out: typeof JobGrid.Out.Type) =>
638
+ JobGrid.Out.match(out, {
639
+ Filtered: ({ change }) => JobGrid.setFilter(filters, change),
640
+ Edited: () => filters,
641
+ Pasted: () => filters,
642
+ UndoRequested: () => filters,
643
+ RedoRequested: () => filters,
644
+ Filled: () => filters,
645
+ RowsRequested: () => filters,
646
+ })
647
+ // Held rows: what the filters keep, read from each row's own field.
648
+ const shown = (all: ReadonlyArray<Job>, filters: JobFilters) =>
649
+ all.filter(
650
+ JobGrid.keeps(filters, {
651
+ title: job => job.title,
652
+ status: job => job.status,
653
+ hours: job => job.hours,
654
+ }),
655
+ )
656
+ ```
657
+
658
+ - **`filter: true`** reads the kind from `edit.schema`'s decoded side
659
+ (`filterKindOf`): a boolean is a checkbox, a `Date` a range of days, a
660
+ number a range, text literals or a text enum a choice of them, a number
661
+ enum a number, anything else text (a branded text, a template literal, a
662
+ mixed enum). A column with no schema filters text; a `CellEditor` names the
663
+ kind for one that does not edit.
664
+ - **`ColumnFilter`** is the value, one variant per kind: `Contains`,
665
+ `Range`, `OneOf`, `Is`, `Between`. A filter that keeps every row (empty
666
+ text, no bound, nothing ticked, any) is reported as none, never an empty
667
+ variant. Each column's is typed by its spec (`FilterOf`), so
668
+ `JobGrid.Filters.Type['status']` is `Option<OneOf<'Open' | 'Done'>>`.
669
+ - **`Out.Filtered({ change })`** carries one column's new filter or none;
670
+ `setFilter` writes it in. Only a grid with a filtering column has this arm,
671
+ so a grid that filters nothing matches no `Filtered`.
672
+ - **`keeps(filters, read)`** is a predicate over held rows. `read` names
673
+ each filtering column's own field, typed by its variant, never the text a
674
+ cell shows: `hours: job => job.hours.toFixed(1)` does not compile.
675
+ `Contains` folds ASCII case only, as `Expr.contains` does on every backend;
676
+ a `Between` compares a `Date` by its local day, so a server applying the
677
+ same filter must store or compare local days too to agree with it. Build it
678
+ once per filters value: the predicate is a function of the filters alone.
679
+ - **`Filters`** is the stored form: `null` for none, and each column only
680
+ its own variant, never empty, a choice only of its literals each once,
681
+ bounds finite numbers or `YYYY-MM-DD` days. A key no filtering column has
682
+ is refused whatever the decode is given, so a URL or a saved view naming a
683
+ removed column fails to decode rather than being dropped silently.
684
+ - **Over a Remote list,** the application maps its filters onto the
685
+ query's input, and the query's body filters what is given
686
+ (`Expr.whenGiven(input.statuses, statuses => Expr.in(fields.status,
687
+ statuses))`, `Expr.whenGiven(input.min, min => Expr.gte(fields.cents,
688
+ min))`), with null for a column not filtered. `examples/registry` filters
689
+ statuses and prices that way, its prices typed in dollars and rounded inward
690
+ to cents so the server keeps what the range says.
691
+
692
+ The form's update:
693
+
694
+ - **`FilterOpened({ column, drawn })`** opens the form seeded with the
695
+ application's filter as the view drew it; it is refused for a column that
696
+ does not filter or is hidden, or a `drawn` its column refuses. Opening
697
+ focuses the header and closes the menu, as `MenuOpened` does.
698
+ - **A field's change** (`FilterTyped`, `FilterOptionToggled`,
699
+ `FilterChecked`) is applied to the form as it is now, so keys faster than a
700
+ frame add up. It is reported when the form reads as a valid filter other
701
+ than the last reported. A bound that is no number (`1x`, `0x10`, or 309
702
+ digits, past every finite number) is not reported, so the rows stay
703
+ filtered by the last filter that held; crossed bounds are reported, and keep
704
+ nothing.
705
+ - **A filter the application wrote while the form was open** (from a URL, a
706
+ saved view): the view draws that frame stale, showing the written filter,
707
+ and every change it sends (Clear included) carries the form's generation
708
+ when it was drawn. The first such change seeds the form from the written
709
+ filter before it applies; the reseed and each report move the generation
710
+ on, so the frame's later changes add to the first rather than seeding
711
+ again.
712
+ - **While the form is open,** a paste, a fill, an undo and a redo are
713
+ refused, as during an edit; whatever focuses a cell or opens an edit, the
714
+ menu or a fill closes the form, and so does hiding its column (a column
715
+ hidden by a write to the Model closes it on the next Message).
716
+
512
717
  ## Limits
513
718
 
514
719
  - Not built: a drag across regions to pin a column (the view's column
515
720
  menu pins), and more than one cell range.
516
721
  - Every row is one height.
722
+ - Filters: one condition per column, all columns joined by "and"; no
723
+ operators beyond the five (`Contains`, `Range`, `OneOf`, `Is`, `Between`);
724
+ options are a choice's literals, not read from the data. A hidden column
725
+ still filters, and its header cannot say so.
package/dist/columns.d.ts CHANGED
@@ -18,12 +18,22 @@ export interface ColumnSpec<Row, Value> {
18
18
  /** Whether it can be hidden. Default `true`. */
19
19
  readonly hideable?: boolean;
20
20
  /**
21
- * Makes the column's cells editable as text. The grid holds the draft,
22
- * commits it only when the column's schema decodes it, and reports the
23
- * committed text as an `Edited` OutMessage; `matchEdit` reads its value
24
- * back, and writing it is the application's.
21
+ * Makes the column's cells editable. The grid holds the draft, commits it
22
+ * only when the column's schema decodes it, and reports the committed text
23
+ * as an `Edited` OutMessage; `matchEdit` reads its value back, and writing
24
+ * it is the application's. A schema that decodes to a boolean
25
+ * (`Columns.checkbox`) makes the cells checkboxes, toggled in place.
25
26
  */
26
27
  readonly edit?: ColumnEdit<Row, unknown>;
28
+ /**
29
+ * Draws a filter control on the column's header (`foldkit-mixins-data-grid`).
30
+ * `true` reads its kind from `edit.schema`'s decoded side (`filterKindOf`):
31
+ * a boolean is a checkbox, a `Date` a range of days, a number a range, text
32
+ * literals a choice of them, anything else text. A `CellEditor` names the
33
+ * kind for a column that does not edit. The value filtered by is the
34
+ * application's: the grid reports it as `Out.Filtered`.
35
+ */
36
+ readonly filter?: true | CellEditor;
27
37
  }
28
38
  export interface ColumnEdit<Row, Value = string> {
29
39
  /** The text an edit of a row's cell begins with. Default the value as a string. */
@@ -37,8 +47,8 @@ export interface ColumnEdit<Row, Value = string> {
37
47
  readonly schema?: Schema.Codec<Value, string>;
38
48
  }
39
49
  /**
40
- * How a cell's edit is drawn, read from its column's schema: a choice of the
41
- * literals its text may be, a number typed, or text.
50
+ * How a cell's edit is drawn, read from its column's schema: a checkbox, a
51
+ * choice of the literals its text may be, a number typed, or text.
42
52
  */
43
53
  export declare const CellEditor: import("foldkit/schema").TaggedUnion<{
44
54
  readonly Text: {};
@@ -50,10 +60,23 @@ export declare const CellEditor: import("foldkit/schema").TaggedUnion<{
50
60
  };
51
61
  /** The schema decodes to a date: a native date field over the draft text. */
52
62
  readonly Date: {};
63
+ /**
64
+ * The schema decodes to a boolean: a checkbox drawn from the column's
65
+ * value, toggled in place (`EditToggled`); it opens no draft.
66
+ */
67
+ readonly Checkbox: {};
53
68
  }>;
54
69
  export type CellEditor = typeof CellEditor.Type;
55
- /** A column's editor, from its schema; a column with none edits text. */
70
+ /**
71
+ * A column's editor, from its schema; a column with none edits text. A choice
72
+ * is read from the text side, since its literals are what is typed.
73
+ */
56
74
  export declare const editorOf: (schema: Schema.Top | undefined) => CellEditor;
75
+ /**
76
+ * A column's filter kind, from its schema; a column with none filters text.
77
+ * Everything is read from the decoded side, the values a filter compares.
78
+ */
79
+ export declare const filterKindOf: (schema: Schema.Top | undefined) => CellEditor;
57
80
  /** The ids of the columns that edit. */
58
81
  export type EditableId<Specs> = { [K in keyof Specs]: Specs[K] extends {
59
82
  readonly edit: object;
@@ -64,6 +87,17 @@ export type EditValue<Spec> = Spec extends {
64
87
  readonly schema: Schema.Codec<infer Value, string>;
65
88
  };
66
89
  } ? Value : string;
90
+ /**
91
+ * A checkbox column's cells are drawn from its value, so a spec whose edit
92
+ * decodes to a boolean must read a boolean from its row.
93
+ */
94
+ export type CheckboxValues<Row, Specs> = { readonly [K in keyof Specs]: Specs[K] extends {
95
+ readonly edit: {
96
+ readonly schema: Schema.Codec<boolean, string>;
97
+ };
98
+ } ? {
99
+ readonly value: (row: Row) => boolean;
100
+ } : unknown; };
67
101
  export interface Column<Row, Id extends string, Value> extends ColumnSpec<Row, Value> {
68
102
  readonly id: Id;
69
103
  }
@@ -89,6 +123,12 @@ export declare const Columns: {
89
123
  defaultWidth: number;
90
124
  /** The narrowest a column with no `minWidth` resizes to. */
91
125
  minWidth: number;
126
+ /**
127
+ * A boolean as a cell's text, `true` or `false`: give it as a column's
128
+ * `edit.schema` and the cells are checkboxes. Any schema from text to a
129
+ * boolean does the same; this one reads what `textOf` writes.
130
+ */
131
+ checkbox: Schema.decodeTo<Schema.Boolean, Schema.Literals<readonly ["true", "false"]>, never, never>;
92
132
  /** A value as a cell shows it: nothing for `null` or `undefined`. */
93
133
  textOf: (value: unknown) => string;
94
134
  /**
@@ -96,7 +136,7 @@ export declare const Columns: {
96
136
  * type and once with the specs, so the ids and values are inferred:
97
137
  * `Columns.define<Product>()({ sku: { header: 'SKU', value: p => p.sku } })`.
98
138
  */
99
- define: <Row>() => <Specs extends Record<string, ColumnSpec<Row, unknown>>>(specs: Specs) => NoInfer<Columns<Row, Specs>>;
139
+ define: <Row>() => <Specs extends Record<string, ColumnSpec<Row, unknown>>>(specs: Specs & CheckboxValues<Row, Specs>) => NoInfer<Columns<Row, Specs>>;
100
140
  };
101
141
  export {};
102
142
  //# sourceMappingURL=columns.d.ts.map
@@ -1 +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,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schema, SchemaAST, SchemaGetter } from "effect";
2
2
  import { defineTaggedUnion } from "foldkit/schema";
3
3
  // src/columns.ts
4
4
  /**
5
- * How a cell's edit is drawn, read from its column's schema: a choice of the
6
- * literals its text may be, a number typed, or text.
5
+ * How a cell's edit is drawn, read from its column's schema: a checkbox, a
6
+ * choice of the literals its text may be, a number typed, or text.
7
7
  */
8
8
  const CellEditor = defineTaggedUnion({
9
9
  Text: {},
@@ -12,7 +12,12 @@ const CellEditor = defineTaggedUnion({
12
12
  /** The schema's text is one of these, offered in order. */
13
13
  Choice: { options: Schema.Array(Schema.String) },
14
14
  /** The schema decodes to a date: a native date field over the draft text. */
15
- Date: {}
15
+ Date: {},
16
+ /**
17
+ * The schema decodes to a boolean: a checkbox drawn from the column's
18
+ * value, toggled in place (`EditToggled`); it opens no draft.
19
+ */
20
+ Checkbox: {}
16
21
  });
17
22
  /**
18
23
  * Whether a schema decodes to a date, found as Effect's own tools find it:
@@ -26,17 +31,48 @@ const isDate = (ast) => {
26
31
  const representation = ast.annotations?.["representation"];
27
32
  return typeof representation === "object" && representation !== null && "id" in representation && representation.id === DATE_ID;
28
33
  };
29
- /** A column's editor, from its schema; a column with none edits text. */
30
- const editorOf = (schema) => {
31
- if (schema === void 0) return CellEditor.Text();
32
- const encoded = SchemaAST.toEncoded(schema.ast);
33
- if (SchemaAST.isUnion(encoded)) {
34
- const options = encoded.types.flatMap((member) => SchemaAST.isLiteral(member) && typeof member.literal === "string" ? [member.literal] : []);
35
- if (options.length === encoded.types.length) return CellEditor.Choice({ options });
34
+ const isBooleanLike = (ast) => SchemaAST.isBoolean(ast) || SchemaAST.isLiteral(ast) && typeof ast.literal === "boolean" || SchemaAST.isUnion(ast) && ast.types.length > 0 && ast.types.every(isBooleanLike);
35
+ const enumValues = (ast) => SchemaAST.isEnum(ast) ? ast.enums.map(([, value]) => value) : [];
36
+ const isNumberLike = (ast) => SchemaAST.isNumber(ast) || SchemaAST.isLiteral(ast) && typeof ast.literal === "number" || SchemaAST.isEnum(ast) && ast.enums.length > 0 && enumValues(ast).every((value) => typeof value === "number") || SchemaAST.isUnion(ast) && ast.types.length > 0 && ast.types.every(isNumberLike);
37
+ /** The text literals an AST is one of, when it is nothing else. */
38
+ const textLiterals = (ast) => {
39
+ if (SchemaAST.isEnum(ast)) {
40
+ const values = enumValues(ast);
41
+ const texts = values.flatMap((value) => typeof value === "string" ? [value] : []);
42
+ return texts.length > 0 && texts.length === values.length ? Option.some(texts) : Option.none();
36
43
  }
37
- const type = SchemaAST.toType(schema.ast);
44
+ if (SchemaAST.isLiteral(ast)) return typeof ast.literal === "string" ? Option.some([ast.literal]) : Option.none();
45
+ if (!SchemaAST.isUnion(ast) || ast.types.length === 0) return Option.none();
46
+ const options = ast.types.flatMap((member) => SchemaAST.isLiteral(member) && typeof member.literal === "string" ? [member.literal] : []);
47
+ return options.length === ast.types.length ? Option.some(options) : Option.none();
48
+ };
49
+ /**
50
+ * The one classifier behind `editorOf` and `filterKindOf`: a checkbox when
51
+ * the value is a boolean (first: `Columns.checkbox`'s text is the literals
52
+ * `true` and `false`), a choice when `choice` is text literals, then a date,
53
+ * a number, or text. `FilterKind` says the same at the type level, and a
54
+ * table test holds the two together.
55
+ */
56
+ const classify = (type, choice) => {
57
+ if (isBooleanLike(type)) return CellEditor.Checkbox();
58
+ const options = textLiterals(choice);
59
+ if (Option.isSome(options)) return CellEditor.Choice({ options: options.value });
38
60
  if (isDate(type)) return CellEditor.Date();
39
- return SchemaAST.isNumber(type) ? CellEditor.Number() : CellEditor.Text();
61
+ return isNumberLike(type) ? CellEditor.Number() : CellEditor.Text();
62
+ };
63
+ /**
64
+ * A column's editor, from its schema; a column with none edits text. A choice
65
+ * is read from the text side, since its literals are what is typed.
66
+ */
67
+ const editorOf = (schema) => schema === void 0 ? CellEditor.Text() : classify(SchemaAST.toType(schema.ast), SchemaAST.toEncoded(schema.ast));
68
+ /**
69
+ * A column's filter kind, from its schema; a column with none filters text.
70
+ * Everything is read from the decoded side, the values a filter compares.
71
+ */
72
+ const filterKindOf = (schema) => {
73
+ if (schema === void 0) return CellEditor.Text();
74
+ const type = SchemaAST.toType(schema.ast);
75
+ return classify(type, type);
40
76
  };
41
77
  const arrayIndex = /^(0|[1-9][0-9]*)$/;
42
78
  const Columns = {
@@ -44,6 +80,15 @@ const Columns = {
44
80
  defaultWidth: 120,
45
81
  /** The narrowest a column with no `minWidth` resizes to. */
46
82
  minWidth: 40,
83
+ /**
84
+ * A boolean as a cell's text, `true` or `false`: give it as a column's
85
+ * `edit.schema` and the cells are checkboxes. Any schema from text to a
86
+ * boolean does the same; this one reads what `textOf` writes.
87
+ */
88
+ checkbox: Schema.Literals(["true", "false"]).pipe(Schema.decodeTo(Schema.Boolean, {
89
+ decode: SchemaGetter.transform((text) => text === "true"),
90
+ encode: SchemaGetter.transform((value) => value ? "true" : "false")
91
+ })),
47
92
  /** A value as a cell shows it: nothing for `null` or `undefined`. */
48
93
  textOf: (value) => value === null || value === void 0 ? "" : String(value),
49
94
  /**
@@ -53,12 +98,13 @@ const Columns = {
53
98
  */
54
99
  define: () => (specs) => {
55
100
  if (Object.getPrototypeOf(specs) !== Object.prototype || Object.hasOwn(specs, "__proto__")) throw new Error("Columns.define: \"__proto__\" cannot name a column.");
56
- const ids = Object.keys(specs);
101
+ const given = specs;
102
+ const ids = Object.keys(given);
57
103
  const byId = {};
58
104
  for (const id of ids) {
59
105
  if (arrayIndex.test(id)) throw new Error(`Columns.define: the column id "${id}" is an array index, which JavaScript orders before every other key. Give it a name that is not a number.`);
60
106
  byId[id] = Object.freeze({
61
- ...specs[id],
107
+ ...given[id],
62
108
  id
63
109
  });
64
110
  }
@@ -68,6 +114,6 @@ const Columns = {
68
114
  });
69
115
  }
70
116
  };
71
- export { CellEditor, Columns, editorOf };
117
+ export { CellEditor, Columns, editorOf, filterKindOf };
72
118
 
73
119
  //# sourceMappingURL=columns.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"columns.js","names":[],"sources":["../src/columns.ts"],"sourcesContent":["import { Schema, SchemaAST } from 'effect'\nimport { defineTaggedUnion } from 'foldkit/schema'\n/** What a column shows and where it starts out. Its id is its key in `Columns.define`. */\nexport interface ColumnSpec<Row, Value> {\n readonly header: string\n readonly value: (row: Row) => Value\n /** The region the column starts in; `ColumnLayout.initial` reads it. */\n readonly pinned?: 'start' | 'end'\n /** Whether the column starts hidden; `ColumnLayout.initial` reads it. */\n readonly hidden?: boolean\n /** Its width in pixels until resized. Default `Columns.defaultWidth`. */\n readonly width?: number\n /** The narrowest a resize makes it. Default `Columns.minWidth`. */\n readonly minWidth?: number\n /** The widest a resize makes it. Default no limit. */\n readonly maxWidth?: number\n /** Whether it can be resized. Default `true`. */\n readonly resizable?: boolean\n /** Whether it can be hidden. Default `true`. */\n readonly hideable?: boolean\n /**\n * Makes the column's cells editable as text. The grid holds the draft,\n * commits it only when the column's schema decodes it, and reports the\n * committed text as an `Edited` OutMessage; `matchEdit` reads its value\n * back, and writing it is the application's.\n */\n readonly edit?: ColumnEdit<Row, unknown>\n}\n\nexport interface ColumnEdit<Row, Value = string> {\n /** The text an edit of a row's cell begins with. Default the value as a string. */\n readonly draft?: (row: Row) => string\n /**\n * What the text means: from the text typed to the column's value. A draft\n * is committed only when it decodes, and the failure's message is the\n * cell's error, so a check's own `message` is what a person reads. Default\n * any text, as itself.\n */\n readonly schema?: Schema.Codec<Value, string>\n}\n\n/**\n * How a cell's edit is drawn, read from its column's schema: a choice of the\n * literals its text may be, a number typed, or text.\n */\nexport const CellEditor = defineTaggedUnion({\n Text: {},\n /** The schema decodes to a number: typed with a decimal keypad on touch. */\n Number: {},\n /** The schema's text is one of these, offered in order. */\n Choice: { options: Schema.Array(Schema.String) },\n /** The schema decodes to a date: a native date field over the draft text. */\n Date: {},\n})\nexport type CellEditor = typeof CellEditor.Type\n\n/**\n * Whether a schema decodes to a date, found as Effect's own tools find it:\n * by the declaration's representation id. Only Date-ness is read here, never\n * the text format: committing decodes the draft through the schema, and a\n * refusal is the cell's error.\n */\nconst DATE_ID = 'effect/schema/Date'\n\nconst isDate = (ast: SchemaAST.AST): boolean => {\n if (!SchemaAST.isDeclaration(ast)) return false\n const representation: unknown = ast.annotations?.['representation']\n return (\n typeof representation === 'object' &&\n representation !== null &&\n 'id' in representation &&\n representation.id === DATE_ID\n )\n}\n\n/** A column's editor, from its schema; a column with none edits text. */\nexport const editorOf = (schema: Schema.Top | undefined): CellEditor => {\n if (schema === undefined) return CellEditor.Text()\n const encoded = SchemaAST.toEncoded(schema.ast)\n if (SchemaAST.isUnion(encoded)) {\n const options = encoded.types.flatMap(member =>\n SchemaAST.isLiteral(member) && typeof member.literal === 'string' ? [member.literal] : [],\n )\n // Every member a text literal: anything else typed would be refused.\n if (options.length === encoded.types.length) return CellEditor.Choice({ options })\n }\n const type = SchemaAST.toType(schema.ast)\n if (isDate(type)) return CellEditor.Date()\n return SchemaAST.isNumber(type) ? CellEditor.Number() : CellEditor.Text()\n}\n\n/** The ids of the columns that edit. */\nexport type EditableId<Specs> = {\n [K in keyof Specs]: Specs[K] extends { readonly edit: object } ? K : never\n}[keyof Specs] &\n string\n\n/** What an editable column's text decodes to: its schema's value, or the text. */\nexport type EditValue<Spec> = Spec extends {\n readonly edit: { readonly schema: Schema.Codec<infer Value, string> }\n}\n ? Value\n : string\n\nexport interface Column<Row, Id extends string, Value> extends ColumnSpec<Row, Value> {\n readonly id: Id\n}\n\ntype ValueOf<Spec> = Spec extends ColumnSpec<never, infer Value> ? Value : never\n\nexport type ColumnId<C> = C extends Columns<never, infer Specs> ? keyof Specs & string : never\n\n/**\n * A grid's columns, keyed by stable id. Order, visibility and pinning live in\n * a `ColumnLayout`, so every reference to a column (focus, a selected range,\n * a saved width) names its id and survives a reorder.\n */\nexport interface Columns<Row, Specs extends Record<string, ColumnSpec<Row, unknown>>> {\n /** In definition order: the order `ColumnLayout.initial` starts from. */\n readonly ids: ReadonlyArray<keyof Specs & string>\n readonly byId: {\n readonly [Id in keyof Specs & string]: Column<Row, Id, ValueOf<Specs[Id]>>\n }\n /**\n * Type-only: the specs as written, so a grid made from these columns infers\n * each one exactly, its edit's schema included. Never set.\n */\n readonly Specs?: Specs\n}\n\n// Integer-like keys are enumerated before every other key, whatever the order\n// they were written in, so `{ name, 2024 }` would put 2024 first.\nconst arrayIndex = /^(0|[1-9][0-9]*)$/\n\nexport const Columns = {\n /** The width of a column that names none. */\n defaultWidth: 120,\n /** The narrowest a column with no `minWidth` resizes to. */\n minWidth: 40,\n /** A value as a cell shows it: nothing for `null` or `undefined`. */\n textOf: (value: unknown): string => (value === null || value === undefined ? '' : String(value)),\n /**\n * Declares a grid's columns over `Row`. Call it twice, once with the row\n * type and once with the specs, so the ids and values are inferred:\n * `Columns.define<Product>()({ sku: { header: 'SKU', value: p => p.sku } })`.\n */\n define:\n <Row>() =>\n <Specs extends Record<string, ColumnSpec<Row, unknown>>>(\n specs: Specs,\n ): NoInfer<Columns<Row, Specs>> => {\n // A literal `__proto__:` key sets the prototype instead of naming a\n // column, so the column would vanish from `Object.keys`.\n if (Object.getPrototypeOf(specs) !== Object.prototype || Object.hasOwn(specs, '__proto__')) {\n throw new Error('Columns.define: \"__proto__\" cannot name a column.')\n }\n const ids = Object.keys(specs)\n const byId: Record<string, Column<Row, string, unknown>> = {}\n for (const id of ids) {\n if (arrayIndex.test(id)) {\n throw new Error(\n `Columns.define: the column id \"${id}\" is an array index, which JavaScript orders before every other key. Give it a name that is not a number.`,\n )\n }\n byId[id] = Object.freeze({ ...specs[id]!, id })\n }\n return Object.freeze({\n ids: Object.freeze(ids),\n byId: Object.freeze(byId),\n }) as Columns<Row, Specs>\n },\n}\n"],"mappings":";;;;;;;AA6CA,MAAa,aAAa,kBAAkB;CAC1C,MAAM,CAAC;;CAEP,QAAQ,CAAC;;CAET,QAAQ,EAAE,SAAS,OAAO,MAAM,OAAO,MAAM,EAAE;;CAE/C,MAAM,CAAC;AACT,CAAC;;;;;;;AASD,MAAM,UAAU;AAEhB,MAAM,UAAU,QAAgC;CAC9C,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K,OAAO,OAAO,GAAG;GACtB,MAAM,OAAO,OAAO,IAAI;EAC1B,CAAC;CACH;AACJ"}
1
+ {"version":3,"file":"columns.js","names":[],"sources":["../src/columns.ts"],"sourcesContent":["import { Option, Schema, SchemaAST, SchemaGetter } from 'effect'\nimport { defineTaggedUnion } from 'foldkit/schema'\n/** What a column shows and where it starts out. Its id is its key in `Columns.define`. */\nexport interface ColumnSpec<Row, Value> {\n readonly header: string\n readonly value: (row: Row) => Value\n /** The region the column starts in; `ColumnLayout.initial` reads it. */\n readonly pinned?: 'start' | 'end'\n /** Whether the column starts hidden; `ColumnLayout.initial` reads it. */\n readonly hidden?: boolean\n /** Its width in pixels until resized. Default `Columns.defaultWidth`. */\n readonly width?: number\n /** The narrowest a resize makes it. Default `Columns.minWidth`. */\n readonly minWidth?: number\n /** The widest a resize makes it. Default no limit. */\n readonly maxWidth?: number\n /** Whether it can be resized. Default `true`. */\n readonly resizable?: boolean\n /** Whether it can be hidden. Default `true`. */\n readonly hideable?: boolean\n /**\n * Makes the column's cells editable. The grid holds the draft, commits it\n * only when the column's schema decodes it, and reports the committed text\n * as an `Edited` OutMessage; `matchEdit` reads its value back, and writing\n * it is the application's. A schema that decodes to a boolean\n * (`Columns.checkbox`) makes the cells checkboxes, toggled in place.\n */\n readonly edit?: ColumnEdit<Row, unknown>\n /**\n * Draws a filter control on the column's header (`foldkit-mixins-data-grid`).\n * `true` reads its kind from `edit.schema`'s decoded side (`filterKindOf`):\n * a boolean is a checkbox, a `Date` a range of days, a number a range, text\n * literals a choice of them, anything else text. A `CellEditor` names the\n * kind for a column that does not edit. The value filtered by is the\n * application's: the grid reports it as `Out.Filtered`.\n */\n readonly filter?: true | CellEditor\n}\n\nexport interface ColumnEdit<Row, Value = string> {\n /** The text an edit of a row's cell begins with. Default the value as a string. */\n readonly draft?: (row: Row) => string\n /**\n * What the text means: from the text typed to the column's value. A draft\n * is committed only when it decodes, and the failure's message is the\n * cell's error, so a check's own `message` is what a person reads. Default\n * any text, as itself.\n */\n readonly schema?: Schema.Codec<Value, string>\n}\n\n/**\n * How a cell's edit is drawn, read from its column's schema: a checkbox, a\n * choice of the literals its text may be, a number typed, or text.\n */\nexport const CellEditor = defineTaggedUnion({\n Text: {},\n /** The schema decodes to a number: typed with a decimal keypad on touch. */\n Number: {},\n /** The schema's text is one of these, offered in order. */\n Choice: { options: Schema.Array(Schema.String) },\n /** The schema decodes to a date: a native date field over the draft text. */\n Date: {},\n /**\n * The schema decodes to a boolean: a checkbox drawn from the column's\n * value, toggled in place (`EditToggled`); it opens no draft.\n */\n Checkbox: {},\n})\nexport type CellEditor = typeof CellEditor.Type\n\n/**\n * Whether a schema decodes to a date, found as Effect's own tools find it:\n * by the declaration's representation id. Only Date-ness is read here, never\n * the text format: committing decodes the draft through the schema, and a\n * refusal is the cell's error.\n */\nconst DATE_ID = 'effect/schema/Date'\n\nconst isDate = (ast: SchemaAST.AST): boolean => {\n if (!SchemaAST.isDeclaration(ast)) return false\n const representation: unknown = ast.annotations?.['representation']\n return (\n typeof representation === 'object' &&\n representation !== null &&\n 'id' in representation &&\n representation.id === DATE_ID\n )\n}\n\nconst isBooleanLike = (ast: SchemaAST.AST): boolean =>\n SchemaAST.isBoolean(ast) ||\n (SchemaAST.isLiteral(ast) && typeof ast.literal === 'boolean') ||\n (SchemaAST.isUnion(ast) && ast.types.length > 0 && ast.types.every(isBooleanLike))\n// A TypeScript enum: its members' values, numbers or text or both.\nconst enumValues = (ast: SchemaAST.AST): ReadonlyArray<string | number> =>\n SchemaAST.isEnum(ast) ? ast.enums.map(([, value]) => value) : []\nconst isNumberLike = (ast: SchemaAST.AST): boolean =>\n SchemaAST.isNumber(ast) ||\n (SchemaAST.isLiteral(ast) && typeof ast.literal === 'number') ||\n (SchemaAST.isEnum(ast) &&\n ast.enums.length > 0 &&\n enumValues(ast).every(value => typeof value === 'number')) ||\n (SchemaAST.isUnion(ast) && ast.types.length > 0 && ast.types.every(isNumberLike))\n/** The text literals an AST is one of, when it is nothing else. */\nconst textLiterals = (ast: SchemaAST.AST): Option.Option<ReadonlyArray<string>> => {\n if (SchemaAST.isEnum(ast)) {\n const values = enumValues(ast)\n const texts = values.flatMap(value => (typeof value === 'string' ? [value] : []))\n return texts.length > 0 && texts.length === values.length ? Option.some(texts) : Option.none()\n }\n if (SchemaAST.isLiteral(ast)) {\n return typeof ast.literal === 'string' ? Option.some([ast.literal]) : Option.none()\n }\n if (!SchemaAST.isUnion(ast) || ast.types.length === 0) return Option.none()\n const options = ast.types.flatMap(member =>\n SchemaAST.isLiteral(member) && typeof member.literal === 'string' ? [member.literal] : [],\n )\n return options.length === ast.types.length ? Option.some(options) : Option.none()\n}\n\n/**\n * The one classifier behind `editorOf` and `filterKindOf`: a checkbox when\n * the value is a boolean (first: `Columns.checkbox`'s text is the literals\n * `true` and `false`), a choice when `choice` is text literals, then a date,\n * a number, or text. `FilterKind` says the same at the type level, and a\n * table test holds the two together.\n */\nconst classify = (type: SchemaAST.AST, choice: SchemaAST.AST): CellEditor => {\n if (isBooleanLike(type)) return CellEditor.Checkbox()\n const options = textLiterals(choice)\n if (Option.isSome(options)) return CellEditor.Choice({ options: options.value })\n if (isDate(type)) return CellEditor.Date()\n return isNumberLike(type) ? CellEditor.Number() : CellEditor.Text()\n}\n\n/**\n * A column's editor, from its schema; a column with none edits text. A choice\n * is read from the text side, since its literals are what is typed.\n */\nexport const editorOf = (schema: Schema.Top | undefined): CellEditor =>\n schema === undefined\n ? CellEditor.Text()\n : classify(SchemaAST.toType(schema.ast), SchemaAST.toEncoded(schema.ast))\n\n/**\n * A column's filter kind, from its schema; a column with none filters text.\n * Everything is read from the decoded side, the values a filter compares.\n */\nexport const filterKindOf = (schema: Schema.Top | undefined): CellEditor => {\n if (schema === undefined) return CellEditor.Text()\n const type = SchemaAST.toType(schema.ast)\n return classify(type, type)\n}\n\n/** The ids of the columns that edit. */\nexport type EditableId<Specs> = {\n [K in keyof Specs]: Specs[K] extends { readonly edit: object } ? K : never\n}[keyof Specs] &\n string\n\n/** What an editable column's text decodes to: its schema's value, or the text. */\nexport type EditValue<Spec> = Spec extends {\n readonly edit: { readonly schema: Schema.Codec<infer Value, string> }\n}\n ? Value\n : string\n\n/**\n * A checkbox column's cells are drawn from its value, so a spec whose edit\n * decodes to a boolean must read a boolean from its row.\n */\nexport type CheckboxValues<Row, Specs> = {\n readonly [K in keyof Specs]: Specs[K] extends {\n readonly edit: { readonly schema: Schema.Codec<boolean, string> }\n }\n ? { readonly value: (row: Row) => boolean }\n : unknown\n}\n\nexport interface Column<Row, Id extends string, Value> extends ColumnSpec<Row, Value> {\n readonly id: Id\n}\n\ntype ValueOf<Spec> = Spec extends ColumnSpec<never, infer Value> ? Value : never\n\nexport type ColumnId<C> = C extends Columns<never, infer Specs> ? keyof Specs & string : never\n\n/**\n * A grid's columns, keyed by stable id. Order, visibility and pinning live in\n * a `ColumnLayout`, so every reference to a column (focus, a selected range,\n * a saved width) names its id and survives a reorder.\n */\nexport interface Columns<Row, Specs extends Record<string, ColumnSpec<Row, unknown>>> {\n /** In definition order: the order `ColumnLayout.initial` starts from. */\n readonly ids: ReadonlyArray<keyof Specs & string>\n readonly byId: {\n readonly [Id in keyof Specs & string]: Column<Row, Id, ValueOf<Specs[Id]>>\n }\n /**\n * Type-only: the specs as written, so a grid made from these columns infers\n * each one exactly, its edit's schema included. Never set.\n */\n readonly Specs?: Specs\n}\n\n// Integer-like keys are enumerated before every other key, whatever the order\n// they were written in, so `{ name, 2024 }` would put 2024 first.\nconst arrayIndex = /^(0|[1-9][0-9]*)$/\n\nexport const Columns = {\n /** The width of a column that names none. */\n defaultWidth: 120,\n /** The narrowest a column with no `minWidth` resizes to. */\n minWidth: 40,\n /**\n * A boolean as a cell's text, `true` or `false`: give it as a column's\n * `edit.schema` and the cells are checkboxes. Any schema from text to a\n * boolean does the same; this one reads what `textOf` writes.\n */\n checkbox: Schema.Literals(['true', 'false']).pipe(\n Schema.decodeTo(Schema.Boolean, {\n decode: SchemaGetter.transform(text => text === 'true'),\n encode: SchemaGetter.transform(value => (value ? 'true' : 'false')),\n }),\n ),\n /** A value as a cell shows it: nothing for `null` or `undefined`. */\n textOf: (value: unknown): string => (value === null || value === undefined ? '' : String(value)),\n /**\n * Declares a grid's columns over `Row`. Call it twice, once with the row\n * type and once with the specs, so the ids and values are inferred:\n * `Columns.define<Product>()({ sku: { header: 'SKU', value: p => p.sku } })`.\n */\n define:\n <Row>() =>\n <Specs extends Record<string, ColumnSpec<Row, unknown>>>(\n specs: Specs & CheckboxValues<Row, Specs>,\n ): NoInfer<Columns<Row, Specs>> => {\n // A literal `__proto__:` key sets the prototype instead of naming a\n // column, so the column would vanish from `Object.keys`.\n if (Object.getPrototypeOf(specs) !== Object.prototype || Object.hasOwn(specs, '__proto__')) {\n throw new Error('Columns.define: \"__proto__\" cannot name a column.')\n }\n const given: Record<string, ColumnSpec<Row, unknown>> = specs\n const ids = Object.keys(given)\n const byId: Record<string, Column<Row, string, unknown>> = {}\n for (const id of ids) {\n if (arrayIndex.test(id)) {\n throw new Error(\n `Columns.define: the column id \"${id}\" is an array index, which JavaScript orders before every other key. Give it a name that is not a number.`,\n )\n }\n byId[id] = Object.freeze({ ...given[id]!, id })\n }\n return Object.freeze({\n ids: Object.freeze(ids),\n byId: Object.freeze(byId),\n }) as Columns<Row, Specs>\n },\n}\n"],"mappings":";;;;;;;AAuDA,MAAa,aAAa,kBAAkB;CAC1C,MAAM,CAAC;;CAEP,QAAQ,CAAC;;CAET,QAAQ,EAAE,SAAS,OAAO,MAAM,OAAO,MAAM,EAAE;;CAE/C,MAAM,CAAC;;;;;CAKP,UAAU,CAAC;AACb,CAAC;;;;;;;AASD,MAAM,UAAU;AAEhB,MAAM,UAAU,QAAgC;CAC9C,IAAI,CAAC,UAAU,cAAc,GAAG,GAAG,OAAO;CAC1C,MAAM,iBAA0B,IAAI,cAAc;CAClD,OACE,OAAO,mBAAmB,YAC1B,mBAAmB,QACnB,QAAQ,kBACR,eAAe,OAAO;AAE1B;AA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,WAAW,KAAK,EAAE,GACpB,MAAM,IAAI,MACR,kCAAkC,GAAG,0GACvC;GAEF,KAAK,MAAM,OAAO,OAAO;IAAE,GAAG,MAAM;IAAM;GAAG,CAAC;EAChD;EACA,OAAO,OAAO,OAAO;GACnB,KAAK,OAAO,OAAO,GAAG;GACtB,MAAM,OAAO,OAAO,IAAI;EAC1B,CAAC;CACH;AACJ"}
package/dist/crud.d.ts CHANGED
@@ -1,9 +1,18 @@
1
+ import { Schema } from "effect";
1
2
  import { ColumnSpec, Columns } from "./columns.js";
2
3
  import { DisplayColumn, DisplayWords } from "foldkit-crud";
3
4
  import { Page, RemoteData } from "foldkit-remote";
4
5
  import { RowModel, RowStatus } from "./rows.js";
5
6
  /** What a grid adds to a listed member's column: where it stands, its size, and editing. */
6
7
  type ColumnOptions<Row> = Partial<Omit<ColumnSpec<Row, string>, 'value'>>;
8
+ /** A listed member's value is its text, so its column cannot be a checkbox (`Columns.checkbox`). */
9
+ type TextEdits<Options> = { readonly [K in keyof Options]: Options[K] extends {
10
+ readonly edit: {
11
+ readonly schema: Schema.Codec<boolean, string>;
12
+ };
13
+ } ? {
14
+ readonly edit: 'A listed member shows as text, so it cannot be a checkbox';
15
+ } : unknown; };
7
16
  /**
8
17
  * The grid's columns for a list: one per listed member, keyed by its member
9
18
  * key, headed by its label, its value the member's text as its Display says
@@ -17,7 +26,7 @@ declare const columns: <Key extends string, Row extends { readonly [K in Key]: u
17
26
  readonly Row: Row;
18
27
  }, options?: {
19
28
  readonly words?: DisplayWords;
20
- readonly columns?: Options;
29
+ readonly columns?: Options & TextEdits<Options>;
21
30
  }) => Columns<Row, { readonly [K in Key]: ColumnSpec<Row, string> & Options[K]; }>;
22
31
  declare const rows: <Row>(page: RemoteData<Page<Row>>, key: (row: Row) => string) => RowModel<Row>;
23
32
  /** Where a page stands, for the grid to say. */
@@ -1 +1 @@
1
- {"version":3,"file":"crud.d.ts","names":[],"sources":["../src/crud.ts"],"mappings":";;;;;KAcK,cAAc,OAAO,QAAQ,KAAK,WAAW;;;;;;;;;cAU5C,UACJ,oBACA,wBAAwB,KAAK,kBAE7B,4BAA4B,KAAK,OAAO,cAAc,SAAM;WAE3C,SAAS,cAAc,cAAc;WAAgB,KAAK;GAAK;WAC5D,QAAQ;WAAuB,UAAU;MAC5D,QAAQ,iBAAiB,KAAK,MAAM,WAAW,eAAe,QAAQ;cA4BnE,OAAQ,KAAG,MAAQ,WAAW,KAAK,OAAK,MAAQ,KAAK,mBAAiB,SAAS;;cAuB/E,SAAU,KAAG,MAAQ,WAAW,KAAK,UAAQ;qBAUtC"}
1
+ {"version":3,"file":"crud.d.ts","names":[],"sources":["../src/crud.ts"],"mappings":";;;;;;KAcK,cAAc,OAAO,QAAQ,KAAK,WAAW;;KAG7C,UAAU,uBACH,WAAW,UAAU,QAAQ;WAC5B;aAAiB,QAAQ,OAAO;;;WAE5B;;;;;;;;;;cAYX,UACJ,oBACA,wBAAwB,KAAK,kBAE7B,4BAA4B,KAAK,OAAO,cAAc,SAAM;WAE3C,SAAS,cAAc,cAAc;WAAgB,KAAK;GAAK;WAC5D,QAAQ;WAAuB,UAAU,UAAU,UAAU;MAChF,QAAQ,iBAAiB,KAAK,MAAM,WAAW,eAAe,QAAQ;cA2BnE,OAAQ,KAAG,MAAQ,WAAW,KAAK,OAAK,MAAQ,KAAK,mBAAiB,SAAS;;cAuB/E,SAAU,KAAG,MAAQ,WAAW,KAAK,UAAQ;qBAUtC"}
package/dist/crud.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"crud.js","names":[],"sources":["../src/crud.ts"],"sourcesContent":["/**\n * `foldkit-data-grid/crud` — a grid over a `foldkit-crud` list and the Remote\n * page it reads. The list says the columns, their labels and how each value\n * shows; Remote owns the page, its loading and its retries. This module only\n * reads both into the grid's terms: columns, a row model, and a status. It\n * fetches nothing and holds nothing.\n */\nimport { Option } from 'effect'\nimport { Display, type DisplayColumn, type DisplayWords } from 'foldkit-crud'\nimport { type Page, RemoteData } from 'foldkit-remote'\nimport { Columns, type ColumnSpec } from './columns.js'\nimport { RowCount, RowModel, RowStatus } from './rows.js'\n\n/** What a grid adds to a listed member's column: where it stands, its size, and editing. */\ntype ColumnOptions<Row> = Partial<Omit<ColumnSpec<Row, string>, 'value'>>\n\n/**\n * The grid's columns for a list: one per listed member, keyed by its member\n * key, headed by its label, its value the member's text as its Display says\n * it. A member whose Display is hidden (usually the id) starts hidden: it is\n * read, and can be shown, but is not drawn. `columns` adds what only the\n * grid knows to a member's column: pinning, widths, `edit`, or another\n * header; what it gives wins over what the list says.\n */\nconst columns = <\n Key extends string,\n Row extends { readonly [K in Key]: unknown },\n // Each member's options as written, so an edit's schema types its value.\n Options extends { readonly [K in Key]?: ColumnOptions<Row> },\n>(\n list: { readonly columns: ReadonlyArray<DisplayColumn<Key>>; readonly Row: Row },\n options: { readonly words?: DisplayWords; readonly columns?: Options } = {},\n): Columns<Row, { readonly [K in Key]: ColumnSpec<Row, string> & Options[K] }> => {\n // Filled for every listed key below, so the record holds each Key.\n const specs = {} as Record<Key, ColumnSpec<Row, string>>\n for (const column of list.columns) {\n specs[column.key] = {\n header: column.label,\n value: row => Display.show(column.display, row[column.key], options.words ?? {}),\n ...(column.display.shown ? {} : { hidden: true }),\n ...options.columns?.[column.key],\n }\n }\n // Each spec is the member's column with its options spread over it, so it\n // holds what `Options` says of it.\n return Columns.define<Row>()(\n specs as { readonly [K in Key]: ColumnSpec<Row, string> & Options[K] },\n )\n}\n\n/**\n * The rows of a page as the grid's row model, in the page's order. A page with\n * more after it counts as unknown, at least its rows; a failed read keeps the\n * rows it had. No answer yet, or none found, is no rows.\n */\n// One row model per page value, so the projection built from it, and what is\n// worked out from that, is kept across renders while the page is unchanged.\nconst pages = new WeakMap<object, RowModel<unknown>>()\nconst empty: ReadonlyArray<never> = []\n\nconst rows = <Row>(page: RemoteData<Page<Row>>, key: (row: Row) => string): RowModel<Row> => {\n const items = (value: Page<Row>): RowModel<Row> => {\n const known = pages.get(value)\n if (known !== undefined) return known as RowModel<Row>\n const model = RowModel.fromArray(value.items, key)\n const counted = value.hasNext\n ? { ...model, count: RowCount.Unknown({ atLeast: value.items.length }) }\n : model\n pages.set(value, counted)\n return counted\n }\n const none = RowModel.fromArray<Row>(empty, key)\n return RemoteData.match<Page<Row>, RowModel<Row>>(page, {\n Initial: () => none,\n Loading: () => none,\n NotFound: () => none,\n Ready: items,\n Refreshing: items,\n Failed: (_, previous) => Option.match(previous, { onNone: () => none, onSome: items }),\n })\n}\n\n/** Where a page stands, for the grid to say. */\nconst status = <Row>(page: RemoteData<Page<Row>>): RowStatus =>\n RemoteData.match<Page<Row>, RowStatus>(page, {\n Initial: () => RowStatus.Loading(),\n Loading: () => RowStatus.Loading(),\n NotFound: () => RowStatus.Ready(),\n Ready: () => RowStatus.Ready(),\n Refreshing: () => RowStatus.Refreshing(),\n Failed: error => RowStatus.Failed({ message: error.message }),\n })\n\nexport const GridCrud = { columns, rows, status }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAwBA,MAAM,WAMJ,MACA,UAAyE,CAAC,MACM;CAEhF,MAAM,QAAQ,CAAC;CACf,KAAK,MAAM,UAAU,KAAK,SACxB,MAAM,OAAO,OAAO;EAClB,QAAQ,OAAO;EACf,QAAO,QAAO,QAAQ,KAAK,OAAO,SAAS,IAAI,OAAO,MAAM,QAAQ,SAAS,CAAC,CAAC;EAC/E,GAAI,OAAO,QAAQ,QAAQ,CAAC,IAAI,EAAE,QAAQ,KAAK;EAC/C,GAAG,QAAQ,UAAU,OAAO;CAC9B;CAIF,OAAO,QAAQ,OAAY,CAAC,CAC1B,KACF;AACF;;;;;;AASA,MAAM,wBAAQ,IAAI,QAAmC;AACrD,MAAM,QAA8B,CAAC;AAErC,MAAM,QAAa,MAA6B,QAA6C;CAC3F,MAAM,SAAS,UAAoC;EACjD,MAAM,QAAQ,MAAM,IAAI,KAAK;EAC7B,IAAI,UAAU,KAAA,GAAW,OAAO;EAChC,MAAM,QAAQ,SAAS,UAAU,MAAM,OAAO,GAAG;EACjD,MAAM,UAAU,MAAM,UAClB;GAAE,GAAG;GAAO,OAAO,SAAS,QAAQ,EAAE,SAAS,MAAM,MAAM,OAAO,CAAC;EAAE,IACrE;EACJ,MAAM,IAAI,OAAO,OAAO;EACxB,OAAO;CACT;CACA,MAAM,OAAO,SAAS,UAAe,OAAO,GAAG;CAC/C,OAAO,WAAW,MAAgC,MAAM;EACtD,eAAe;EACf,eAAe;EACf,gBAAgB;EAChB,OAAO;EACP,YAAY;EACZ,SAAS,GAAG,aAAa,OAAO,MAAM,UAAU;GAAE,cAAc;GAAM,QAAQ;EAAM,CAAC;CACvF,CAAC;AACH;;AAGA,MAAM,UAAe,SACnB,WAAW,MAA4B,MAAM;CAC3C,eAAe,UAAU,QAAQ;CACjC,eAAe,UAAU,QAAQ;CACjC,gBAAgB,UAAU,MAAM;CAChC,aAAa,UAAU,MAAM;CAC7B,kBAAkB,UAAU,WAAW;CACvC,SAAQ,UAAS,UAAU,OAAO,EAAE,SAAS,MAAM,QAAQ,CAAC;AAC9D,CAAC;AAEH,MAAa,WAAW;CAAE;CAAS;CAAM;AAAO"}
1
+ {"version":3,"file":"crud.js","names":[],"sources":["../src/crud.ts"],"sourcesContent":["/**\n * `foldkit-data-grid/crud` — a grid over a `foldkit-crud` list and the Remote\n * page it reads. The list says the columns, their labels and how each value\n * shows; Remote owns the page, its loading and its retries. This module only\n * reads both into the grid's terms: columns, a row model, and a status. It\n * fetches nothing and holds nothing.\n */\nimport { Option, type Schema } from 'effect'\nimport { Display, type DisplayColumn, type DisplayWords } from 'foldkit-crud'\nimport { type Page, RemoteData } from 'foldkit-remote'\nimport { type CheckboxValues, Columns, type ColumnSpec } from './columns.js'\nimport { RowCount, RowModel, RowStatus } from './rows.js'\n\n/** What a grid adds to a listed member's column: where it stands, its size, and editing. */\ntype ColumnOptions<Row> = Partial<Omit<ColumnSpec<Row, string>, 'value'>>\n\n/** A listed member's value is its text, so its column cannot be a checkbox (`Columns.checkbox`). */\ntype TextEdits<Options> = {\n readonly [K in keyof Options]: Options[K] extends {\n readonly edit: { readonly schema: Schema.Codec<boolean, string> }\n }\n ? { readonly edit: 'A listed member shows as text, so it cannot be a checkbox' }\n : unknown\n}\n\n/**\n * The grid's columns for a list: one per listed member, keyed by its member\n * key, headed by its label, its value the member's text as its Display says\n * it. A member whose Display is hidden (usually the id) starts hidden: it is\n * read, and can be shown, but is not drawn. `columns` adds what only the\n * grid knows to a member's column: pinning, widths, `edit`, or another\n * header; what it gives wins over what the list says.\n */\nconst columns = <\n Key extends string,\n Row extends { readonly [K in Key]: unknown },\n // Each member's options as written, so an edit's schema types its value.\n Options extends { readonly [K in Key]?: ColumnOptions<Row> },\n>(\n list: { readonly columns: ReadonlyArray<DisplayColumn<Key>>; readonly Row: Row },\n options: { readonly words?: DisplayWords; readonly columns?: Options & TextEdits<Options> } = {},\n): Columns<Row, { readonly [K in Key]: ColumnSpec<Row, string> & Options[K] }> => {\n // Filled for every listed key below, so the record holds each Key.\n const specs = {} as Record<Key, ColumnSpec<Row, string>>\n for (const column of list.columns) {\n specs[column.key] = {\n header: column.label,\n value: row => Display.show(column.display, row[column.key], options.words ?? {}),\n ...(column.display.shown ? {} : { hidden: true }),\n ...options.columns?.[column.key],\n }\n }\n // Each spec is the member's column with its options spread over it, so it\n // holds what `Options` says of it, and `TextEdits` kept a checkbox out.\n type Specs = { readonly [K in Key]: ColumnSpec<Row, string> & Options[K] }\n return Columns.define<Row>()<Specs>(specs as Specs & CheckboxValues<Row, Specs>)\n}\n\n/**\n * The rows of a page as the grid's row model, in the page's order. A page with\n * more after it counts as unknown, at least its rows; a failed read keeps the\n * rows it had. No answer yet, or none found, is no rows.\n */\n// One row model per page value, so the projection built from it, and what is\n// worked out from that, is kept across renders while the page is unchanged.\nconst pages = new WeakMap<object, RowModel<unknown>>()\nconst empty: ReadonlyArray<never> = []\n\nconst rows = <Row>(page: RemoteData<Page<Row>>, key: (row: Row) => string): RowModel<Row> => {\n const items = (value: Page<Row>): RowModel<Row> => {\n const known = pages.get(value)\n if (known !== undefined) return known as RowModel<Row>\n const model = RowModel.fromArray(value.items, key)\n const counted = value.hasNext\n ? { ...model, count: RowCount.Unknown({ atLeast: value.items.length }) }\n : model\n pages.set(value, counted)\n return counted\n }\n const none = RowModel.fromArray<Row>(empty, key)\n return RemoteData.match<Page<Row>, RowModel<Row>>(page, {\n Initial: () => none,\n Loading: () => none,\n NotFound: () => none,\n Ready: items,\n Refreshing: items,\n Failed: (_, previous) => Option.match(previous, { onNone: () => none, onSome: items }),\n })\n}\n\n/** Where a page stands, for the grid to say. */\nconst status = <Row>(page: RemoteData<Page<Row>>): RowStatus =>\n RemoteData.match<Page<Row>, RowStatus>(page, {\n Initial: () => RowStatus.Loading(),\n Loading: () => RowStatus.Loading(),\n NotFound: () => RowStatus.Ready(),\n Ready: () => RowStatus.Ready(),\n Refreshing: () => RowStatus.Refreshing(),\n Failed: error => RowStatus.Failed({ message: error.message }),\n })\n\nexport const GridCrud = { columns, rows, status }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiCA,MAAM,WAMJ,MACA,UAA8F,CAAC,MACf;CAEhF,MAAM,QAAQ,CAAC;CACf,KAAK,MAAM,UAAU,KAAK,SACxB,MAAM,OAAO,OAAO;EAClB,QAAQ,OAAO;EACf,QAAO,QAAO,QAAQ,KAAK,OAAO,SAAS,IAAI,OAAO,MAAM,QAAQ,SAAS,CAAC,CAAC;EAC/E,GAAI,OAAO,QAAQ,QAAQ,CAAC,IAAI,EAAE,QAAQ,KAAK;EAC/C,GAAG,QAAQ,UAAU,OAAO;CAC9B;CAKF,OAAO,QAAQ,OAAY,CAAC,CAAQ,KAA2C;AACjF;;;;;;AASA,MAAM,wBAAQ,IAAI,QAAmC;AACrD,MAAM,QAA8B,CAAC;AAErC,MAAM,QAAa,MAA6B,QAA6C;CAC3F,MAAM,SAAS,UAAoC;EACjD,MAAM,QAAQ,MAAM,IAAI,KAAK;EAC7B,IAAI,UAAU,KAAA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