foldkit-data-grid 0.3.1 → 0.4.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 (60) hide show
  1. package/dist/clipboard.d.ts +44 -0
  2. package/dist/clipboard.d.ts.map +1 -0
  3. package/dist/clipboard.js +109 -0
  4. package/dist/clipboard.js.map +1 -0
  5. package/dist/columnState.d.ts +53 -0
  6. package/dist/columnState.d.ts.map +1 -0
  7. package/dist/columnState.js +201 -0
  8. package/dist/columnState.js.map +1 -0
  9. package/dist/{rows-D8siEVqF.d.mts → columns.d.ts} +15 -81
  10. package/dist/columns.d.ts.map +1 -0
  11. package/dist/columns.js +73 -0
  12. package/dist/columns.js.map +1 -0
  13. package/dist/{crud.d.mts → crud.d.ts} +3 -2
  14. package/dist/{crud.d.mts.map → crud.d.ts.map} +1 -1
  15. package/dist/{crud.mjs → crud.js} +3 -2
  16. package/dist/crud.js.map +1 -0
  17. package/dist/fill.d.ts +49 -0
  18. package/dist/fill.d.ts.map +1 -0
  19. package/dist/fill.js +113 -0
  20. package/dist/fill.js.map +1 -0
  21. package/dist/focus.d.ts +119 -0
  22. package/dist/focus.d.ts.map +1 -0
  23. package/dist/focus.js +150 -0
  24. package/dist/focus.js.map +1 -0
  25. package/dist/{index.d.mts → grid.d.ts} +13 -564
  26. package/dist/grid.d.ts.map +1 -0
  27. package/dist/{index.mjs → grid.js} +11 -1024
  28. package/dist/grid.js.map +1 -0
  29. package/dist/index.d.ts +13 -0
  30. package/dist/index.js +13 -0
  31. package/dist/layout.d.ts +20 -0
  32. package/dist/layout.d.ts.map +1 -0
  33. package/dist/layout.js +27 -0
  34. package/dist/layout.js.map +1 -0
  35. package/dist/projection.d.ts +87 -0
  36. package/dist/projection.d.ts.map +1 -0
  37. package/dist/projection.js +102 -0
  38. package/dist/projection.js.map +1 -0
  39. package/dist/rows.d.ts +70 -0
  40. package/dist/rows.d.ts.map +1 -0
  41. package/dist/{rows-Dy1HPpGX.mjs → rows.js} +3 -71
  42. package/dist/rows.js.map +1 -0
  43. package/dist/selection.d.ts +65 -0
  44. package/dist/selection.d.ts.map +1 -0
  45. package/dist/selection.js +137 -0
  46. package/dist/selection.js.map +1 -0
  47. package/dist/viewport.d.ts +74 -0
  48. package/dist/viewport.d.ts.map +1 -0
  49. package/dist/viewport.js +116 -0
  50. package/dist/viewport.js.map +1 -0
  51. package/dist/virtual.d.ts +73 -0
  52. package/dist/virtual.d.ts.map +1 -0
  53. package/dist/virtual.js +112 -0
  54. package/dist/virtual.js.map +1 -0
  55. package/package.json +15 -15
  56. package/dist/crud.mjs.map +0 -1
  57. package/dist/index.d.mts.map +0 -1
  58. package/dist/index.mjs.map +0 -1
  59. package/dist/rows-D8siEVqF.d.mts.map +0 -1
  60. package/dist/rows-Dy1HPpGX.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grid.js","names":[],"sources":["../src/grid.ts"],"sourcesContent":["import { Equal, Option, Result, Schema } from 'effect'\nimport { defineMessageUnion } from 'foldkit/message'\nimport { defineTaggedUnion } from 'foldkit/schema'\nimport { modifyFields } from 'foldkit/struct'\nimport type * as Update from 'foldkit/update'\nimport { Bundle } from 'foldkit-bundle'\nimport { ColumnState } from './columnState.js'\nimport { Fill } from './fill.js'\nimport {\n CellEditor,\n Columns,\n type ColumnSpec,\n type EditValue,\n type EditableId,\n editorOf,\n} from './columns.js'\nimport { GridFocus } from './focus.js'\nimport { GridProjection } from './projection.js'\nimport type { RowModel } from './rows.js'\nimport { GridSelection, RowSelection } from './selection.js'\nimport { GridViewport } from './viewport.js'\nimport { type GridWindow, type Viewport, VirtualGrid } from './virtual.js'\n\nconst Offsets = Schema.Struct({ top: Schema.Number, left: Schema.Number })\n\n/** How a choice's draft moves through its options (`EditStepped`). */\nconst choiceSteps = ['next', 'previous', 'first', 'last', 'pageNext', 'pagePrevious'] as const\ntype ChoiceStep = (typeof choiceSteps)[number]\n\n/**\n * One grid's interaction state: focus, the viewport and the column state, as\n * one Bundle. Its update is the parts' own, joined: a key that moves focus\n * off screen carries the scroll that reveals the cell, and the grid issues it.\n *\n * `id` names the grid in the DOM: the scroll container's id, and the prefix\n * of every cell's id (`GridFocus.cellId`). Selection is opt-in:\n * `rowSelection` lets rows be selected one at a time or several, and\n * `cellSelection` lets a rectangle of cells be selected; without them their\n * Messages change nothing.\n */\nconst make = <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(options: {\n readonly id: string\n readonly columns: Columns<Row, Specs>\n readonly rowSelection?: 'single' | 'multiple'\n readonly cellSelection?: boolean\n}) => {\n const focus = GridFocus.make(options.columns)\n const columnState = ColumnState.make(options.columns)\n const Column = focus.Address.fields.column\n const CellText = Schema.Struct({ row: Schema.String, column: Column, text: Schema.String })\n const PastedCell = Schema.Struct({ ...CellText.fields, from: Schema.String })\n const Range = Schema.Struct({ anchor: focus.Address, focus: focus.Address })\n /** A fill: the range carried on, and the cell it is carried to. */\n const FillRequest = Schema.Struct({ source: Range, to: focus.Address })\n const Model = Schema.Struct({\n focus: focus.Model,\n viewport: GridViewport.Model,\n columns: columnState.Model,\n /** A column being resized by the pointer, and its width when the drag began. */\n resizing: Schema.OptionFromNullOr(Schema.Struct({ column: Column, from: Schema.Number })),\n /**\n * A column header being dragged by the pointer, and how far toward its\n * region's end. Where it lands is worked out when it is let go.\n */\n dragging: Schema.OptionFromNullOr(Schema.Struct({ column: Column, delta: Schema.Number })),\n /** The column whose menu is open, and the item the keyboard is on (`menuItems`). */\n menu: Schema.OptionFromNullOr(Schema.Struct({ column: Column, active: Schema.Number })),\n /**\n * A fill being dragged from the range's handle: the range, and the cell\n * the pointer is over. What it writes is worked out when it is let go.\n */\n filling: Schema.OptionFromNullOr(FillRequest),\n selection: Schema.Struct({\n rows: RowSelection,\n /** Where the last plain row selection happened; a Shift range extends from it. */\n anchor: Schema.OptionFromNullOr(Schema.String),\n /** A rectangle of cells, by its corners; a single focused cell is none. */\n cells: Schema.OptionFromNullOr(Range),\n }),\n /**\n * The cell being edited, the text it began from, its draft, and the error\n * that refused it, if one did.\n */\n editing: Schema.OptionFromNullOr(\n Schema.Struct({\n address: focus.Address,\n from: Schema.String,\n draft: Schema.String,\n error: Schema.OptionFromNullOr(Schema.String),\n }),\n ),\n })\n const Region = Schema.Literals(['start', 'center', 'end'])\n type Model = typeof Model.Type\n /**\n * What a column's menu offers: pinning it to another region, hiding it,\n * and showing each hidden column. Each is a column Message the grid\n * already has; the menu only gathers them.\n */\n const MenuItem = defineTaggedUnion({\n Pin: { region: Region },\n Hide: {},\n Show: { column: Column },\n })\n type MenuItem = typeof MenuItem.Type\n const Message = defineMessageUnion({\n /** The pointer or the browser focused a cell. */\n Focused: { address: focus.Address },\n /**\n * A key moved focus. `reveal` is the scroll that brings the cell into\n * view, worked out by the view from the viewport it drew, or none when\n * the cell is shown.\n */\n Moved: { address: focus.Address, reveal: Schema.OptionFromNullOr(Offsets) },\n /** A key moved focus up to a column's header, revealing it when scrolled away. */\n HeaderFocused: { column: Column, reveal: Schema.OptionFromNullOr(Offsets) },\n /** The scroll container moved or changed size: `GridViewport.Measure` reports it. */\n Measured: { ...Offsets.fields, width: Schema.Number, height: Schema.Number },\n /** The reveal a `Moved` asked for has scrolled the container. */\n Revealed: Offsets.fields,\n /** A column was resized; the width is clamped to its limits. */\n ColumnResized: { column: Column, width: Schema.Number },\n ColumnHidden: { column: Column },\n ColumnShown: { column: Column },\n /** A column moved to `index` in `region`: a reorder, a pin or an unpin. */\n ColumnMoved: { column: Column, region: Region, index: Schema.Number },\n /** The pointer went down on a column's resize handle. */\n ResizeStarted: { column: Column },\n /**\n * The pointer moved `delta` pixels toward the column's end edge since the\n * resize began: positive widens it, in either direction of text.\n */\n ResizeMoved: { delta: Schema.Number },\n /** The pointer let go, or the drag was cancelled and the width goes back. */\n ResizeEnded: { completed: Schema.Boolean },\n /**\n * The pointer began dragging the column header whose DOM id is `header`\n * (`GridFocus.headerId`). The id comes from the page, so one that is not\n * a shown column of this grid changes nothing.\n */\n ColumnDragStarted: { header: Schema.String },\n /** The pointer is `delta` pixels toward the region's end from where the drag began. */\n ColumnDragged: { delta: Schema.Number },\n /**\n * The pointer let go and the column moves where it was dropped\n * (`ColumnState.dropAt`), or the drag was cancelled and nothing moves.\n */\n ColumnDragEnded: { completed: Schema.Boolean },\n /**\n * A column's menu opened, from its button or a key on its header; focus\n * goes to the header, so closing the menu returns there.\n */\n MenuOpened: { column: Column },\n /** The keyboard moved to item `active` of the open menu. */\n MenuMoved: { active: Schema.Number },\n /**\n * Item `index` of the open menu was chosen. It is read from the menu as\n * it stands now, and the menu closes.\n */\n MenuChosen: { index: Schema.Number },\n MenuClosed: {},\n /** A row was chosen: in single mode it is the selection, in multiple it toggles. */\n RowSelected: { row: Schema.String },\n /** A Shift range of rows, worked out by the view from the projection it drew. */\n RowsExtended: { rows: Schema.Array(Schema.String), to: Schema.String },\n AllRowsSelected: {},\n RowsCleared: {},\n /**\n * A rectangle of cells, from Shift with a key. `reveal` scrolls its far\n * corner into view, as `Moved`'s does for a focused cell.\n */\n CellsSelected: {\n anchor: focus.Address,\n focus: focus.Address,\n reveal: Schema.OptionFromNullOr(Offsets),\n },\n /**\n * The pointer pressed the cell whose DOM id is `cell` (`GridFocus.cellId`).\n * With Shift it spans a range from the focused cell, with Ctrl or Meta it\n * toggles the cell's row, and plainly it focuses the cell. The id comes\n * from the page, so one that is not this grid's cell changes nothing.\n */\n CellPressed: { cell: Schema.String, shiftKey: Schema.Boolean, toggleKey: Schema.Boolean },\n CellsCleared: {},\n /** An edit began on an editable cell, with the text it starts from. */\n EditStarted: { address: focus.Address, draft: Schema.String },\n /**\n * A key typed on the grid itself, over an editable cell: it starts an\n * edit with the text, or, when that cell's edit is already open (the\n * keys came faster than the editor took focus), adds to its draft.\n * On a choice it picks the next option starting with the key instead,\n * after the draft's, as a select finds one. `from` is the text the cell\n * showed, which a new edit began from.\n */\n EditTyped: { address: focus.Address, text: Schema.String, from: Schema.String },\n EditChanged: { draft: Schema.String },\n /**\n * A choice's draft moved through its column's options: the next or\n * previous, the first or last, or a page of ten either way, stopping at\n * the ends. The view sends the step; `update` works out the option from\n * the draft as it is. On a column that is no choice it changes nothing.\n */\n EditStepped: {\n by: Schema.Literals(choiceSteps),\n },\n /** A pointer chose one of a choice's options: it is the draft, committed in place. */\n EditChosen: { draft: Schema.String },\n /**\n * The draft is to be kept. When the column accepts it the edit ends, focus\n * goes to `next` (the cell below, or beside, worked out by the view), and\n * the grid reports `Out.Edited`, unless the draft is the text the edit\n * began from or decodes to the same value; when it refuses it, the edit\n * stays with the error.\n */\n EditCommitted: {\n next: Schema.OptionFromNullOr(focus.Address),\n reveal: Schema.OptionFromNullOr(Offsets),\n },\n EditCancelled: {},\n /**\n * Text pasted, or a cut's cleared cells, laid onto editable cells by the\n * view (`Clipboard.pasteAt`). A cell its text leaves unchanged (as an\n * edit judges it, against `from`) is dropped; the rest are checked against\n * their columns and reported as one `Pasted`, or nothing when none is left.\n */\n Pasted: { cells: Schema.Array(PastedCell) },\n /**\n * Ctrl or Meta with Z on the grid, or with Shift (or Ctrl+Y) for redo.\n * An open edit keeps them, since the editor's own undo is the field's.\n */\n UndoRequested: {},\n RedoRequested: {},\n /** Ctrl+D or Ctrl+R over a range, worked out by the view: carry `source` on to `to`. */\n FillRequested: FillRequest.fields,\n /** The range's fill handle was pressed and moved: a fill begins from the range. */\n FillStarted: {},\n /** The pointer, filling, is over the cell whose DOM id is `cell`. */\n FillDragged: { cell: Schema.String },\n /** The fill handle was let go, or the drag cancelled (`completed` false). */\n FillEnded: { completed: Schema.Boolean },\n })\n type Message = typeof Message.Type\n /**\n * What the grid reports to its parent: one cell's committed text, or a\n * paste's, as one change. Turning text into values and writing them is the\n * application's, and so is taking them back: `UndoRequested` and\n * `RedoRequested` carry nothing, since what to undo is the application's\n * history, read when the request arrives.\n */\n const Out = defineTaggedUnion({\n Edited: { row: Schema.String, column: Column, text: Schema.String },\n /** The cells their columns accepted, and those they refused, with why. */\n Pasted: {\n accepted: Schema.Array(CellText),\n refused: Schema.Array(Schema.Struct({ ...CellText.fields, error: Schema.String })),\n },\n UndoRequested: {},\n RedoRequested: {},\n /**\n * A fill: carry `source` on to `to`. What it writes is worked out from the\n * rows by `fill`, which the application holds.\n */\n Filled: FillRequest.fields,\n /**\n * A Shift-click range of rows, from the anchor to the clicked row. Which\n * rows lie between is worked out from the rows by `extendRows`, which the\n * application holds.\n */\n RowsRequested: { from: Schema.String, to: Schema.String },\n })\n type Out = typeof Out.Type\n type Return = Update.ReturnWithOutMessage<Model, Message, Out, never>\n\n const focusTo = (model: Model, address: typeof focus.Address.Type): Model => {\n const next = focus.bundle.update(\n model.focus,\n focus.Message.Focused({ address }),\n undefined,\n ).model\n return next === model.focus ? model : modifyFields(model, { focus: () => next })\n }\n const viewportBy = (model: Model, message: typeof GridViewport.Message.Type): Model => {\n const next = GridViewport.bundle.update(model.viewport, message, undefined).model\n return next === model.viewport ? model : modifyFields(model, { viewport: () => next })\n }\n const columnsBy = (model: Model, next: typeof columnState.Model.Type): Model =>\n next === model.columns ? model : modifyFields(model, { columns: () => next })\n type Selection = Model['selection']\n const selectionBy = (model: Model, next: Selection): Model =>\n next === model.selection ? model : modifyFields(model, { selection: () => next })\n const clearCells = (model: Model): Model =>\n Option.isNone(model.selection.cells)\n ? model\n : selectionBy(model, { ...model.selection, cells: Option.none() })\n type Address = typeof focus.Address.Type\n const isColumn = (column: string): column is keyof Specs & string =>\n Object.hasOwn(options.columns.byId, column)\n /** The address of one of this grid's cells, from its DOM id. */\n const addressOf = (cell: string): Option.Option<Address> =>\n Option.flatMap(GridFocus.cellOf(options.id, cell), ({ row, column }) =>\n isColumn(column) ? Option.some({ row, column }) : Option.none(),\n )\n const pressed = (\n model: Model,\n address: Address,\n shiftKey: boolean,\n toggleKey: boolean,\n ): Return => {\n if (shiftKey && options.cellSelection === true) {\n // The range runs from where it began, or from the focused cell, which stays focused.\n const anchor = Option.getOrElse(\n Option.orElse(\n Option.map(model.selection.cells, cells => cells.anchor),\n () => model.focus.current,\n ),\n () => address,\n )\n return {\n model: selectionBy(model, {\n ...model.selection,\n cells: Option.some({ anchor, focus: address }),\n }),\n }\n }\n const focused = clearCells(focusTo(model, address))\n if (shiftKey && options.rowSelection === 'multiple') {\n // The range runs from the anchor, or from the row focused before the click.\n const from = Option.getOrElse(\n Option.orElse(model.selection.anchor, () =>\n Option.map(model.focus.current, current => current.row),\n ),\n () => address.row,\n )\n // The range is anchored where it runs from, so the next Shift press keeps that end.\n const anchored = Option.isSome(focused.selection.anchor)\n ? focused\n : selectionBy(focused, { ...focused.selection, anchor: Option.some(from) })\n return { model: anchored, outMessage: Out.RowsRequested({ from, to: address.row }) }\n }\n if (toggleKey && options.rowSelection !== undefined) {\n return { model: selectionBy(focused, choose(focused.selection, address.row)) }\n }\n return { model: focused }\n }\n\n // Each editable column's decoder and editor, made once: a draft is accepted\n // when it decodes, and drawn as its schema says.\n type Id = keyof Specs & string\n const decoders = new Map<string, (text: string) => Result.Result<unknown, Schema.SchemaError>>()\n const editors = new Map<string, CellEditor>()\n for (const id of options.columns.ids) {\n const edit = options.columns.byId[id].edit\n if (edit === undefined) continue\n decoders.set(id, Schema.decodeUnknownResult(edit.schema ?? Schema.String))\n editors.set(id, editorOf(edit.schema))\n }\n /** How a column's cells are edited: as text, a number, or a choice; none when it does not edit. */\n const editorFor = (column: Id): Option.Option<CellEditor> =>\n Option.fromUndefinedOr(editors.get(column))\n /** Why a column refuses a text, or none when it takes it. */\n const errorOf = (column: Id, text: string): Option.Option<string> =>\n Option.flatMap(Option.fromUndefinedOr(decoders.get(column)), decode =>\n Result.match(decode(text), {\n onSuccess: () => Option.none(),\n onFailure: error => Option.some(error.message),\n }),\n )\n /**\n * A reported cell's value, decoded by its column's schema, handed to the\n * handler for that column: one for each column that edits, each given its\n * own value type. The grid reports only text its column accepted, so a cell\n * that does not decode, or names a column that does not edit, was not the\n * grid's, and throws.\n */\n const matchEdit = <\n const Handlers extends {\n readonly [K in EditableId<Specs>]: (edited: {\n readonly row: string\n readonly value: EditValue<Specs[K]>\n }) => unknown\n },\n >(\n cell: { readonly row: string; readonly column: Id; readonly text: string },\n handlers: Handlers & {\n readonly [K in Exclude<keyof Handlers, EditableId<Specs>>]: never\n },\n ): ReturnType<Handlers[EditableId<Specs>]> => {\n const decode = decoders.get(cell.column)\n if (decode === undefined) {\n throw new Error(`DataGrid.matchEdit: the ${cell.column} column does not edit.`)\n }\n return Result.match(decode(cell.text), {\n onFailure: error => {\n throw new Error(\n `DataGrid.matchEdit: the ${cell.column} column refuses \"${cell.text}\" (${error.message}); the grid reports only text its column accepted.`,\n )\n },\n // The handlers are keyed by the editable ids, and this column has a decoder,\n // so it is one of them; its value is what that column's schema decodes to.\n onSuccess: value =>\n (\n handlers[cell.column as EditableId<Specs>] as (edited: {\n readonly row: string\n readonly value: unknown\n }) => ReturnType<Handlers[EditableId<Specs>]>\n )({ row: cell.row, value }),\n })\n }\n\n /**\n * Whether a column's new text says what its old text did: the same text,\n * or two that decode to equal values (`01.73` and `1.73`). An edit is\n * judged against the text it began from, not the cell as it is now, so\n * one left as it opened never writes over a change made meanwhile.\n */\n const unchanged = (column: Id, from: string, text: string): boolean =>\n text === from ||\n Option.exists(Option.fromUndefinedOr(decoders.get(column)), decode =>\n Result.match(Result.all([decode(from), decode(text)]), {\n onSuccess: ([before, after]) => Equal.equals(before, after),\n onFailure: () => false,\n }),\n )\n\n /** A choice column's options, or none for a column that is no choice. */\n const optionsOf = (column: Id): Option.Option<ReadonlyArray<string>> =>\n Option.flatMap(\n editorFor(column),\n CellEditor.match({\n Text: () => Option.none(),\n Number: () => Option.none(),\n Date: () => Option.none(),\n Choice: ({ options }) => Option.some(options),\n }),\n )\n /** The option after `current` that starts with `key`, ignoring case, wrapping round; else `current`. */\n const typedOption = (options: ReadonlyArray<string>, current: string, key: string): string => {\n const start = options.indexOf(current)\n const wanted = key.toLowerCase()\n for (let offset = 1; offset <= options.length; offset++) {\n const option = options[(start + offset) % options.length]!\n if (option.toLowerCase().startsWith(wanted)) return option\n }\n return current\n }\n const page = 10\n const steppedIndex = (by: ChoiceStep, at: number, count: number) =>\n Math.max(\n 0,\n Math.min(\n count - 1,\n {\n next: at + 1,\n previous: at - 1,\n first: 0,\n last: count - 1,\n pageNext: at + page,\n pagePrevious: at - page,\n }[by],\n ),\n )\n\n const sameCell = (a: Address, b: Address): boolean => a.row === b.row && a.column === b.column\n /**\n * Cells laid by a paste or a fill, as their columns judge them: those that\n * pass and those refused, with why. A cell on a column that does not edit,\n * or one its text leaves unchanged, is dropped.\n */\n const judged = (cells: ReadonlyArray<typeof PastedCell.Type>) => {\n const accepted: Array<typeof CellText.Type> = []\n const refused: Array<typeof CellText.Type & { readonly error: string }> = []\n for (const { from, ...cell } of cells) {\n if (options.columns.byId[cell.column].edit === undefined) continue\n if (unchanged(cell.column, from, cell.text)) continue\n Option.match(errorOf(cell.column, cell.text), {\n onNone: () => accepted.push(cell),\n onSome: error => refused.push({ ...cell, error }),\n })\n }\n return { accepted, refused }\n }\n /**\n * Ends an edit with its draft: none to report when nothing was edited or\n * the draft is unchanged, `refused` with the column's error when the draft\n * does not pass, or the edit closed and `Edited` to report.\n */\n const finish = (\n model: Model,\n ): { readonly model: Model; readonly edited: Option.Option<Out>; readonly refused: boolean } =>\n Option.match(model.editing, {\n onNone: () => ({ model, edited: Option.none(), refused: false }),\n onSome: editing => {\n const { address, from, draft } = editing\n // Checked before the column's error, so a cell holding text its column\n // now refuses can still be opened and left as it was.\n if (unchanged(address.column, from, draft)) {\n return {\n model: modifyFields(model, { editing: () => Option.none() }),\n edited: Option.none(),\n refused: false,\n }\n }\n return Option.match(errorOf(address.column, draft), {\n onSome: message => ({\n model: modifyFields(model, {\n editing: () => Option.some({ ...editing, error: Option.some(message) }),\n }),\n edited: Option.none(),\n refused: true,\n }),\n onNone: () => ({\n model: modifyFields(model, { editing: () => Option.none() }),\n edited: Option.some(\n Out.Edited({ row: address.row, column: address.column, text: draft }),\n ),\n refused: false,\n }),\n })\n },\n })\n /**\n * Keeps a draft: the column refusing it leaves the edit open with the\n * error; otherwise the edit ends, focus goes to `next`, and `Edited` is\n * reported unless the draft is unchanged.\n */\n const committed = (\n model: Model,\n next: Option.Option<Address>,\n reveal: Option.Option<typeof Offsets.Type>,\n ): Return => {\n const finished = finish(model)\n if (finished.refused) return { model: finished.model }\n const moved = Option.match(next, {\n onNone: () => finished.model,\n onSome: address => focusTo(finished.model, address),\n })\n return {\n model: moved,\n ...Option.match(finished.edited, {\n onNone: () => ({}),\n onSome: outMessage => ({ outMessage }),\n }),\n commands: Option.match(reveal, {\n onNone: () => [],\n onSome: offsets => [GridViewport.scrollTo(options.id, offsets)],\n }),\n }\n }\n\n /**\n * The pointer leaving an edit commits it first, as a spreadsheet does; a\n * draft the column refuses keeps the edit, and the pointer's change waits.\n */\n const afterEdit = (model: Model, then: (settled: Model) => Return): Return => {\n const finished = finish(model)\n if (finished.refused) return { model: finished.model }\n const next = then(finished.model)\n return Option.match(finished.edited, {\n onNone: () => next,\n onSome: outMessage => ({ ...next, outMessage }),\n })\n }\n\n // Single mode replaces, as a radio group does; RowsCleared empties it.\n const choose = (selection: Selection, row: string): Selection => {\n if (options.rowSelection === 'single') {\n return { ...selection, rows: RowSelection.Keys({ keys: [row] }), anchor: Option.some(row) }\n }\n return {\n ...selection,\n rows: GridSelection.toggle(selection.rows, row),\n anchor: Option.some(row),\n }\n }\n\n /**\n * The items of a column's menu, in order: pin to each other region, hide\n * when it can be hidden, and show each hidden column. An item is offered\n * only when it changes something.\n */\n const menuItems = (\n state: Model['columns'],\n column: keyof Specs & string,\n ): ReadonlyArray<MenuItem> => [\n ...(['start', 'end', 'center'] as const)\n .filter(region => region !== columnState.regionOf(state, column))\n .map(region => MenuItem.Pin({ region })),\n ...(columnState.hide(state, column) === state ? [] : [MenuItem.Hide()]),\n ...state.hidden.map(other => MenuItem.Show({ column: other })),\n ]\n /** The column Message a menu item stands for. */\n const messageOf = (\n state: Model['columns'],\n column: keyof Specs & string,\n item: MenuItem,\n ): Message =>\n MenuItem.match(item, {\n // Pinned, it goes next to the center; unpinned, to the center's edge it came from.\n Pin: ({ region }) =>\n Message.ColumnMoved({\n column,\n region,\n index: {\n start: state.start.length,\n end: 0,\n center: columnState.regionOf(state, column) === 'start' ? 0 : state.center.length,\n }[region],\n }),\n Hide: () => Message.ColumnHidden({ column }),\n Show: ({ column: other }) => Message.ColumnShown({ column: other }),\n })\n const closeMenu = (model: Model): Model =>\n Option.isNone(model.menu) ? model : modifyFields(model, { menu: () => Option.none() })\n\n const bundle = Bundle.make('DataGrid', {\n Model,\n Message,\n init: () => ({\n model: {\n focus: focus.bundle.init(undefined).model,\n viewport: GridViewport.bundle.init(undefined).model,\n columns: columnState.initial(),\n resizing: Option.none(),\n dragging: Option.none(),\n menu: Option.none(),\n filling: Option.none(),\n selection: { rows: GridSelection.none, anchor: Option.none(), cells: Option.none() },\n editing: Option.none(),\n },\n }),\n update: (model: Model, message: Message): Return =>\n Message.match(message, {\n // A plain click or key is a single cell again: any range it leaves goes.\n Focused: ({ address }): Return =>\n afterEdit(model, settled => ({ model: clearCells(focusTo(settled, address)) })),\n Moved: ({ address, reveal }): Return => ({\n model: clearCells(focusTo(model, address)),\n commands: Option.match(reveal, {\n onNone: () => [],\n onSome: offsets => [GridViewport.scrollTo(options.id, offsets)],\n }),\n }),\n HeaderFocused: ({ column, reveal }): Return => {\n const next = focus.bundle.update(\n model.focus,\n focus.Message.HeaderFocused({ column }),\n undefined,\n ).model\n return {\n model: next === model.focus ? model : modifyFields(model, { focus: () => next }),\n commands: Option.match(reveal, {\n onNone: () => [],\n onSome: offsets => [GridViewport.scrollTo(options.id, offsets)],\n }),\n }\n },\n Measured: (fields): Return => ({\n model: viewportBy(model, GridViewport.Message.Measured(fields)),\n }),\n Revealed: (fields): Return => ({\n model: viewportBy(model, GridViewport.Message.Revealed(fields)),\n }),\n ColumnResized: ({ column, width }): Return => ({\n model: columnsBy(model, columnState.resize(model.columns, column, width)),\n }),\n // What was on a hidden column goes with it: its edit, its header's focus, its menu.\n ColumnHidden: ({ column }): Return => {\n const hidden = columnsBy(model, columnState.hide(model.columns, column))\n if (hidden === model) return { model }\n const off = (on: Option.Option<string>) => Option.contains(on, column)\n return {\n model: modifyFields(hidden, {\n editing: editing =>\n off(Option.map(editing, each => each.address.column)) ? Option.none() : editing,\n focus: current =>\n off(current.header) ? { ...current, header: Option.none() } : current,\n menu: menu => (off(Option.map(menu, each => each.column)) ? Option.none() : menu),\n }),\n }\n },\n ColumnShown: ({ column }): Return => ({\n model: columnsBy(model, columnState.show(model.columns, column)),\n }),\n ColumnMoved: ({ column, region, index }): Return => ({\n model: columnsBy(model, columnState.move(model.columns, column, region, index)),\n }),\n // Each move is measured from where the drag began, so the width is the\n // pointer's place now, not a sum of every step on the way.\n ResizeStarted: ({ column }): Return => ({\n model:\n options.columns.byId[column].resizable === false\n ? model\n : modifyFields(model, {\n resizing: () =>\n Option.some({ column, from: columnState.widthOf(model.columns)(column) }),\n }),\n }),\n ResizeMoved: ({ delta }): Return => ({\n model: Option.match(model.resizing, {\n onNone: () => model,\n onSome: ({ column, from }) =>\n columnsBy(model, columnState.resize(model.columns, column, from + delta)),\n }),\n }),\n MenuOpened: ({ column }): Return =>\n model.columns.hidden.includes(column)\n ? { model }\n : afterEdit(model, settled => {\n const focused = focus.bundle.update(\n settled.focus,\n focus.Message.HeaderFocused({ column }),\n undefined,\n ).model\n return {\n model: modifyFields(settled, {\n focus: () => focused,\n menu: () => Option.some({ column, active: 0 }),\n }),\n }\n }),\n MenuMoved: ({ active }): Return => ({\n model: Option.match(model.menu, {\n onNone: () => model,\n onSome: menu => {\n const last = menuItems(model.columns, menu.column).length - 1\n const clamped = Math.min(Math.max(0, Math.trunc(active)), Math.max(0, last))\n return clamped === menu.active\n ? model\n : modifyFields(model, { menu: () => Option.some({ ...menu, active: clamped }) })\n },\n }),\n }),\n MenuChosen: ({ index }): Return =>\n Option.match(model.menu, {\n onNone: () => ({ model }),\n onSome: ({ column }) =>\n Option.match(Option.fromUndefinedOr(menuItems(model.columns, column)[index]), {\n onNone: () => ({ model: closeMenu(model) }),\n onSome: item =>\n bundle.update(\n closeMenu(model),\n messageOf(model.columns, column, item),\n undefined,\n ),\n }),\n }),\n MenuClosed: (): Return => ({ model: closeMenu(model) }),\n ColumnDragStarted: ({ header }): Return => ({\n model: Option.match(\n Option.filter(\n Option.flatMap(GridFocus.headerOf(options.id, header), column =>\n isColumn(column) ? Option.some(column) : Option.none(),\n ),\n column => !model.columns.hidden.includes(column),\n ),\n {\n onNone: () => model,\n onSome: column =>\n modifyFields(model, { dragging: () => Option.some({ column, delta: 0 }) }),\n },\n ),\n }),\n ColumnDragged: ({ delta }): Return => ({\n model: Option.match(model.dragging, {\n onNone: () => model,\n onSome: dragging =>\n dragging.delta === delta\n ? model\n : modifyFields(model, { dragging: () => Option.some({ ...dragging, delta }) }),\n }),\n }),\n // The drop is worked out from the columns as they stand now, not as\n // they stood when the pointer last moved.\n ColumnDragEnded: ({ completed }): Return => ({\n model: Option.match(model.dragging, {\n onNone: () => model,\n onSome: ({ column, delta }) => {\n const dropped = completed\n ? columnsBy(\n model,\n columnState.move(\n model.columns,\n column,\n columnState.regionOf(model.columns, column),\n columnState.dropAt(model.columns, column, delta),\n ),\n )\n : model\n return modifyFields(dropped, { dragging: () => Option.none() })\n },\n }),\n }),\n RowSelected: ({ row }): Return => ({\n model:\n options.rowSelection === undefined\n ? model\n : selectionBy(model, choose(model.selection, row)),\n }),\n RowsExtended: ({ rows, to }): Return => {\n if (options.rowSelection !== 'multiple') return { model }\n const added = GridSelection.add(model.selection.rows, rows)\n const anchor = Option.orElse(model.selection.anchor, () => Option.some(to))\n return {\n model:\n added === model.selection.rows && Option.isSome(model.selection.anchor)\n ? model\n : selectionBy(model, { ...model.selection, rows: added, anchor }),\n }\n },\n AllRowsSelected: (): Return => ({\n model:\n options.rowSelection !== 'multiple'\n ? model\n : selectionBy(model, {\n ...model.selection,\n rows: RowSelection.AllExcept({ except: [] }),\n }),\n }),\n RowsCleared: (): Return => {\n const empty = RowSelection.match(model.selection.rows, {\n Keys: ({ keys }) => keys.length === 0,\n AllExcept: () => false,\n })\n return {\n model:\n empty && Option.isNone(model.selection.anchor)\n ? model\n : selectionBy(model, {\n ...model.selection,\n rows: GridSelection.none,\n anchor: Option.none(),\n }),\n }\n },\n CellsSelected: ({ anchor, focus: far, reveal }): Return =>\n options.cellSelection === true\n ? {\n model: selectionBy(model, {\n ...model.selection,\n cells: Option.some({ anchor, focus: far }),\n }),\n commands: Option.match(reveal, {\n onNone: () => [],\n onSome: offsets => [GridViewport.scrollTo(options.id, offsets)],\n }),\n }\n : { model },\n CellPressed: ({ cell, shiftKey, toggleKey }): Return =>\n Option.match(addressOf(cell), {\n onNone: () => ({ model }),\n onSome: address =>\n Option.exists(model.editing, editing => sameCell(editing.address, address))\n ? { model }\n : afterEdit(model, settled => pressed(settled, address, shiftKey, toggleKey)),\n }),\n EditStarted: ({ address, draft }): Return =>\n options.columns.byId[address.column].edit === undefined\n ? { model }\n : {\n model: modifyFields(clearCells(focusTo(model, address)), {\n editing: () => Option.some({ address, from: draft, draft, error: Option.none() }),\n }),\n },\n EditTyped: ({ address, text, from }): Return => {\n if (options.columns.byId[address.column].edit === undefined) return { model }\n const open = Option.filter(model.editing, editing => sameCell(editing.address, address))\n // On a choice a key finds an option; elsewhere it is typed.\n const typed = (draft: string) =>\n Option.match(optionsOf(address.column), {\n onNone: () => draft + text,\n onSome: choices => typedOption(choices, draft, text),\n })\n const editing = Option.match(open, {\n onNone: () => ({\n address,\n from,\n draft: Option.isSome(optionsOf(address.column)) ? typed(from) : text,\n error: Option.none(),\n }),\n onSome: edit => ({ ...edit, draft: typed(edit.draft), error: Option.none() }),\n })\n return {\n model: modifyFields(clearCells(focusTo(model, address)), {\n editing: () => Option.some(editing),\n }),\n }\n },\n EditChanged: ({ draft }): Return => ({\n model: Option.match(model.editing, {\n onNone: () => model,\n onSome: editing =>\n editing.draft === draft && Option.isNone(editing.error)\n ? model\n : modifyFields(model, {\n editing: () => Option.some({ ...editing, draft, error: Option.none() }),\n }),\n }),\n }),\n EditStepped: ({ by }): Return =>\n Option.match(model.editing, {\n onNone: () => ({ model }),\n onSome: editing =>\n Option.match(optionsOf(editing.address.column), {\n onNone: () => ({ model }),\n onSome: choices => {\n const draft =\n choices[steppedIndex(by, choices.indexOf(editing.draft), choices.length)]\n return draft === undefined || draft === editing.draft\n ? { model }\n : {\n model: modifyFields(model, {\n editing: () => Option.some({ ...editing, draft, error: Option.none() }),\n }),\n }\n },\n }),\n }),\n EditChosen: ({ draft }): Return =>\n Option.match(model.editing, {\n onNone: () => ({ model }),\n onSome: editing =>\n committed(\n modifyFields(model, { editing: () => Option.some({ ...editing, draft }) }),\n Option.none(),\n Option.none(),\n ),\n }),\n EditCommitted: ({ next, reveal }): Return => committed(model, next, reveal),\n // An edit in progress has the keyboard and the clipboard: a paste then is the field's.\n Pasted: ({ cells }): Return => {\n if (Option.isSome(model.editing) || cells.length === 0) return { model }\n const { accepted, refused } = judged(cells)\n return accepted.length === 0 && refused.length === 0\n ? { model }\n : { model, outMessage: Out.Pasted({ accepted, refused }) }\n },\n FillRequested: (request): Return =>\n Option.isSome(model.editing)\n ? { model }\n : { model, outMessage: Out.Filled({ source: request.source, to: request.to }) },\n FillStarted: (): Return => {\n if (Option.isSome(model.editing)) return { model }\n // The range, or the focused cell as a range of one.\n const source = Option.orElse(model.selection.cells, () =>\n Option.map(model.focus.current, address => ({ anchor: address, focus: address })),\n )\n return {\n model: Option.match(source, {\n onNone: () => model,\n onSome: range =>\n modifyFields(model, {\n filling: () => Option.some({ source: range, to: range.focus }),\n }),\n }),\n }\n },\n FillDragged: ({ cell }): Return => ({\n model: Option.match(\n Option.zipWith(model.filling, addressOf(cell), (filling, to) => ({ filling, to })),\n {\n onNone: () => model,\n onSome: ({ filling, to }) =>\n sameCell(filling.to, to)\n ? model\n : modifyFields(model, { filling: () => Option.some({ ...filling, to }) }),\n },\n ),\n }),\n // Where the fill lands is worked out by `fill` from the rows as they\n // are when it arrives, not from the frame the pointer was let go over.\n FillEnded: ({ completed }): Return =>\n Option.match(model.filling, {\n onNone: () => ({ model }),\n onSome: ({ source, to }) => {\n const ended = modifyFields(model, { filling: () => Option.none() })\n return completed\n ? { model: ended, outMessage: Out.Filled({ source, to }) }\n : { model: ended }\n },\n }),\n UndoRequested: (): Return =>\n Option.isSome(model.editing) ? { model } : { model, outMessage: Out.UndoRequested() },\n RedoRequested: (): Return =>\n Option.isSome(model.editing) ? { model } : { model, outMessage: Out.RedoRequested() },\n EditCancelled: (): Return => ({\n model: Option.isNone(model.editing)\n ? model\n : modifyFields(model, { editing: () => Option.none() }),\n }),\n\n CellsCleared: (): Return => ({ model: clearCells(model) }),\n ResizeEnded: ({ completed }): Return => ({\n model: Option.match(model.resizing, {\n onNone: () => model,\n onSome: ({ column, from }) => {\n const settled = completed\n ? model\n : columnsBy(model, columnState.resize(model.columns, column, from))\n return modifyFields(settled, { resizing: () => Option.none() })\n },\n }),\n }),\n }),\n })\n\n // One projection per rows model and column state, so the view and the\n // application's own reads of the same render share it.\n const projections = new WeakMap<\n RowModel<Row>,\n {\n readonly state: Model['columns']\n readonly projection: GridProjection<Row, keyof Specs & string>\n }\n >()\n /** The text an edit of a cell begins from: its column's `draft`, or the text it shows. */\n const draftOf = (projection: GridProjection<Row, Id>, address: Address): string =>\n Option.match(\n Option.flatMap(projection.rowIndex(address.row), index => projection.rows.rowAt(index)),\n {\n onNone: () => '',\n onSome: row => {\n const column = options.columns.byId[address.column]\n const authored = column.edit?.draft?.(row)\n if (authored !== undefined) return authored\n const value = column.value(row)\n // A date input reads `YYYY-MM-DD` in the local calendar. `toISOString`\n // is the UTC day, so a local midnight opens the field on the wrong one.\n if (value instanceof Date && !Number.isNaN(value.getTime())) {\n const editor = editorFor(address.column)\n if (Option.exists(editor, CellEditor.guards.Date)) {\n const month = String(value.getMonth() + 1).padStart(2, '0')\n const day = String(value.getDate()).padStart(2, '0')\n return `${value.getFullYear()}-${month}-${day}`\n }\n }\n return Columns.textOf(value)\n },\n },\n )\n\n /**\n * What an `Out.Filled` writes, judged as a paste's cells are: those their\n * columns accept and those they refuse, over `rows` as they are now and the\n * grid's column state. Nothing when `to` is inside the source.\n */\n const fill = (\n rows: RowModel<Row>,\n state: { readonly columns: Model['columns'] },\n request: typeof FillRequest.Type,\n ) => {\n const projection = project(rows, state.columns)\n return Option.match(Fill.plan(projection, request), {\n onNone: () => judged([]),\n onSome: plan =>\n judged(\n Fill.cells(projection, plan, {\n editable: column => options.columns.byId[column].edit !== undefined,\n from: address => draftOf(projection, address),\n }),\n ),\n })\n }\n\n /**\n * The grid's Model with an `Out.RowsRequested` range added to its row\n * selection, over `rows` as they are now.\n */\n const extendRows = (\n rows: RowModel<Row>,\n model: Model,\n request: { readonly from: string; readonly to: string },\n ): Model =>\n bundle.update(\n model,\n Message.RowsExtended({\n rows: GridSelection.rowsBetween(project(rows, model.columns), request.from, request.to),\n to: request.to,\n }),\n undefined,\n ).model\n\n /** The grid as presented: the rows through the column state in the Model. */\n const project = (\n rows: RowModel<Row>,\n state: Model['columns'],\n ): GridProjection<Row, keyof Specs & string> => {\n const cached = projections.get(rows)\n if (cached !== undefined && cached.state === state) return cached.projection\n const projection = GridProjection.make({ rows, columns: options.columns, layout: state })\n projections.set(rows, { state, projection })\n return projection\n }\n\n /**\n * The rows and columns the view draws for this input, as the view itself\n * works them out: a count of what is drawn, read from here, is what is drawn.\n */\n const window = (input: {\n readonly rows: RowModel<Row>\n readonly state: { readonly viewport: Viewport; readonly columns: Model['columns'] }\n readonly rowHeight: number\n readonly headerHeight: number\n readonly overscan?: { readonly rows?: number; readonly columns?: number }\n }): GridWindow<keyof Specs & string> =>\n VirtualGrid.window({\n projection: project(input.rows, input.state.columns),\n rowHeight: input.rowHeight,\n width: columnState.widthOf(input.state.columns),\n headerHeight: input.headerHeight,\n viewport: input.state.viewport,\n ...(input.overscan === undefined ? {} : { overscan: input.overscan }),\n })\n\n return {\n id: options.id,\n matchEdit,\n editorFor,\n MenuItem,\n menuItems,\n columns: options.columns,\n rowSelection: options.rowSelection,\n cellSelection: options.cellSelection === true,\n focus,\n columnState,\n project,\n window,\n fill,\n extendRows,\n draftOf,\n Out,\n Model,\n Message,\n bundle,\n }\n}\n\nexport const DataGrid = { make }\n\n/** What `DataGrid.make` returns for these columns: the grid a view draws. */\nexport type DataGridOf<Row, Specs extends Record<string, ColumnSpec<Row, unknown>>> = ReturnType<\n typeof make<Row, Specs>\n>\n"],"mappings":";;;;;;;;;;;;;;AAuBA,MAAM,UAAU,OAAO,OAAO;CAAE,KAAK,OAAO;CAAQ,MAAM,OAAO;AAAO,CAAC;;AAGzE,MAAM,cAAc;CAAC;CAAQ;CAAY;CAAS;CAAQ;CAAY;AAAc;;;;;;;;;;;;AAcpF,MAAM,QAAqE,YAKrE;CACJ,MAAM,QAAQ,UAAU,KAAK,QAAQ,OAAO;CAC5C,MAAM,cAAc,YAAY,KAAK,QAAQ,OAAO;CACpD,MAAM,SAAS,MAAM,QAAQ,OAAO;CACpC,MAAM,WAAW,OAAO,OAAO;EAAE,KAAK,OAAO;EAAQ,QAAQ;EAAQ,MAAM,OAAO;CAAO,CAAC;CAC1F,MAAM,aAAa,OAAO,OAAO;EAAE,GAAG,SAAS;EAAQ,MAAM,OAAO;CAAO,CAAC;CAC5E,MAAM,QAAQ,OAAO,OAAO;EAAE,QAAQ,MAAM;EAAS,OAAO,MAAM;CAAQ,CAAC;;CAE3E,MAAM,cAAc,OAAO,OAAO;EAAE,QAAQ;EAAO,IAAI,MAAM;CAAQ,CAAC;CACtE,MAAM,QAAQ,OAAO,OAAO;EAC1B,OAAO,MAAM;EACb,UAAU,aAAa;EACvB,SAAS,YAAY;;EAErB,UAAU,OAAO,iBAAiB,OAAO,OAAO;GAAE,QAAQ;GAAQ,MAAM,OAAO;EAAO,CAAC,CAAC;;;;;EAKxF,UAAU,OAAO,iBAAiB,OAAO,OAAO;GAAE,QA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EACA;EACA;EACA;CACF;AACF;AAEA,MAAa,WAAW,EAAE,KAAK"}
@@ -0,0 +1,13 @@
1
+ import { CellEditor, Column, ColumnEdit, ColumnId, ColumnSpec, Columns, EditableId } from "./columns.js";
2
+ import { ColumnLayout } from "./layout.js";
3
+ import { RowCount, RowModel, RowStatus, addressableRows } from "./rows.js";
4
+ import { CellAddress, CellBox, CellOffset, CellPosition, GridProjection, ProjectionOptions } from "./projection.js";
5
+ import { ColumnState, Region, Restored } from "./columnState.js";
6
+ import { Fill, FillPlan, FillRequest } from "./fill.js";
7
+ import { Direction, GridFocus, KeyOptions } from "./focus.js";
8
+ import { CellRange, ExtendOptions, GridSelection, RowSelection } from "./selection.js";
9
+ import { GridViewport } from "./viewport.js";
10
+ import { AxisWindow, Geometry, GridWindow, RevealOptions, Viewport, VirtualGrid, WindowOptions } from "./virtual.js";
11
+ import { CellText, Clipboard, PastedCell } from "./clipboard.js";
12
+ import { DataGrid, DataGridOf } from "./grid.js";
13
+ export { type AxisWindow, CellAddress, type CellBox, CellEditor, type CellOffset, type CellPosition, type CellRange, type CellText, Clipboard, type Column, type ColumnEdit, type ColumnId, ColumnLayout, type ColumnSpec, ColumnState, Columns, DataGrid, type DataGridOf, type Direction, type EditableId, type ExtendOptions, Fill, type FillPlan, type FillRequest, type Geometry, GridFocus, GridProjection, GridSelection, GridViewport, type GridWindow, type KeyOptions, type PastedCell, type ProjectionOptions, type Region, type Restored, type RevealOptions, RowCount, RowModel, RowSelection, RowStatus, type Viewport, VirtualGrid, type WindowOptions, addressableRows };
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import { CellEditor, Columns } from "./columns.js";
2
+ import { ColumnLayout } from "./layout.js";
3
+ import { RowCount, RowModel, RowStatus, addressableRows } from "./rows.js";
4
+ import { CellAddress, GridProjection } from "./projection.js";
5
+ import { ColumnState } from "./columnState.js";
6
+ import { Fill } from "./fill.js";
7
+ import { GridFocus } from "./focus.js";
8
+ import { GridSelection, RowSelection } from "./selection.js";
9
+ import { GridViewport } from "./viewport.js";
10
+ import { VirtualGrid } from "./virtual.js";
11
+ import { Clipboard } from "./clipboard.js";
12
+ import { DataGrid } from "./grid.js";
13
+ export { CellAddress, CellEditor, Clipboard, ColumnLayout, ColumnState, Columns, DataGrid, Fill, GridFocus, GridProjection, GridSelection, GridViewport, RowCount, RowModel, RowSelection, RowStatus, VirtualGrid, addressableRows };
@@ -0,0 +1,20 @@
1
+ import { ColumnSpec, Columns } from "./columns.js";
2
+ /**
3
+ * Where each column stands: the start, center and end regions in display
4
+ * order, and which columns are hidden. Hiding keeps a column's place, so
5
+ * showing it again puts it back where it was. The grid owns this state; it
6
+ * holds column ids only, so it can be saved and restored.
7
+ */
8
+ export interface ColumnLayout<Id extends string> {
9
+ /** Pinned to the start edge, outside horizontal scrolling. */
10
+ readonly start: ReadonlyArray<Id>;
11
+ readonly center: ReadonlyArray<Id>;
12
+ /** Pinned to the end edge, outside horizontal scrolling. */
13
+ readonly end: ReadonlyArray<Id>;
14
+ readonly hidden: ReadonlyArray<Id>;
15
+ }
16
+ export declare const ColumnLayout: {
17
+ /** The layout the columns declare: definition order, each in its `pinned` region. */
18
+ initial: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(columns: Columns<Row, Specs>) => ColumnLayout<keyof Specs & string>;
19
+ };
20
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","names":[],"sources":["../src/layout.ts"],"mappings":";;;;;;;iBAQiB,aAAa;;WAEnB,OAAO,cAAc;WACrB,QAAQ,cAAc;;WAEtB,KAAK,cAAc;WACnB,QAAQ,cAAc;;qBAGpB;;EAEX,UAAU,KAAK,cAAc,eAAe,WAAW,gBAAc,SAC1D,QAAQ,KAAK,WACrB,mBAAmB"}
package/dist/layout.js ADDED
@@ -0,0 +1,27 @@
1
+ // src/layout.ts
2
+ const ColumnLayout = {
3
+ /** The layout the columns declare: definition order, each in its `pinned` region. */
4
+ initial: (columns) => {
5
+ const start = [];
6
+ const center = [];
7
+ const end = [];
8
+ const hidden = [];
9
+ const pinned = {
10
+ start,
11
+ end
12
+ };
13
+ for (const id of columns.ids) {
14
+ const column = columns.byId[id];
15
+ (column.pinned === void 0 ? center : pinned[column.pinned]).push(id);
16
+ if (column.hidden === true) hidden.push(id);
17
+ }
18
+ return {
19
+ start,
20
+ center,
21
+ end,
22
+ hidden
23
+ };
24
+ } };
25
+ export { ColumnLayout };
26
+
27
+ //# sourceMappingURL=layout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.js","names":[],"sources":["../src/layout.ts"],"sourcesContent":["import type { Columns, ColumnSpec } from './columns.js'\n\n/**\n * Where each column stands: the start, center and end regions in display\n * order, and which columns are hidden. Hiding keeps a column's place, so\n * showing it again puts it back where it was. The grid owns this state; it\n * holds column ids only, so it can be saved and restored.\n */\nexport interface ColumnLayout<Id extends string> {\n /** Pinned to the start edge, outside horizontal scrolling. */\n readonly start: ReadonlyArray<Id>\n readonly center: ReadonlyArray<Id>\n /** Pinned to the end edge, outside horizontal scrolling. */\n readonly end: ReadonlyArray<Id>\n readonly hidden: ReadonlyArray<Id>\n}\n\nexport const ColumnLayout = {\n /** The layout the columns declare: definition order, each in its `pinned` region. */\n initial: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(\n columns: Columns<Row, Specs>,\n ): ColumnLayout<keyof Specs & string> => {\n type Id = keyof Specs & string\n const start: Array<Id> = []\n const center: Array<Id> = []\n const end: Array<Id> = []\n const hidden: Array<Id> = []\n const pinned = { start, end }\n for (const id of columns.ids) {\n const column = columns.byId[id]\n ;(column.pinned === undefined ? center : pinned[column.pinned]).push(id)\n if (column.hidden === true) hidden.push(id)\n }\n return { start, center, end, hidden }\n },\n}\n"],"mappings":";AAiBA,MAAa,eAAe;;AAE1B,UACE,YACuC;CAEvC,MAAM,QAAmB,CAAC;CAC1B,MAAM,SAAoB,CAAC;CAC3B,MAAM,MAAiB,CAAC;CACxB,MAAM,SAAoB,CAAC;CAC3B,MAAM,SAAS;EAAE;EAAO;CAAI;CAC5B,KAAK,MAAM,MAAM,QAAQ,KAAK;EAC5B,MAAM,SAAS,QAAQ,KAAK;EAC3B,CAAC,OAAO,WAAW,KAAA,IAAY,SAAS,OAAO,OAAO,QAAA,CAAS,KAAK,EAAE;EACvE,IAAI,OAAO,WAAW,MAAM,OAAO,KAAK,EAAE;CAC5C;CACA,OAAO;EAAE;EAAO;EAAQ;EAAK;CAAO;AACtC,EACF"}
@@ -0,0 +1,87 @@
1
+ import { Option, Schema } from "effect";
2
+ import { ColumnSpec, Columns } from "./columns.js";
3
+ import { ColumnLayout } from "./layout.js";
4
+ import { RowCount, RowModel } from "./rows.js";
5
+ /** A cell named by identity, so it stays the same cell through a sort or a reorder. */
6
+ export interface CellAddress<Id extends string> {
7
+ readonly row: string;
8
+ readonly column: Id;
9
+ }
10
+ export declare const CellAddress: {
11
+ /**
12
+ * An address as stored or sent: the row key as text, and the column as one
13
+ * of these columns' ids, so a saved address naming a removed column fails
14
+ * to decode instead of naming nothing.
15
+ */
16
+ schema: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(columns: Columns<Row, Specs>) => Schema.Struct<{
17
+ readonly row: Schema.String;
18
+ readonly column: Schema.Literals<readonly (keyof Specs & string)[]>;
19
+ }>;
20
+ };
21
+ /** Where a cell is drawn now: its row index, and its column's index in display order. */
22
+ export interface CellPosition {
23
+ readonly row: number;
24
+ readonly column: number;
25
+ }
26
+ /** A rectangle of cells: row indexes `[start, end)` and the columns it spans, in display order. */
27
+ export interface CellBox<Id extends string> {
28
+ readonly rows: {
29
+ readonly start: number;
30
+ readonly end: number;
31
+ };
32
+ readonly columns: ReadonlyArray<Id>;
33
+ }
34
+ export interface CellOffset {
35
+ readonly rows?: number;
36
+ readonly columns?: number;
37
+ }
38
+ /**
39
+ * The grid as presented: rows in the application's order, crossed with the
40
+ * visible columns in display order. It is the one source of geometry for
41
+ * focus, selection, virtualization and the clipboard; none of them reads
42
+ * positions from the DOM. A pure value, cheap to rebuild: it reads the
43
+ * column layout once and asks the row model for rows only on lookup.
44
+ *
45
+ * Every lookup is an `Option`. A cell is absent when its column is hidden,
46
+ * its row is gone, or its row is in range but not loaded yet.
47
+ */
48
+ export interface GridProjection<Row, Id extends string> {
49
+ readonly rows: RowModel<Row>;
50
+ readonly rowCount: RowCount;
51
+ /** Visible columns in display order: the start region, the center, the end. */
52
+ readonly columns: ReadonlyArray<Id>;
53
+ /** The visible columns of each region, in display order. */
54
+ readonly start: ReadonlyArray<Id>;
55
+ readonly center: ReadonlyArray<Id>;
56
+ readonly end: ReadonlyArray<Id>;
57
+ columnIndex(id: Id): Option.Option<number>;
58
+ rowIndex(key: string): Option.Option<number>;
59
+ cellAt(position: CellPosition): Option.Option<CellAddress<Id>>;
60
+ positionOf(address: CellAddress<Id>): Option.Option<CellPosition>;
61
+ /**
62
+ * The cell `offset` away, stopping at the grid's edges. A fractional offset
63
+ * (a page of rows worked out from a height) drops its fraction.
64
+ */
65
+ moveBy(address: CellAddress<Id>, offset: CellOffset): Option.Option<CellAddress<Id>>;
66
+ rowStart(address: CellAddress<Id>): Option.Option<CellAddress<Id>>;
67
+ rowEnd(address: CellAddress<Id>): Option.Option<CellAddress<Id>>;
68
+ first(): Option.Option<CellAddress<Id>>;
69
+ last(): Option.Option<CellAddress<Id>>;
70
+ /** The rectangle two cells span, in either order. */
71
+ box(anchor: CellAddress<Id>, focus: CellAddress<Id>): Option.Option<CellBox<Id>>;
72
+ }
73
+ export interface ProjectionOptions<Row, Specs extends Record<string, ColumnSpec<Row, unknown>>> {
74
+ readonly rows: RowModel<Row>;
75
+ readonly columns: Columns<Row, Specs>;
76
+ readonly layout: ColumnLayout<keyof Specs & string>;
77
+ }
78
+ export declare const GridProjection: {
79
+ /**
80
+ * Projects rows through a column layout. A layout saved before a column
81
+ * was added does not mention it, so the column joins the center region in
82
+ * definition order; an id the columns do not define, or one named twice,
83
+ * keeps only its first place.
84
+ */
85
+ make: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(options: ProjectionOptions<Row, Specs>) => GridProjection<Row, keyof Specs & string>;
86
+ };
87
+ //# sourceMappingURL=projection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.d.ts","names":[],"sources":["../src/projection.ts"],"mappings":";;;;;iBAMiB,YAAY;WAClB;WACA,QAAQ;;qBAGN;;;;;;EAMX,SAAS,KAAK,cAAc,eAAe,WAAW,gBAAc,SACzD,QAAQ,KAAK,WAAM,OAAA;;;;;;iBAKf;WACN;WACA;;;iBAIM,QAAQ;WACd;aAAiB;aAAwB;;WACzC,SAAS,cAAc;;iBAGjB;WACN;WACA;;;;;;;;;;;;iBAaM,eAAe,KAAK;WAC1B,MAAM,SAAS;WACf,UAAU;;WAEV,SAAS,cAAc;;WAEvB,OAAO,cAAc;WACrB,QAAQ,cAAc;WACtB,KAAK,cAAc;EAC5B,YAAY,IAAI,KAAK,OAAO;EAC5B,SAAS,cAAc,OAAO;EAC9B,OAAO,UAAU,eAAe,OAAO,OAAO,YAAY;EAC1D,WAAW,SAAS,YAAY,MAAM,OAAO,OAAO;;;;;EAKpD,OAAO,SAAS,YAAY,KAAK,QAAQ,aAAa,OAAO,OAAO,YAAY;EAChF,SAAS,SAAS,YAAY,MAAM,OAAO,OAAO,YAAY;EAC9D,OAAO,SAAS,YAAY,MAAM,OAAO,OAAO,YAAY;EAC5D,SAAS,OAAO,OAAO,YAAY;EACnC,QAAQ,OAAO,OAAO,YAAY;;EAElC,IAAI,QAAQ,YAAY,KAAK,OAAO,YAAY,MAAM,OAAO,OAAO,QAAQ;;iBAG7D,kBAAkB,KAAK,cAAc,eAAe,WAAW;WACrE,MAAM,SAAS;WACf,SAAS,QAAQ,KAAK;WACtB,QAAQ,mBAAmB;;qBAKzB;;;;;;;EAOX,OAAO,KAAK,cAAc,eAAe,WAAW,gBAAc,SACvD,kBAAkB,KAAK,WAC/B,eAAe,WAAW"}
@@ -0,0 +1,102 @@
1
+ import { Option, Schema } from "effect";
2
+ import { addressableRows } from "./rows.js";
3
+ // src/projection.ts
4
+ const CellAddress = {
5
+ /**
6
+ * An address as stored or sent: the row key as text, and the column as one
7
+ * of these columns' ids, so a saved address naming a removed column fails
8
+ * to decode instead of naming nothing.
9
+ */
10
+ schema: (columns) => Schema.Struct({
11
+ row: Schema.String,
12
+ column: Schema.Literals(columns.ids)
13
+ }) };
14
+ const clamp = (value, last) => Math.min(Math.max(value, 0), last);
15
+ const GridProjection = {
16
+ /**
17
+ * Projects rows through a column layout. A layout saved before a column
18
+ * was added does not mention it, so the column joins the center region in
19
+ * definition order; an id the columns do not define, or one named twice,
20
+ * keeps only its first place.
21
+ */
22
+ make: (options) => {
23
+ const { rows, columns, layout } = options;
24
+ const placed = /* @__PURE__ */ new Set();
25
+ const place = (ids) => ids.filter((id) => {
26
+ if (!Object.hasOwn(columns.byId, id) || placed.has(id)) return false;
27
+ placed.add(id);
28
+ return true;
29
+ });
30
+ const startPlaced = place(layout.start);
31
+ const centerPlaced = place(layout.center);
32
+ const endPlaced = place(layout.end);
33
+ centerPlaced.push(...columns.ids.filter((id) => !placed.has(id)));
34
+ const hidden = new Set(layout.hidden);
35
+ const shown = (ids) => ids.filter((id) => !hidden.has(id));
36
+ const start = shown(startPlaced);
37
+ const center = shown(centerPlaced);
38
+ const end = shown(endPlaced);
39
+ const visible = [
40
+ ...start,
41
+ ...center,
42
+ ...end
43
+ ];
44
+ const indexes = new Map(visible.map((id, index) => [id, index]));
45
+ const lastRow = addressableRows(rows.count) - 1;
46
+ const lastColumn = visible.length - 1;
47
+ const cellAt = (position) => {
48
+ const column = visible[position.column];
49
+ if (column === void 0) return Option.none();
50
+ return Option.map(rows.keyAt(position.row), (row) => ({
51
+ row,
52
+ column
53
+ }));
54
+ };
55
+ const positionOf = (address) => Option.flatMap(Option.fromUndefinedOr(indexes.get(address.column)), (column) => Option.map(rows.indexOf(address.row), (row) => ({
56
+ row,
57
+ column
58
+ })));
59
+ const within = (address, to) => Option.flatMap(positionOf(address), (position) => cellAt(to(position)));
60
+ return {
61
+ rows,
62
+ rowCount: rows.count,
63
+ columns: visible,
64
+ start,
65
+ center,
66
+ end,
67
+ columnIndex: (id) => Option.fromUndefinedOr(indexes.get(id)),
68
+ rowIndex: (key) => rows.indexOf(key),
69
+ cellAt,
70
+ positionOf,
71
+ moveBy: (address, offset) => within(address, ({ row, column }) => ({
72
+ row: clamp(row + Math.trunc(offset.rows ?? 0), lastRow),
73
+ column: clamp(column + Math.trunc(offset.columns ?? 0), lastColumn)
74
+ })),
75
+ rowStart: (address) => within(address, ({ row }) => ({
76
+ row,
77
+ column: 0
78
+ })),
79
+ rowEnd: (address) => within(address, ({ row }) => ({
80
+ row,
81
+ column: lastColumn
82
+ })),
83
+ first: () => cellAt({
84
+ row: 0,
85
+ column: 0
86
+ }),
87
+ last: () => cellAt({
88
+ row: lastRow,
89
+ column: lastColumn
90
+ }),
91
+ box: (anchor, focus) => Option.flatMap(positionOf(anchor), (from) => Option.map(positionOf(focus), (to) => ({
92
+ rows: {
93
+ start: Math.min(from.row, to.row),
94
+ end: Math.max(from.row, to.row) + 1
95
+ },
96
+ columns: visible.slice(Math.min(from.column, to.column), Math.max(from.column, to.column) + 1)
97
+ })))
98
+ };
99
+ } };
100
+ export { CellAddress, GridProjection };
101
+
102
+ //# sourceMappingURL=projection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projection.js","names":[],"sources":["../src/projection.ts"],"sourcesContent":["import { Option, Schema } from 'effect'\nimport type { Columns, ColumnSpec } from './columns.js'\nimport type { ColumnLayout } from './layout.js'\nimport { addressableRows, type RowCount, type RowModel } from './rows.js'\n\n/** A cell named by identity, so it stays the same cell through a sort or a reorder. */\nexport interface CellAddress<Id extends string> {\n readonly row: string\n readonly column: Id\n}\n\nexport const CellAddress = {\n /**\n * An address as stored or sent: the row key as text, and the column as one\n * of these columns' ids, so a saved address naming a removed column fails\n * to decode instead of naming nothing.\n */\n schema: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(\n columns: Columns<Row, Specs>,\n ) => Schema.Struct({ row: Schema.String, column: Schema.Literals(columns.ids) }),\n}\n\n/** Where a cell is drawn now: its row index, and its column's index in display order. */\nexport interface CellPosition {\n readonly row: number\n readonly column: number\n}\n\n/** A rectangle of cells: row indexes `[start, end)` and the columns it spans, in display order. */\nexport interface CellBox<Id extends string> {\n readonly rows: { readonly start: number; readonly end: number }\n readonly columns: ReadonlyArray<Id>\n}\n\nexport interface CellOffset {\n readonly rows?: number\n readonly columns?: number\n}\n\n/**\n * The grid as presented: rows in the application's order, crossed with the\n * visible columns in display order. It is the one source of geometry for\n * focus, selection, virtualization and the clipboard; none of them reads\n * positions from the DOM. A pure value, cheap to rebuild: it reads the\n * column layout once and asks the row model for rows only on lookup.\n *\n * Every lookup is an `Option`. A cell is absent when its column is hidden,\n * its row is gone, or its row is in range but not loaded yet.\n */\nexport interface GridProjection<Row, Id extends string> {\n readonly rows: RowModel<Row>\n readonly rowCount: RowCount\n /** Visible columns in display order: the start region, the center, the end. */\n readonly columns: ReadonlyArray<Id>\n /** The visible columns of each region, in display order. */\n readonly start: ReadonlyArray<Id>\n readonly center: ReadonlyArray<Id>\n readonly end: ReadonlyArray<Id>\n columnIndex(id: Id): Option.Option<number>\n rowIndex(key: string): Option.Option<number>\n cellAt(position: CellPosition): Option.Option<CellAddress<Id>>\n positionOf(address: CellAddress<Id>): Option.Option<CellPosition>\n /**\n * The cell `offset` away, stopping at the grid's edges. A fractional offset\n * (a page of rows worked out from a height) drops its fraction.\n */\n moveBy(address: CellAddress<Id>, offset: CellOffset): Option.Option<CellAddress<Id>>\n rowStart(address: CellAddress<Id>): Option.Option<CellAddress<Id>>\n rowEnd(address: CellAddress<Id>): Option.Option<CellAddress<Id>>\n first(): Option.Option<CellAddress<Id>>\n last(): Option.Option<CellAddress<Id>>\n /** The rectangle two cells span, in either order. */\n box(anchor: CellAddress<Id>, focus: CellAddress<Id>): Option.Option<CellBox<Id>>\n}\n\nexport interface ProjectionOptions<Row, Specs extends Record<string, ColumnSpec<Row, unknown>>> {\n readonly rows: RowModel<Row>\n readonly columns: Columns<Row, Specs>\n readonly layout: ColumnLayout<keyof Specs & string>\n}\n\nconst clamp = (value: number, last: number): number => Math.min(Math.max(value, 0), last)\n\nexport const GridProjection = {\n /**\n * Projects rows through a column layout. A layout saved before a column\n * was added does not mention it, so the column joins the center region in\n * definition order; an id the columns do not define, or one named twice,\n * keeps only its first place.\n */\n make: <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(\n options: ProjectionOptions<Row, Specs>,\n ): GridProjection<Row, keyof Specs & string> => {\n type Id = keyof Specs & string\n const { rows, columns, layout } = options\n const placed = new Set<string>()\n const place = (ids: ReadonlyArray<Id>): Array<Id> =>\n ids.filter(id => {\n if (!Object.hasOwn(columns.byId, id) || placed.has(id)) return false\n placed.add(id)\n return true\n })\n const startPlaced = place(layout.start)\n const centerPlaced = place(layout.center)\n const endPlaced = place(layout.end)\n centerPlaced.push(...columns.ids.filter(id => !placed.has(id)))\n\n const hidden = new Set<string>(layout.hidden)\n const shown = (ids: ReadonlyArray<Id>) => ids.filter(id => !hidden.has(id))\n const start = shown(startPlaced)\n const center = shown(centerPlaced)\n const end = shown(endPlaced)\n const visible = [...start, ...center, ...end]\n const indexes = new Map<string, number>(visible.map((id, index) => [id, index]))\n\n const lastRow = addressableRows(rows.count) - 1\n const lastColumn = visible.length - 1\n\n const cellAt = (position: CellPosition): Option.Option<CellAddress<Id>> => {\n const column = visible[position.column]\n if (column === undefined) return Option.none()\n return Option.map(rows.keyAt(position.row), row => ({ row, column }))\n }\n\n const positionOf = (address: CellAddress<Id>): Option.Option<CellPosition> =>\n Option.flatMap(Option.fromUndefinedOr(indexes.get(address.column)), column =>\n Option.map(rows.indexOf(address.row), row => ({ row, column })),\n )\n\n const within = (\n address: CellAddress<Id>,\n to: (position: CellPosition) => CellPosition,\n ): Option.Option<CellAddress<Id>> =>\n Option.flatMap(positionOf(address), position => cellAt(to(position)))\n\n return {\n rows,\n rowCount: rows.count,\n columns: visible,\n start,\n center,\n end,\n columnIndex: id => Option.fromUndefinedOr(indexes.get(id)),\n rowIndex: key => rows.indexOf(key),\n cellAt,\n positionOf,\n moveBy: (address, offset) =>\n within(address, ({ row, column }) => ({\n row: clamp(row + Math.trunc(offset.rows ?? 0), lastRow),\n column: clamp(column + Math.trunc(offset.columns ?? 0), lastColumn),\n })),\n rowStart: address => within(address, ({ row }) => ({ row, column: 0 })),\n rowEnd: address => within(address, ({ row }) => ({ row, column: lastColumn })),\n first: () => cellAt({ row: 0, column: 0 }),\n last: () => cellAt({ row: lastRow, column: lastColumn }),\n box: (anchor, focus) =>\n Option.flatMap(positionOf(anchor), from =>\n Option.map(positionOf(focus), to => ({\n rows: { start: Math.min(from.row, to.row), end: Math.max(from.row, to.row) + 1 },\n columns: visible.slice(\n Math.min(from.column, to.column),\n Math.max(from.column, to.column) + 1,\n ),\n })),\n ),\n }\n },\n}\n"],"mappings":";;;AAWA,MAAa,cAAc;;;;;;AAMzB,SACE,YACG,OAAO,OAAO;CAAE,KAAK,OAAO;CAAQ,QAAQ,OAAO,SAAS,QAAQ,GAAG;AAAE,CAAC,EACjF;AA6DA,MAAM,SAAS,OAAe,SAAyB,KAAK,IAAI,KAAK,IAAI,OAAO,CAAC,GAAG,IAAI;AAExF,MAAa,iBAAiB;;;;;;;AAO5B,OACE,YAC8C;CAE9C,MAAM,EAAE,MAAM,SAAS,WAAW;CAClC,MAAM,yBAAS,IAAI,IAAY;CAC/B,MAAM,SAAS,QACb,IAAI,QAAO,OAAM;EACf,IAAI,CAAC,OAAO,OAAO,QAAQ,MAAM,EAAE,KAAK,OAAO,IAAI,EAAE,GAAG,OAAO;EAC/D,OAAO,IAAI,EAAE;EACb,OAAO;CACT,CAAC;CACH,MAAM,cAAc,MAAM,OAAO,KAAK;CACtC,MAAM,eAAe,MAAM,OAAO,MAAM;CACxC,MAAM,YAAY,MAAM,OAAO,GAAG;CAClC,aAAa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AAK,MAAM,OAAO,QAAQ,CAAC,GAAG,OAAO;GACtD,QAAQ,MAAM,SAAS,KAAK,MAAM,OAAO,WAAW,CAAC,GAAG,UAAU;EACpE,EAAE;EACJ,WAAU,YAAW,OAAO,UAAU,EAAE,WAAW;GAAE;GAAK,QAAQ;EAAE,EAAE;EACtE,SAAQ,YAAW,OAAO,UAAU,EAAE,WAAW;GAAE;GAAK,QAAQ;EAAW,EAAE;EAC7E,aAAa,OAAO;GAAE,KAAK;GAAG,QAAQ;EAAE,CAAC;EACzC,YAAY,OAAO;GAAE,KAAK;GAAS,QAAQ;EAAW,CAAC;EACvD,MAAM,QAAQ,UACZ,OAAO,QAAQ,WAAW,MAAM,IAAG,SACjC,OAAO,IAAI,WAAW,KAAK,IAAG,QAAO;GACnC,MAAM;IAAE,OAAO,KAAK,IAAI,KAAK,KAAK,GAAG,GAAG;IAAG,KAAK,KAAK,IAAI,KAAK,KAAK,GAAG,GAAG,IAAI;GAAE;GAC/E,SAAS,QAAQ,MACf,KAAK,IAAI,KAAK,QAAQ,GAAG,MAAM,GAC/B,KAAK,IAAI,KAAK,QAAQ,GAAG,MAAM,IAAI,CACrC;EACF,EAAE,CACJ;CACJ;AACF,EACF"}
package/dist/rows.d.ts ADDED
@@ -0,0 +1,70 @@
1
+ import { Option, Schema } from "effect";
2
+ /**
3
+ * How many rows a grid can address. A local array, or a server that reports
4
+ * its total, is `Known`; a cursor that has not reached its end is `Unknown`,
5
+ * with the rows seen so far as a lower bound.
6
+ */
7
+ export declare const RowCount: import("foldkit/schema").TaggedUnion<{
8
+ /** Exactly `total` rows, loaded or not. */
9
+ readonly Known: {
10
+ total: Schema.Number;
11
+ };
12
+ /** At least `atLeast` rows; more may follow. */
13
+ readonly Unknown: {
14
+ atLeast: Schema.Number;
15
+ };
16
+ }>;
17
+ export type RowCount = typeof RowCount.Type;
18
+ /**
19
+ * Where the rows' source stands, for a view to say: `Loading` before any
20
+ * answer, `Refreshing` while a newer one is on its way and the rows shown are
21
+ * the last good ones, `Failed` with what went wrong. The grid holds no
22
+ * loading state of its own; the source's owner (Remote, a store) says this.
23
+ */
24
+ export declare const RowStatus: import("foldkit/schema").TaggedUnion<{
25
+ readonly Ready: {};
26
+ readonly Loading: {};
27
+ readonly Refreshing: {};
28
+ readonly Failed: {
29
+ message: Schema.String;
30
+ };
31
+ }>;
32
+ export type RowStatus = typeof RowStatus.Type;
33
+ /** The number of row indexes a grid may address: the total, or the lower bound. */
34
+ export declare const addressableRows: (value: {
35
+ readonly _tag: "Known";
36
+ readonly total: number;
37
+ } | {
38
+ readonly _tag: "Unknown";
39
+ readonly atLeast: number;
40
+ }) => number;
41
+ /**
42
+ * Logical row space: rows by index, each with a stable key, whatever stores
43
+ * or fetches them. Indexes follow the order the application supplies, so a
44
+ * sorted or filtered result is the application's, not the grid's. An index
45
+ * that is in range may still have no row yet (a page not loaded), so every
46
+ * lookup is an `Option`.
47
+ */
48
+ export interface RowModel<Row> {
49
+ readonly count: RowCount;
50
+ rowAt(index: number): Option.Option<Row>;
51
+ keyAt(index: number): Option.Option<string>;
52
+ indexOf(key: string): Option.Option<number>;
53
+ }
54
+ export declare const RowModel: {
55
+ /**
56
+ * Rows held in memory, in the order given. Throws when two rows share a
57
+ * key, since focus and selection would then name two rows at once.
58
+ */
59
+ fromArray: <Row>(rows: ReadonlyArray<Row>, key: (row: Row) => string) => RowModel<Row>;
60
+ /**
61
+ * The rows with each one transformed as it is read: a local edit laid over
62
+ * a row a server sent, say. `make` turns `input` into the per-row function,
63
+ * once per `rows` and `input`, so a lookup it builds is built once; the
64
+ * result is the same model while both are, and a new one when either
65
+ * changes. Keys, count and order are `rows`' own, so `make`'s function must
66
+ * keep each row's key.
67
+ */
68
+ map: <Row, Mapped, Input extends object>(rows: RowModel<Row>, input: Input, make: (input: Input) => (row: Row) => Mapped) => RowModel<Mapped>;
69
+ };
70
+ //# sourceMappingURL=rows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rows.d.ts","names":[],"sources":["../src/rows.ts"],"mappings":";;;;;;qBAQa,mCAAQ;;;IAEV,OAAK,OAAA;;;;IAEH,SAAO,OAAA;;;YAER,kBAAkB,SAAS;;;;;;;qBAQ1B,oCAAS;;;;;IAIV,SAAO,OAAA;;;YAEP,mBAAmB,UAAU;;qBAG5B,kBAAe;;;;;;;;;;;;;;iBAYX,SAAS;WACf,OAAO;EAChB,MAAM,gBAAgB,OAAO,OAAO;EACpC,MAAM,gBAAgB,OAAO;EAC7B,QAAQ,cAAc,OAAO;;qBA6ClB;;;;;EAKX,YAAY,KAAG,MAAQ,cAAc,MAAI,MAAQ,KAAK,mBAAiB,SAAS;;;;;;;;;EAgBhF,MAAM,KAAK,QAAQ,sBAAoB,MAC/B,SAAS,MAAI,OACZ,OAAK,OACL,OAAO,WAAW,KAAK,QAAQ,WACrC,SAAS"}
@@ -1,73 +1,5 @@
1
- import { Option, Schema, SchemaAST } from "effect";
1
+ import { Option, Schema } from "effect";
2
2
  import { defineTaggedUnion } from "foldkit/schema";
3
- // src/columns.ts
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.
7
- */
8
- const CellEditor = defineTaggedUnion({
9
- Text: {},
10
- /** The schema decodes to a number: typed with a decimal keypad on touch. */
11
- Number: {},
12
- /** The schema's text is one of these, offered in order. */
13
- Choice: { options: Schema.Array(Schema.String) },
14
- /** The schema decodes to a date: a native date field over the draft text. */
15
- Date: {}
16
- });
17
- /**
18
- * Whether a schema decodes to a date, found as Effect's own tools find it:
19
- * by the declaration's representation id. Only Date-ness is read here, never
20
- * the text format: committing decodes the draft through the schema, and a
21
- * refusal is the cell's error.
22
- */
23
- const DATE_ID = "effect/schema/Date";
24
- const isDate = (ast) => {
25
- if (!SchemaAST.isDeclaration(ast)) return false;
26
- const representation = ast.annotations?.["representation"];
27
- return typeof representation === "object" && representation !== null && "id" in representation && representation.id === DATE_ID;
28
- };
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 });
36
- }
37
- const type = SchemaAST.toType(schema.ast);
38
- if (isDate(type)) return CellEditor.Date();
39
- return SchemaAST.isNumber(type) ? CellEditor.Number() : CellEditor.Text();
40
- };
41
- const arrayIndex = /^(0|[1-9][0-9]*)$/;
42
- const Columns = {
43
- /** The width of a column that names none. */
44
- defaultWidth: 120,
45
- /** The narrowest a column with no `minWidth` resizes to. */
46
- minWidth: 40,
47
- /** A value as a cell shows it: nothing for `null` or `undefined`. */
48
- textOf: (value) => value === null || value === void 0 ? "" : String(value),
49
- /**
50
- * Declares a grid's columns over `Row`. Call it twice, once with the row
51
- * type and once with the specs, so the ids and values are inferred:
52
- * `Columns.define<Product>()({ sku: { header: 'SKU', value: p => p.sku } })`.
53
- */
54
- define: () => (specs) => {
55
- 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);
57
- const byId = {};
58
- for (const id of ids) {
59
- 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
- byId[id] = Object.freeze({
61
- ...specs[id],
62
- id
63
- });
64
- }
65
- return Object.freeze({
66
- ids: Object.freeze(ids),
67
- byId: Object.freeze(byId)
68
- });
69
- }
70
- };
71
3
  // src/rows.ts
72
4
  /**
73
5
  * How many rows a grid can address. A local array, or a server that reports
@@ -155,6 +87,6 @@ const RowModel = {
155
87
  return model;
156
88
  }
157
89
  };
158
- export { CellEditor as a, addressableRows as i, RowModel as n, Columns as o, RowStatus as r, editorOf as s, RowCount as t };
90
+ export { RowCount, RowModel, RowStatus, addressableRows };
159
91
 
160
- //# sourceMappingURL=rows-Dy1HPpGX.mjs.map
92
+ //# sourceMappingURL=rows.js.map