foldkit-data-grid 0.2.3 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["make","arrows","make"],"sources":["../src/clipboard.ts","../src/fill.ts","../src/layout.ts","../src/columnState.ts","../src/projection.ts","../src/focus.ts","../src/selection.ts","../src/viewport.ts","../src/virtual.ts","../src/grid.ts"],"sourcesContent":["import { Option } from 'effect'\nimport type { CellAddress, CellBox, GridProjection } from './projection.js'\n\n/** One cell's text in a paste, by identity: what the grid hands the application. */\nexport interface CellText<Id extends string> {\n readonly row: string\n readonly column: Id\n readonly text: string\n}\n\n/** A pasted cell, with the text it showed before, so an unchanged one is no edit. */\nexport interface PastedCell<Id extends string> extends CellText<Id> {\n readonly from: string\n}\n\n// A cell holding a tab, a line break or a quote is quoted, its quotes doubled,\n// as spreadsheets write and read tab-separated text.\nconst needsQuotes = /[\\t\\n\\r\"]/\n\nconst quote = (cell: string): string =>\n needsQuotes.test(cell) ? `\"${cell.replaceAll('\"', '\"\"')}\"` : cell\n\n/** Rows of cells as tab-separated text, the form spreadsheets copy and paste. */\nconst toTsv = (rows: ReadonlyArray<ReadonlyArray<string>>): string =>\n rows.map(row => row.map(quote).join('\\t')).join('\\n')\n\n/**\n * Tab-separated text as rows of cells. Quoted cells may hold tabs, line\n * breaks and doubled quotes; `\\r\\n` and `\\r` end a row as `\\n` does; the line\n * break a spreadsheet adds after the last row makes no empty row.\n */\nconst parseTsv = (text: string): ReadonlyArray<ReadonlyArray<string>> => {\n const rows: Array<Array<string>> = []\n let row: Array<string> = []\n let cell = ''\n let quoted = false\n let index = 0\n const endCell = () => {\n row.push(cell)\n cell = ''\n }\n const endRow = () => {\n endCell()\n rows.push(row)\n row = []\n }\n while (index < text.length) {\n const char = text[index]!\n if (quoted) {\n if (char === '\"' && text[index + 1] === '\"') {\n cell += '\"'\n index += 2\n continue\n }\n if (char === '\"') quoted = false\n else cell += char\n index += 1\n continue\n }\n if (char === '\"' && cell === '') quoted = true\n else if (char === '\\t') endCell()\n else if (char === '\\r' || char === '\\n') {\n endRow()\n if (char === '\\r' && text[index + 1] === '\\n') index += 1\n } else cell += char\n index += 1\n }\n // Text that ends in a line break has said all its rows.\n if (cell !== '' || row.length > 0) endRow()\n return rows\n}\n\n/**\n * The text of the cells a box covers, row by row in the projection's order\n * and column by column in display order. A row counted but not loaded copies\n * as empty cells, so the shape is the box's.\n */\nconst copy = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n box: CellBox<Id>,\n textOf: (address: CellAddress<Id>) => string,\n): string => {\n const rows: Array<ReadonlyArray<string>> = []\n for (let index = box.rows.start; index < box.rows.end; index++) {\n const key = projection.rows.keyAt(index)\n rows.push(\n box.columns.map(column =>\n Option.match(key, { onNone: () => '', onSome: row => textOf({ row, column }) }),\n ),\n )\n }\n return toTsv(rows)\n}\n\n/**\n * Where pasted cells land: the matrix laid from `anchor` across rows in the\n * projection's order and columns in display order. Cells past the grid's\n * edges are dropped, as are those landing on a column that does not edit or\n * a row not loaded; the rest keep their place, each with `from`, the text\n * the cell showed (the text an edit of it would begin from).\n */\nconst pasteAt = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n anchor: CellAddress<Id>,\n matrix: ReadonlyArray<ReadonlyArray<string>>,\n cells: {\n readonly editable: (column: Id) => boolean\n readonly from: (address: CellAddress<Id>) => string\n },\n): ReadonlyArray<PastedCell<Id>> =>\n Option.match(projection.positionOf(anchor), {\n onNone: () => [],\n onSome: start => {\n const landed: Array<PastedCell<Id>> = []\n matrix.forEach((texts, down) => {\n const key = projection.rows.keyAt(start.row + down)\n if (Option.isNone(key)) return\n const row = key.value\n texts.forEach((text, across) => {\n const column = projection.columns[start.column + across]\n if (column !== undefined && cells.editable(column)) {\n landed.push({ row, column, text, from: cells.from({ row, column }) })\n }\n })\n })\n return landed\n },\n })\n\nexport const Clipboard = { toTsv, parseTsv, copy, pasteAt }\n","import { Option } from 'effect'\nimport type { PastedCell } from './clipboard.js'\nimport type { CellAddress, CellBox, GridProjection } from './projection.js'\n\n/** A fill: the range whose cells are carried on, and the cell it was carried to. */\nexport interface FillRequest<Id extends string> {\n readonly source: { readonly anchor: CellAddress<Id>; readonly focus: CellAddress<Id> }\n readonly to: CellAddress<Id>\n}\n\n/**\n * Where a fill lands: the source's box, and the box it fills beyond it, down,\n * up, right or left, whichever way `to` lies further outside the source. A\n * fill carries on along one axis only, as spreadsheets do.\n */\nexport interface FillPlan<Id extends string> {\n readonly source: CellBox<Id>\n readonly target: CellBox<Id>\n /** Rows (`down`/`up`) or columns (`right`/`left`), away from the source. */\n readonly toward: 'down' | 'up' | 'right' | 'left'\n}\n\nconst number = /^-?\\d+(?:\\.(\\d+))?$/\n\n/**\n * The texts that carry `source` on for `count` cells, the first of them next\n * to it. Two or more numbers a constant step apart continue their step, with\n * as many decimals as the most precise of them; anything else repeats, in\n * order. `backward` carries the source on before its first text, as filling\n * up or left does.\n */\nconst series = (\n source: ReadonlyArray<string>,\n count: number,\n backward: boolean,\n): ReadonlyArray<string> => {\n const at = (index: number) => source[((index % source.length) + source.length) % source.length]!\n const repeated = Array.from({ length: count }, (_, index) =>\n backward ? at(-1 - index) : at(source.length + index),\n )\n if (source.length < 2) return repeated\n const parsed = source.map(text => number.exec(text.trim()))\n if (parsed.some(match => match === null)) return repeated\n const decimals = Math.max(...parsed.map(match => match![1]?.length ?? 0))\n // Whole units of the finest decimal, so a step of 0.1 adds up exactly.\n const scale = 10 ** decimals\n const units = source.map(text => Math.round(Number(text.trim()) * scale))\n const step = units[1]! - units[0]!\n if (units.some((unit, index) => index > 0 && unit - units[index - 1]! !== step)) return repeated\n const from = backward ? units[0]! : units[units.length - 1]!\n return Array.from({ length: count }, (_, index) =>\n ((from + (backward ? -step : step) * (index + 1)) / scale).toFixed(decimals),\n )\n}\n\n/** The source's box and the box beyond it toward `to`; none when `to` is inside it. */\nconst plan = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n request: FillRequest<Id>,\n): Option.Option<FillPlan<Id>> =>\n Option.flatMap(projection.box(request.source.anchor, request.source.focus), source =>\n Option.flatMap(projection.positionOf(request.to), to => {\n const first = projection.columns.indexOf(source.columns[0]!)\n const last = first + source.columns.length - 1\n const below = to.row - (source.rows.end - 1)\n const above = source.rows.start - to.row\n const right = to.column - last\n const left = first - to.column\n const rows = Math.max(below, above)\n const columns = Math.max(right, left)\n if (rows <= 0 && columns <= 0) return Option.none()\n if (rows >= columns) {\n const target =\n below > 0\n ? { start: source.rows.end, end: to.row + 1 }\n : { start: to.row, end: source.rows.start }\n return Option.some({\n source,\n target: { rows: target, columns: source.columns },\n toward: below > 0 ? 'down' : 'up',\n })\n }\n const columnsOf = (start: number, end: number) => projection.columns.slice(start, end)\n return Option.some({\n source,\n target: {\n rows: source.rows,\n columns: right > 0 ? columnsOf(last + 1, to.column + 1) : columnsOf(to.column, first),\n },\n toward: right > 0 ? 'right' : 'left',\n })\n }),\n )\n\n/**\n * The cells a fill writes: each lane of the source (a column for a fill down\n * or up, a row for one right or left) carried on through the target by\n * `series`. Cells on a column that does not edit, or on a row not loaded, are\n * dropped; each kept cell has `from`, the text it showed.\n */\nconst cells = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n fill: FillPlan<Id>,\n options: {\n readonly editable: (column: Id) => boolean\n readonly from: (address: CellAddress<Id>) => string\n },\n): ReadonlyArray<PastedCell<Id>> => {\n const rowsOf = (box: { readonly start: number; readonly end: number }) =>\n Array.from({ length: box.end - box.start }, (_, offset) => box.start + offset)\n const keyAt = (index: number) => projection.rows.keyAt(index)\n const textAt = (index: number, column: Id) =>\n Option.match(keyAt(index), { onNone: () => '', onSome: row => options.from({ row, column }) })\n const cell = (index: number, column: Id, text: string): ReadonlyArray<PastedCell<Id>> =>\n options.editable(column)\n ? Option.match(keyAt(index), {\n onNone: () => [],\n onSome: row => [{ row, column, text, from: options.from({ row, column }) }],\n })\n : []\n const backward = fill.toward === 'up' || fill.toward === 'left'\n // Away from the source, so the series' first text lands next to it.\n const away = <A>(items: ReadonlyArray<A>) => (backward ? [...items].reverse() : items)\n if (fill.toward === 'down' || fill.toward === 'up') {\n const targetRows = away(rowsOf(fill.target.rows))\n return fill.source.columns.flatMap(column => {\n const texts = series(\n rowsOf(fill.source.rows).map(index => textAt(index, column)),\n targetRows.length,\n backward,\n )\n return targetRows.flatMap((index, at) => cell(index, column, texts[at]!))\n })\n }\n const targetColumns = away(fill.target.columns)\n return rowsOf(fill.source.rows).flatMap(index => {\n const texts = series(\n fill.source.columns.map(column => textAt(index, column)),\n targetColumns.length,\n backward,\n )\n return targetColumns.flatMap((column, at) => cell(index, column, texts[at]!))\n })\n}\n\nexport const Fill = { series, plan, cells }\n","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","import { Option, Schema } from 'effect'\nimport { Columns, type ColumnSpec } from './columns.js'\nimport { ColumnLayout } from './layout.js'\n\nexport type Region = 'start' | 'center' | 'end'\n\nconst regions: ReadonlyArray<Region> = ['start', 'center', 'end']\n\n/**\n * Where each column stands and how wide the resized ones are. Widths list only\n * the columns resized; the rest take their spec's. The grid owns it, and it is\n * plain data, so an application can save it and restore it.\n */\nexport interface ColumnState<Id extends string> extends ColumnLayout<Id> {\n readonly widths: ReadonlyArray<{ readonly column: Id; readonly width: number }>\n}\n\n/** What `restore` made of a saved state: the state, and the ids it had to drop. */\nexport interface Restored<Id extends string> {\n readonly state: ColumnState<Id>\n /** Ids the saved state named that these columns do not define, or named twice. */\n readonly dropped: ReadonlyArray<string>\n}\n\nconst Saved = Schema.Struct({\n start: Schema.Array(Schema.String),\n center: Schema.Array(Schema.String),\n end: Schema.Array(Schema.String),\n hidden: Schema.Array(Schema.String),\n widths: Schema.Array(Schema.Struct({ column: Schema.String, width: Schema.Number })),\n})\n\nconst without = <Id extends string>(ids: ReadonlyArray<Id>, id: Id): ReadonlyArray<Id> =>\n ids.filter(each => each !== id)\n\n/**\n * Column state for one grid's columns: its Schema, which decodes only these\n * columns' ids, and the operations a grid's Messages run. Every operation\n * returns the state it was given when it changes nothing, so a no-op draws\n * nothing.\n */\nconst make = <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(\n columns: Columns<Row, Specs>,\n) => {\n type Id = keyof Specs & string\n type State = ColumnState<Id>\n const Ids = Schema.Literals(columns.ids)\n const Model = Schema.Struct({\n start: Schema.Array(Ids),\n center: Schema.Array(Ids),\n end: Schema.Array(Ids),\n hidden: Schema.Array(Ids),\n widths: Schema.Array(Schema.Struct({ column: Ids, width: Schema.Number })),\n })\n\n const spec = (id: Id) => columns.byId[id]\n const isColumn = (id: string): id is Id => Object.hasOwn(columns.byId, id)\n const clampWidth = (id: Id, width: number): number => {\n const { minWidth = Columns.minWidth, maxWidth = Number.POSITIVE_INFINITY } = spec(id)\n return Math.min(Math.max(width, minWidth), maxWidth)\n }\n\n const initial = (): State => ({ ...ColumnLayout.initial(columns), widths: [] })\n\n /** The width each column is drawn at: its resize, else its spec's. Call once per state. */\n const widthOf = (state: State): ((id: Id) => number) => {\n const resized = new Map(state.widths.map(entry => [entry.column, entry.width]))\n return id => resized.get(id) ?? spec(id).width ?? Columns.defaultWidth\n }\n\n const regionOf = (state: State, id: Id): Region =>\n regions.find(region => state[region].includes(id)) ?? 'center'\n\n /** Resizes a resizable column, within its `minWidth` and `maxWidth`. */\n const resize = (state: State, id: Id, width: number): State => {\n if (spec(id).resizable === false || !Number.isFinite(width)) return state\n const clamped = clampWidth(id, width)\n if (clamped === widthOf(state)(id)) return state\n return {\n ...state,\n widths: [\n ...state.widths.filter(entry => entry.column !== id),\n { column: id, width: clamped },\n ],\n }\n }\n\n const visibleCount = (state: State): number => {\n const hidden = new Set(state.hidden)\n return regions.reduce(\n (count, region) => count + state[region].filter(id => !hidden.has(id)).length,\n 0,\n )\n }\n\n /** Hides a hideable column; the last one shown stays, so the grid keeps a cell to focus. */\n const hide = (state: State, id: Id): State => {\n if (spec(id).hideable === false || state.hidden.includes(id) || visibleCount(state) <= 1) {\n return state\n }\n return { ...state, hidden: [...state.hidden, id] }\n }\n\n const show = (state: State, id: Id): State =>\n state.hidden.includes(id) ? { ...state, hidden: without(state.hidden, id) } : state\n\n /**\n * Moves a column to `index` among the columns of `region`, counted with it\n * removed: a reorder within its region, or a pin or an unpin across them.\n */\n const move = (state: State, id: Id, region: Region, index: number): State => {\n const from = regionOf(state, id)\n const target = without(state[region], id)\n const at = Math.min(Math.max(0, Math.trunc(index)), target.length)\n if (from === region && state[region].indexOf(id) === at) return state\n const placed = [...target.slice(0, at), id, ...target.slice(at)]\n return { ...state, [from]: without(state[from], id), [region]: placed }\n }\n\n /**\n * Where a column dragged `delta` pixels toward its region's end lands, as\n * the index `move` takes in that region: past the middle of each shown\n * neighbour it crossed. A column that crosses none stays where it is, so\n * hidden columns keep their places; so do a hidden column and a delta that\n * is not a number.\n */\n const dropAt = (state: State, id: Id, delta: number): number => {\n const order = state[regionOf(state, id)]\n const here = order.indexOf(id)\n const hidden = new Set(state.hidden)\n if (hidden.has(id) || !Number.isFinite(delta)) return here\n const width = widthOf(state)\n const shown: Array<{ readonly id: Id; readonly middle: number }> = []\n let dragged = 0\n let before = 0\n let edge = 0\n for (const each of order) {\n if (hidden.has(each)) continue\n const middle = edge + width(each) / 2\n if (each === id) {\n dragged = middle + delta\n before = shown.length\n } else shown.push({ id: each, middle })\n edge += width(each)\n }\n // How many shown neighbours end up before it, in middle order.\n const passed = shown.filter(other => other.middle <= dragged).length\n if (passed === before) return here\n const others = without(order, id)\n return passed < shown.length\n ? others.indexOf(shown[passed]!.id)\n : others.indexOf(shown[passed - 1]!.id) + 1\n }\n\n /**\n * A saved state read back leniently: an id these columns no longer define,\n * or one named twice, is dropped and listed; a column the save predates\n * takes its initial place; a width is clamped to its column's limits.\n * Input that is not a saved state at all is the initial state, with nothing\n * dropped, since nothing was read.\n */\n const restore = (saved: unknown): Restored<Id> =>\n Option.match(Schema.decodeUnknownOption(Saved)(saved), {\n onNone: () => ({ state: initial(), dropped: [] }),\n onSome: value => {\n const dropped: Array<string> = []\n const saved = new Set<Id>()\n const keep = (ids: ReadonlyArray<string>): Array<Id> =>\n ids.filter((id): id is Id => {\n if (!isColumn(id) || saved.has(id)) {\n dropped.push(id)\n return false\n }\n saved.add(id)\n return true\n })\n const placed = {\n start: keep(value.start),\n center: keep(value.center),\n end: keep(value.end),\n }\n // A column the save predates takes its initial region and visibility.\n const fresh = initial()\n for (const region of regions) {\n for (const id of fresh[region]) if (!saved.has(id)) placed[region].push(id)\n }\n const hidden = new Set<Id>(fresh.hidden.filter(id => !saved.has(id)))\n for (const id of value.hidden) if (isColumn(id)) hidden.add(id)\n const widths = new Map<Id, number>()\n for (const entry of value.widths) {\n if (isColumn(entry.column) && Number.isFinite(entry.width)) {\n widths.set(entry.column, clampWidth(entry.column, entry.width))\n }\n }\n return {\n state: {\n ...placed,\n hidden: [...hidden],\n widths: [...widths].map(([column, width]) => ({ column, width })),\n },\n dropped,\n }\n },\n })\n\n return { Model, initial, widthOf, regionOf, resize, hide, show, move, dropAt, restore }\n}\n\nexport const ColumnState = { make }\n","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","import { Option, Schema } from 'effect'\nimport type { KeyboardModifiers } from 'foldkit/html'\nimport { defineMessageUnion } from 'foldkit/message'\nimport { modifyFields } from 'foldkit/struct'\nimport { Bundle } from 'foldkit-bundle'\nimport type { Columns, ColumnSpec } from './columns.js'\nimport { CellAddress, type GridProjection } from './projection.js'\n\nexport type Direction = 'ltr' | 'rtl'\n\nexport interface KeyOptions<Id extends string> {\n readonly current: Option.Option<CellAddress<Id>>\n readonly key: string\n readonly modifiers: KeyboardModifiers\n /** Default `'ltr'`; under `'rtl'` the left and right arrows swap. */\n readonly direction?: Direction\n /** How many rows PageUp and PageDown move: the rows a viewport shows. */\n readonly pageRows: number\n}\n\nconst sameAddress = <Id extends string>(a: CellAddress<Id>, b: CellAddress<Id>): boolean =>\n a.row === b.row && a.column === b.column\n\n/**\n * The cell that holds the grid's one tab stop: the focused cell while it is\n * shown, and otherwise the first cell. A focused cell whose column was hidden\n * or whose row went away stays in the Model, so focus returns to it if it\n * comes back, but the tab stop moves on until then.\n */\nconst tabStop = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n current: Option.Option<CellAddress<Id>>,\n): Option.Option<CellAddress<Id>> =>\n Option.orElse(\n Option.filter(current, address => Option.isSome(projection.positionOf(address))),\n () => projection.first(),\n )\n\nconst arrows: ReadonlyMap<string, { readonly rows: number; readonly columns: number }> = new Map([\n ['ArrowUp', { rows: -1, columns: 0 }],\n ['ArrowDown', { rows: 1, columns: 0 }],\n ['ArrowLeft', { rows: 0, columns: -1 }],\n ['ArrowRight', { rows: 0, columns: 1 }],\n])\n\n/**\n * The cell a key moves focus to, or none when the key is not the grid's to\n * handle, so the caller leaves it to the page. Arrows step one cell, Home and\n * End go to the row's edges and, with Ctrl, to the grid's corners; PageUp and\n * PageDown move `pageRows`. A key the grid handles always lands somewhere: at\n * an edge, or onto a row that is counted but not loaded, focus stays where it\n * is. Shift, Alt and Meta combinations are left alone: Shift extends a\n * selection, which is not focus's to decide.\n */\nconst target = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n options: KeyOptions<Id>,\n): Option.Option<CellAddress<Id>> => {\n const { key, modifiers } = options\n if (modifiers.shiftKey || modifiers.altKey || modifiers.metaKey) return Option.none()\n return Option.flatMap(tabStop(projection, options.current), from => {\n const stay = (to: Option.Option<CellAddress<Id>>) =>\n Option.some(Option.getOrElse(to, () => from))\n if (key === 'Home')\n return stay(modifiers.ctrlKey ? projection.first() : projection.rowStart(from))\n if (key === 'End') return stay(modifiers.ctrlKey ? projection.last() : projection.rowEnd(from))\n if (modifiers.ctrlKey) return Option.none()\n if (key === 'PageUp') return stay(projection.moveBy(from, { rows: -options.pageRows }))\n if (key === 'PageDown') return stay(projection.moveBy(from, { rows: options.pageRows }))\n const step = arrows.get(key)\n if (step === undefined) return Option.none()\n const flip = options.direction === 'rtl' ? -1 : 1\n return stay(projection.moveBy(from, { rows: step.rows, columns: step.columns * flip }))\n })\n}\n\n/**\n * A cell's DOM id: the grid's id, the row key and the column id, each\n * URI-encoded and joined by `:`, which encoding never leaves in a part, so no\n * two cells share an id. The container points at it with\n * `aria-activedescendant`.\n */\nconst cellId = <Id extends string>(grid: string, address: CellAddress<Id>): string =>\n [grid, address.row, address.column].map(encodeURIComponent).join(':')\n\nconst decode = Option.liftThrowable(decodeURIComponent)\n\n/**\n * The address a `cellId` names, if it is one of this grid's: its row key and\n * its column id as written, for the grid's columns to check. An id from\n * another grid, or with a malformed escape, is none.\n */\nconst cellOf = (\n grid: string,\n id: string,\n): Option.Option<{ readonly row: string; readonly column: string }> =>\n Option.map(partsOf(grid, id, 3), ([row, column]) => ({ row: row!, column: column! }))\n\n/** The parts of one of this grid's ids after the grid's own, when it has `count` parts in all. */\nconst partsOf = (grid: string, id: string, count: number): Option.Option<ReadonlyArray<string>> => {\n const parts = id.split(':')\n if (parts.length !== count) return Option.none()\n return Option.flatMap(Option.all(parts.map(part => decode(part))), ([owner, ...rest]) =>\n owner === grid ? Option.some(rest) : Option.none(),\n )\n}\n\n/**\n * A column header's DOM id: the grid's id and the column id, URI-encoded and\n * joined by `:`. It has two parts where a cell's has three, so the two never\n * meet.\n */\nconst headerId = (grid: string, column: string): string =>\n [grid, column].map(encodeURIComponent).join(':')\n\n/** The column a `headerId` names, if it is one of this grid's, as written. */\nconst headerOf = (grid: string, id: string): Option.Option<string> =>\n Option.map(partsOf(grid, id, 2), ([column]) => column!)\n\n/**\n * Focus for one grid: which cell is current, by identity. Make it once per\n * grid from its columns, so a focus saved in the Model decodes only against\n * columns that exist.\n */\nconst make = <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(\n columns: Columns<Row, Specs>,\n) => {\n const Address = CellAddress.schema(columns)\n const Model = Schema.Struct({\n /** The focused cell; stored as `null` when none is. */\n current: Schema.OptionFromNullOr(Address),\n /**\n * The column header focus is on, when it is on the header row. The cell\n * focused before stays in `current`, so going back down returns to it.\n */\n header: Schema.OptionFromNullOr(Address.fields.column),\n })\n type Model = typeof Model.Type\n const Message = defineMessageUnion({\n /** A cell became current: the user focused it, or a key moved there. */\n Focused: { address: Address },\n /** Focus went up to a column's header. */\n HeaderFocused: { column: Address.fields.column },\n })\n const bundle = Bundle.make('GridFocus', {\n Model,\n Message,\n init: () => ({ model: { current: Option.none(), header: Option.none() } }),\n update: (model: Model, message: typeof Message.Type) => ({\n model: Message.match(message, {\n Focused: ({ address }) =>\n Option.isNone(model.header) &&\n Option.isSome(model.current) &&\n sameAddress(model.current.value, address)\n ? model\n : modifyFields(model, {\n current: () => Option.some(address),\n header: () => Option.none(),\n }),\n HeaderFocused: ({ column }) =>\n Option.contains(model.header, column)\n ? model\n : modifyFields(model, { header: () => Option.some(column) }),\n }),\n }),\n })\n return { Address, Model, Message, bundle }\n}\n\nexport const GridFocus = { make, target, tabStop, cellId, cellOf, headerId, headerOf }\n","import { Option, Schema } from 'effect'\nimport { defineTaggedUnion } from 'foldkit/schema'\nimport type { KeyboardModifiers } from 'foldkit/html'\nimport type { Direction } from './focus.js'\nimport type { CellAddress, CellBox, GridProjection } from './projection.js'\n\n/**\n * Which rows are selected. `Keys` names them; `AllExcept` is every row but\n * these, so select-all holds whatever the rows are, loaded or not, and\n * however many there turn out to be.\n */\nexport const RowSelection = defineTaggedUnion({\n Keys: { keys: Schema.Array(Schema.String) },\n AllExcept: { except: Schema.Array(Schema.String) },\n})\nexport type RowSelection = typeof RowSelection.Type\n\nconst none = RowSelection.Keys({ keys: [] })\n\n// One lookup per selection value, so drawing a window of rows asks a Set.\nconst lookups = new WeakMap<RowSelection, (key: string) => boolean>()\n\n/** Whether a row is selected. Call it once per selection: it indexes the keys. */\nconst isSelected = (selection: RowSelection): ((key: string) => boolean) => {\n const cached = lookups.get(selection)\n if (cached !== undefined) return cached\n const lookup = RowSelection.match(selection, {\n Keys: ({ keys }) => {\n const set = new Set(keys)\n return (key: string) => set.has(key)\n },\n AllExcept: ({ except }) => {\n const set = new Set(except)\n return (key: string) => !set.has(key)\n },\n })\n lookups.set(selection, lookup)\n return lookup\n}\n\n/** Selects a row, or deselects it if it is selected. */\nconst toggle = (selection: RowSelection, key: string): RowSelection => {\n const selected = isSelected(selection)(key)\n return RowSelection.match(selection, {\n Keys: ({ keys }) =>\n RowSelection.Keys({ keys: selected ? keys.filter(each => each !== key) : [...keys, key] }),\n AllExcept: ({ except }) =>\n RowSelection.AllExcept({\n except: selected ? [...except, key] : except.filter(each => each !== key),\n }),\n })\n}\n\n/** Selects every row in `keys`, keeping what was selected. */\nconst add = (selection: RowSelection, keys: ReadonlyArray<string>): RowSelection => {\n const selected = isSelected(selection)\n const fresh = keys.filter(key => !selected(key))\n if (fresh.length === 0) return selection\n return RowSelection.match(selection, {\n Keys: ({ keys: held }) => RowSelection.Keys({ keys: [...held, ...new Set(fresh)] }),\n AllExcept: ({ except }) => {\n const adding = new Set(fresh)\n return RowSelection.AllExcept({ except: except.filter(key => !adding.has(key)) })\n },\n })\n}\n\n/** The keys of the rows from `from` to `to`, in the projection's order, both included. */\nconst rowsBetween = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n from: string,\n to: string,\n): ReadonlyArray<string> => {\n const keys: Array<string> = []\n const ends = Option.all([projection.rowIndex(from), projection.rowIndex(to)])\n if (Option.isNone(ends)) return keys\n const [a, b] = ends.value\n for (let index = Math.min(a, b); index <= Math.max(a, b); index++) {\n const key = projection.rows.keyAt(index)\n if (Option.isSome(key)) keys.push(key.value)\n }\n return keys\n}\n\n/** A rectangle of cells, named by its corners, so it survives a re-sort as two cells. */\nexport interface CellRange<Id extends string> {\n readonly anchor: CellAddress<Id>\n readonly focus: CellAddress<Id>\n}\n\n/** The cells a range covers now, or none when a corner is hidden or gone. */\nconst boxOf = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n range: CellRange<Id>,\n): Option.Option<CellBox<Id>> => projection.box(range.anchor, range.focus)\n\nexport interface ExtendOptions<Id extends string> {\n readonly range: Option.Option<CellRange<Id>>\n /** The focused cell: a range grows from it when there is none. */\n readonly current: Option.Option<CellAddress<Id>>\n readonly key: string\n readonly modifiers: KeyboardModifiers\n readonly pageRows: number\n readonly direction?: Direction\n}\n\nconst arrows: ReadonlyMap<string, { readonly rows: number; readonly columns: number }> = new Map([\n ['ArrowUp', { rows: -1, columns: 0 }],\n ['ArrowDown', { rows: 1, columns: 0 }],\n ['ArrowLeft', { rows: 0, columns: -1 }],\n ['ArrowRight', { rows: 0, columns: 1 }],\n])\n\n/** Where a Shift key takes a range's far corner, or none when it is not such a key. */\nconst farCorner = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n focus: CellAddress<Id>,\n options: ExtendOptions<Id>,\n): Option.Option<Option.Option<CellAddress<Id>>> => {\n const step = arrows.get(options.key)\n if (step !== undefined) {\n const flip = options.direction === 'rtl' ? -1 : 1\n return Option.some(projection.moveBy(focus, { rows: step.rows, columns: step.columns * flip }))\n }\n const moves: Readonly<Record<string, () => Option.Option<CellAddress<Id>>>> = {\n PageDown: () => projection.moveBy(focus, { rows: options.pageRows }),\n PageUp: () => projection.moveBy(focus, { rows: -options.pageRows }),\n Home: () => projection.rowStart(focus),\n End: () => projection.rowEnd(focus),\n }\n return Object.hasOwn(moves, options.key) ? Option.some(moves[options.key]!()) : Option.none()\n}\n\n/**\n * The range a Shift key makes, or none when the key is not one: Shift with an\n * arrow moves the range's far corner a cell, with PageUp or PageDown a page,\n * with Home or End to the row's edge. The near corner stays where the range\n * began, the focused cell when there was none. As with focus, a key the grid\n * handles always lands: at an edge, or before a row not loaded, the range\n * stays as it is.\n */\nconst extend = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n options: ExtendOptions<Id>,\n): Option.Option<CellRange<Id>> => {\n const { modifiers } = options\n if (!modifiers.shiftKey || modifiers.altKey || modifiers.metaKey || modifiers.ctrlKey) {\n return Option.none()\n }\n const start = Option.orElse(options.range, () =>\n Option.map(options.current, current => ({ anchor: current, focus: current })),\n )\n return Option.flatMap(start, range =>\n Option.map(farCorner(projection, range.focus, options), to =>\n Option.match(to, {\n onNone: () => range,\n onSome: focus => ({ anchor: range.anchor, focus }),\n }),\n ),\n )\n}\n\nexport const GridSelection = { none, isSelected, toggle, add, rowsBetween, boxOf, extend }\n","import { Effect, Queue, Schema, Stream } from 'effect'\nimport type { Command } from 'foldkit/command'\nimport { defineMessageUnion } from 'foldkit/message'\nimport * as Mount from 'foldkit/mount'\nimport { modifyFields } from 'foldkit/struct'\nimport { Bundle } from 'foldkit-bundle'\nimport type { Viewport } from './virtual.js'\n\nconst Model = Schema.Struct({\n top: Schema.Number,\n left: Schema.Number,\n width: Schema.Number,\n height: Schema.Number,\n})\ntype Model = typeof Model.Type\n\nconst Message = defineMessageUnion({\n /** The scroll container moved or changed size; the Mount reports it. */\n Measured: {\n top: Schema.Number,\n left: Schema.Number,\n width: Schema.Number,\n height: Schema.Number,\n },\n /** A reveal set the scroll offsets; the container's own scroll event confirms it later. */\n Revealed: { top: Schema.Number, left: Schema.Number },\n})\ntype Message = typeof Message.Type\n\n// A detached element measures NaN, and an overscroll less than nothing; neither\n// may reach the window math. An unchanged reading returns the Model it was given.\nconst write = (model: Model, next: ReadonlyArray<readonly [keyof Model, number]>): Model => {\n const fields: Partial<Record<keyof Model, () => number>> = {}\n for (const [key, value] of next) {\n const clean = Math.max(0, value)\n if (Number.isFinite(value) && clean !== model[key]) fields[key] = () => clean\n }\n return Object.keys(fields).length === 0 ? model : modifyFields(model, fields)\n}\n\n/**\n * The scroll container's geometry, as the window math reads it. The grid\n * owns no scroll position of its own: the container's is the fact, reported\n * by the `Measure` Mount, and a reveal moves the container.\n */\nconst bundle = Bundle.make('GridViewport', {\n Model,\n Message,\n init: () => ({ model: { top: 0, left: 0, width: 0, height: 0 } }),\n update: (model: Model, message: Message) => ({\n model: Message.match(message, {\n Measured: ({ top, left, width, height }) =>\n write(model, [\n ['top', top],\n ['left', left],\n ['width', width],\n ['height', height],\n ]),\n Revealed: ({ top, left }) =>\n write(model, [\n ['top', top],\n ['left', left],\n ]),\n }),\n }),\n})\n\ninterface Scroller {\n readonly scrollTop: number\n readonly scrollLeft: number\n readonly clientWidth: number\n readonly clientHeight: number\n}\n\ntype ResizeObserverCtor = new (callback: () => void) => ResizeObserver\n\n/**\n * Reports the element's scroll offsets and size: once when it mounts, then on\n * every scroll and every resize. Attach it to the scroll container. Without\n * `ResizeObserver` (a test DOM) it still reports scrolls.\n */\nconst Measure = Mount.defineStream('GridViewportMeasure', {\n messages: [Message.Measured],\n execute: ({ element }) =>\n Stream.callback<typeof Message.Measured.Type>(queue =>\n Effect.gen(function* () {\n const scroller = element as unknown as Scroller\n const report = () =>\n Queue.offerUnsafe(\n queue,\n Message.Measured({\n top: scroller.scrollTop,\n left: scroller.scrollLeft,\n width: scroller.clientWidth,\n height: scroller.clientHeight,\n }),\n )\n const Observer = (globalThis as { ResizeObserver?: ResizeObserverCtor }).ResizeObserver\n yield* Effect.acquireRelease(\n Effect.sync(() => {\n // Built before anything listens, so a constructor that throws leaves nothing attached.\n const observer = Observer === undefined ? undefined : new Observer(report)\n element.addEventListener('scroll', report, { passive: true })\n observer?.observe(element)\n report()\n return observer\n }),\n observer =>\n Effect.sync(() => {\n element.removeEventListener('scroll', report)\n observer?.disconnect()\n }),\n )\n }),\n ),\n})\n\n/**\n * Scrolls the container with this DOM id to `offsets` (from\n * `VirtualGrid.reveal`) and reports `Revealed`, so the next window is drawn\n * from the new offsets at once rather than after the scroll event.\n */\nconst scrollTo = (\n viewportId: string,\n offsets: Pick<Viewport, 'top' | 'left'>,\n): Command<Message> => ({\n name: 'GridViewport.scrollTo',\n args: { viewportId, ...offsets },\n effect: Effect.sync(() => {\n const element = typeof document === 'undefined' ? null : document.getElementById(viewportId)\n // A DOM with no layout (jsdom, in a test) has no scrollTo and nothing to scroll.\n if (element !== null && typeof element.scrollTo === 'function') {\n element.scrollTo({ top: offsets.top, left: offsets.left })\n }\n return Message.Revealed(offsets)\n }),\n})\n\nexport const GridViewport = { Model, Message, bundle, Measure, scrollTo }\n","import { Option } from 'effect'\nimport type { CellPosition, GridProjection } from './projection.js'\nimport { addressableRows } from './rows.js'\n\n/** The scroll container's offsets and size, in pixels. */\nexport interface Viewport {\n readonly top: number\n readonly left: number\n readonly width: number\n readonly height: number\n}\n\n/** Rendered items `[start, end)` on one axis, with the space the rest take before and after. */\nexport interface AxisWindow {\n readonly start: number\n readonly end: number\n readonly before: number\n readonly after: number\n}\n\nexport interface GridWindow<Id extends string> {\n /** Row indexes to render; every row is `rowHeight` tall. */\n readonly rows: AxisWindow\n /** Center columns to render, as indexes into `projection.center`. */\n readonly center: AxisWindow\n /** The center columns in that window, in display order. */\n readonly centerColumns: ReadonlyArray<Id>\n /** Pinned columns are always rendered: they never scroll horizontally. */\n readonly start: ReadonlyArray<Id>\n readonly end: ReadonlyArray<Id>\n /** The scrollable content's full size. */\n readonly width: number\n readonly height: number\n}\n\nexport interface Geometry<Row, Id extends string> {\n readonly projection: GridProjection<Row, Id>\n readonly rowHeight: number\n /** Width of each visible column. */\n readonly width: (column: NoInfer<Id>) => number\n /** Height of the header rows inside the scroll container, above the body. */\n readonly headerHeight?: number\n}\n\nexport interface WindowOptions<Row, Id extends string> extends Geometry<Row, Id> {\n readonly viewport: Viewport\n /** Extra rows and columns rendered beyond each edge, so a fast scroll shows no gap. */\n readonly overscan?: { readonly rows?: number; readonly columns?: number }\n}\n\nconst sum = (values: ReadonlyArray<number>): number =>\n values.reduce((total, value) => total + value, 0)\n\n/** `edges[i]` is where center column `i` begins; `edges[count]` is the center's width. */\nconst edgesOf = <Id extends string>(\n ids: ReadonlyArray<Id>,\n width: (column: Id) => number,\n): Float64Array => {\n const edges = new Float64Array(ids.length + 1)\n ids.forEach((id, index) => {\n edges[index + 1] = edges[index]! + Math.max(0, width(id))\n })\n return edges\n}\n\n/** How many of `0..count-1` satisfy `holds`, which holds for a prefix of them: a binary search. */\nconst prefixWhere = (count: number, holds: (index: number) => boolean): number => {\n let low = 0\n let high = count\n while (low < high) {\n const middle = (low + high) >>> 1\n if (holds(middle)) low = middle + 1\n else high = middle\n }\n return low\n}\n\ninterface Layout<Id extends string> {\n readonly rowCount: number\n readonly bodyHeight: number\n readonly centerWidth: number\n readonly edges: Float64Array\n readonly startWidth: number\n readonly endWidth: number\n readonly center: ReadonlyArray<Id>\n}\n\nconst layoutOf = <Row, Id extends string>(\n geometry: Geometry<Row, Id>,\n viewport: Viewport,\n): Layout<Id> => {\n const { projection, width, rowHeight } = geometry\n if (!(Number.isFinite(rowHeight) && rowHeight > 0)) {\n throw new Error(`VirtualGrid: rowHeight must be a positive number of pixels, not ${rowHeight}.`)\n }\n const startWidth = sum(projection.start.map(id => Math.max(0, width(id))))\n const endWidth = sum(projection.end.map(id => Math.max(0, width(id))))\n return {\n rowCount: addressableRows(projection.rowCount),\n bodyHeight: Math.max(0, viewport.height - (geometry.headerHeight ?? 0)),\n centerWidth: Math.max(0, viewport.width - startWidth - endWidth),\n edges: edgesOf(projection.center, width),\n startWidth,\n endWidth,\n center: projection.center,\n }\n}\n\n/**\n * What to render for a viewport: the rows and center columns it shows, plus\n * overscan, and the space the rest take. Rows are one fixed height, so the\n * row window is arithmetic on the scroll offset and never walks the rows; the\n * column window is a binary search over the center columns' widths. The\n * pinned columns are always rendered, outside the horizontal window.\n */\nconst window = <Row, Id extends string>(options: WindowOptions<Row, Id>): GridWindow<Id> => {\n const { viewport, rowHeight } = options\n const layout = layoutOf(options, viewport)\n const overRows = Math.max(0, Math.trunc(options.overscan?.rows ?? 0))\n const overColumns = Math.max(0, Math.trunc(options.overscan?.columns ?? 0))\n\n const top = Math.max(0, viewport.top)\n const firstRow = Math.floor(top / rowHeight)\n const pastRow = Math.ceil((top + layout.bodyHeight) / rowHeight)\n const rowStart = Math.min(layout.rowCount, Math.max(0, firstRow - overRows))\n const rowEnd = Math.min(layout.rowCount, Math.max(rowStart, pastRow + overRows))\n\n // A column is shown when it ends after the left edge and begins before the right.\n const { edges } = layout\n const count = layout.center.length\n const totalCenter = edges[count]!\n const left = Math.max(0, viewport.left)\n const right = left + layout.centerWidth\n const firstColumn = prefixWhere(count, index => edges[index + 1]! <= left)\n const pastColumn = Math.max(\n firstColumn,\n prefixWhere(count, index => edges[index]! < right),\n )\n const columnStart = Math.max(0, firstColumn - overColumns)\n const columnEnd = Math.min(count, pastColumn + overColumns)\n\n return {\n rows: {\n start: rowStart,\n end: rowEnd,\n before: rowStart * rowHeight,\n after: (layout.rowCount - rowEnd) * rowHeight,\n },\n center: {\n start: columnStart,\n end: columnEnd,\n before: edges[columnStart]!,\n after: totalCenter - edges[columnEnd]!,\n },\n centerColumns: layout.center.slice(columnStart, columnEnd),\n start: options.projection.start,\n end: options.projection.end,\n width: layout.startWidth + totalCenter + layout.endWidth,\n height: (options.headerHeight ?? 0) + layout.rowCount * rowHeight,\n }\n}\n\nexport interface RevealOptions<Row, Id extends string> extends Geometry<Row, Id> {\n readonly viewport: Viewport\n readonly position: CellPosition\n}\n\n/**\n * The scroll offsets that bring a cell fully into view, moving each axis the\n * least it can, or none when it is already in view. A pinned column never\n * scrolls, so only its row is brought in.\n */\nconst reveal = <Row, Id extends string>(\n options: RevealOptions<Row, Id>,\n): Option.Option<{ readonly top: number; readonly left: number }> => {\n const { viewport, position, rowHeight, projection } = options\n const layout = layoutOf(options, viewport)\n // The least scroll that shows `[from, from + size)` in a span of `span` at `offset`.\n const nearest = (offset: number, from: number, size: number, span: number): number => {\n if (from < offset) return from\n if (from + size > offset + span) return Math.max(0, from + size - span)\n return offset\n }\n\n const top = nearest(viewport.top, position.row * rowHeight, rowHeight, layout.bodyHeight)\n const centerIndex = position.column - projection.start.length\n // A pinned column is outside the center, and stays where it is drawn.\n const left =\n layout.center[centerIndex] !== undefined\n ? nearest(\n viewport.left,\n layout.edges[centerIndex]!,\n layout.edges[centerIndex + 1]! - layout.edges[centerIndex]!,\n layout.centerWidth,\n )\n : viewport.left\n return top === viewport.top && left === viewport.left ? Option.none() : Option.some({ top, left })\n}\n\nexport const VirtualGrid = { window, reveal }\n","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 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 (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 /** 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 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":";;;;;;;;AAiBA,MAAM,cAAc;AAEpB,MAAM,SAAS,SACb,YAAY,KAAK,IAAI,IAAI,IAAI,KAAK,WAAW,MAAK,MAAI,EAAE,KAAK;;AAG/D,MAAM,SAAS,SACb,KAAK,KAAI,QAAO,IAAI,IAAI,KAAK,CAAC,CAAC,KAAK,GAAI,CAAC,CAAC,CAAC,KAAK,IAAI;;;;;;AAOtD,MAAM,YAAY,SAAuD;CACvE,MAAM,OAA6B,CAAC;CACpC,IAAI,MAAqB,CAAC;CAC1B,IAAI,OAAO;CACX,IAAI,SAAS;CACb,IAAI,QAAQ;CACZ,MAAM,gBAAgB;EACpB,IAAI,KAAK,IAAI;EACb,OAAO;CACT;CACA,MAAM,eAAe;EACnB,QAAQ;EACR,KAAK,KAAK,GAAG;EACb,MAAM,CAAC;CACT;CACA,OAAO,QAAQ,KAAK,QAAQ;EAC1B,MAAM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AM;GAAE;GAAO;EAAW,CAAC;EAC3C,OAAO;CACT;;;;;CAMA,MAAM,UAAU,UAOd,YAAY,OAAO;EACjB,YAAY,QAAQ,MAAM,MAAM,MAAM,MAAM,OAAO;EACnD,WAAW,MAAM;EACjB,OAAO,YAAY,QAAQ,MAAM,MAAM,OAAO;EAC9C,cAAc,MAAM;EACpB,UAAU,MAAM,MAAM;EACtB,GAAI,MAAM,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,UAAU,MAAM,SAAS;CACrE,CAAC;CAEH,OAAO;EACL,IAAI,QAAQ;EACZ;EACA;EACA;EACA;EACA,SAAS,QAAQ;EACjB,cAAc,QAAQ;EACtB,eAAe,QAAQ,kBAAkB;EACzC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;AAEA,MAAa,WAAW,EAAE,KAAK"}
1
+ {"version":3,"file":"index.mjs","names":["make","arrows","make"],"sources":["../src/clipboard.ts","../src/fill.ts","../src/layout.ts","../src/columnState.ts","../src/projection.ts","../src/focus.ts","../src/selection.ts","../src/viewport.ts","../src/virtual.ts","../src/grid.ts"],"sourcesContent":["import { Option } from 'effect'\nimport type { CellAddress, CellBox, GridProjection } from './projection.js'\n\n/** One cell's text in a paste, by identity: what the grid hands the application. */\nexport interface CellText<Id extends string> {\n readonly row: string\n readonly column: Id\n readonly text: string\n}\n\n/** A pasted cell, with the text it showed before, so an unchanged one is no edit. */\nexport interface PastedCell<Id extends string> extends CellText<Id> {\n readonly from: string\n}\n\n// A cell holding a tab, a line break or a quote is quoted, its quotes doubled,\n// as spreadsheets write and read tab-separated text.\nconst needsQuotes = /[\\t\\n\\r\"]/\n\nconst quote = (cell: string): string =>\n needsQuotes.test(cell) ? `\"${cell.replaceAll('\"', '\"\"')}\"` : cell\n\n/** Rows of cells as tab-separated text, the form spreadsheets copy and paste. */\nconst toTsv = (rows: ReadonlyArray<ReadonlyArray<string>>): string =>\n rows.map(row => row.map(quote).join('\\t')).join('\\n')\n\n/**\n * Tab-separated text as rows of cells. Quoted cells may hold tabs, line\n * breaks and doubled quotes; `\\r\\n` and `\\r` end a row as `\\n` does; the line\n * break a spreadsheet adds after the last row makes no empty row.\n */\nconst parseTsv = (text: string): ReadonlyArray<ReadonlyArray<string>> => {\n const rows: Array<Array<string>> = []\n let row: Array<string> = []\n let cell = ''\n let quoted = false\n let index = 0\n const endCell = () => {\n row.push(cell)\n cell = ''\n }\n const endRow = () => {\n endCell()\n rows.push(row)\n row = []\n }\n while (index < text.length) {\n const char = text[index]!\n if (quoted) {\n if (char === '\"' && text[index + 1] === '\"') {\n cell += '\"'\n index += 2\n continue\n }\n if (char === '\"') quoted = false\n else cell += char\n index += 1\n continue\n }\n if (char === '\"' && cell === '') quoted = true\n else if (char === '\\t') endCell()\n else if (char === '\\r' || char === '\\n') {\n endRow()\n if (char === '\\r' && text[index + 1] === '\\n') index += 1\n } else cell += char\n index += 1\n }\n // Text that ends in a line break has said all its rows.\n if (cell !== '' || row.length > 0) endRow()\n return rows\n}\n\n/**\n * The text of the cells a box covers, row by row in the projection's order\n * and column by column in display order. A row counted but not loaded copies\n * as empty cells, so the shape is the box's.\n */\nconst copy = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n box: CellBox<Id>,\n textOf: (address: CellAddress<Id>) => string,\n): string => {\n const rows: Array<ReadonlyArray<string>> = []\n for (let index = box.rows.start; index < box.rows.end; index++) {\n const key = projection.rows.keyAt(index)\n rows.push(\n box.columns.map(column =>\n Option.match(key, { onNone: () => '', onSome: row => textOf({ row, column }) }),\n ),\n )\n }\n return toTsv(rows)\n}\n\n/**\n * Where pasted cells land: the matrix laid from `anchor` across rows in the\n * projection's order and columns in display order. Cells past the grid's\n * edges are dropped, as are those landing on a column that does not edit or\n * a row not loaded; the rest keep their place, each with `from`, the text\n * the cell showed (the text an edit of it would begin from).\n */\nconst pasteAt = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n anchor: CellAddress<Id>,\n matrix: ReadonlyArray<ReadonlyArray<string>>,\n cells: {\n readonly editable: (column: Id) => boolean\n readonly from: (address: CellAddress<Id>) => string\n },\n): ReadonlyArray<PastedCell<Id>> =>\n Option.match(projection.positionOf(anchor), {\n onNone: () => [],\n onSome: start => {\n const landed: Array<PastedCell<Id>> = []\n matrix.forEach((texts, down) => {\n const key = projection.rows.keyAt(start.row + down)\n if (Option.isNone(key)) return\n const row = key.value\n texts.forEach((text, across) => {\n const column = projection.columns[start.column + across]\n if (column !== undefined && cells.editable(column)) {\n landed.push({ row, column, text, from: cells.from({ row, column }) })\n }\n })\n })\n return landed\n },\n })\n\nexport const Clipboard = { toTsv, parseTsv, copy, pasteAt }\n","import { Option } from 'effect'\nimport type { PastedCell } from './clipboard.js'\nimport type { CellAddress, CellBox, GridProjection } from './projection.js'\n\n/** A fill: the range whose cells are carried on, and the cell it was carried to. */\nexport interface FillRequest<Id extends string> {\n readonly source: { readonly anchor: CellAddress<Id>; readonly focus: CellAddress<Id> }\n readonly to: CellAddress<Id>\n}\n\n/**\n * Where a fill lands: the source's box, and the box it fills beyond it, down,\n * up, right or left, whichever way `to` lies further outside the source. A\n * fill carries on along one axis only, as spreadsheets do.\n */\nexport interface FillPlan<Id extends string> {\n readonly source: CellBox<Id>\n readonly target: CellBox<Id>\n /** Rows (`down`/`up`) or columns (`right`/`left`), away from the source. */\n readonly toward: 'down' | 'up' | 'right' | 'left'\n}\n\nconst number = /^-?\\d+(?:\\.(\\d+))?$/\n\n/**\n * The texts that carry `source` on for `count` cells, the first of them next\n * to it. Two or more numbers a constant step apart continue their step, with\n * as many decimals as the most precise of them; anything else repeats, in\n * order. `backward` carries the source on before its first text, as filling\n * up or left does.\n */\nconst series = (\n source: ReadonlyArray<string>,\n count: number,\n backward: boolean,\n): ReadonlyArray<string> => {\n const at = (index: number) => source[((index % source.length) + source.length) % source.length]!\n const repeated = Array.from({ length: count }, (_, index) =>\n backward ? at(-1 - index) : at(source.length + index),\n )\n if (source.length < 2) return repeated\n const parsed = source.map(text => number.exec(text.trim()))\n if (parsed.some(match => match === null)) return repeated\n const decimals = Math.max(...parsed.map(match => match![1]?.length ?? 0))\n // Whole units of the finest decimal, so a step of 0.1 adds up exactly.\n const scale = 10 ** decimals\n const units = source.map(text => Math.round(Number(text.trim()) * scale))\n const step = units[1]! - units[0]!\n if (units.some((unit, index) => index > 0 && unit - units[index - 1]! !== step)) return repeated\n const from = backward ? units[0]! : units[units.length - 1]!\n return Array.from({ length: count }, (_, index) =>\n ((from + (backward ? -step : step) * (index + 1)) / scale).toFixed(decimals),\n )\n}\n\n/** The source's box and the box beyond it toward `to`; none when `to` is inside it. */\nconst plan = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n request: FillRequest<Id>,\n): Option.Option<FillPlan<Id>> =>\n Option.flatMap(projection.box(request.source.anchor, request.source.focus), source =>\n Option.flatMap(projection.positionOf(request.to), to => {\n const first = projection.columns.indexOf(source.columns[0]!)\n const last = first + source.columns.length - 1\n const below = to.row - (source.rows.end - 1)\n const above = source.rows.start - to.row\n const right = to.column - last\n const left = first - to.column\n const rows = Math.max(below, above)\n const columns = Math.max(right, left)\n if (rows <= 0 && columns <= 0) return Option.none()\n if (rows >= columns) {\n const target =\n below > 0\n ? { start: source.rows.end, end: to.row + 1 }\n : { start: to.row, end: source.rows.start }\n return Option.some({\n source,\n target: { rows: target, columns: source.columns },\n toward: below > 0 ? 'down' : 'up',\n })\n }\n const columnsOf = (start: number, end: number) => projection.columns.slice(start, end)\n return Option.some({\n source,\n target: {\n rows: source.rows,\n columns: right > 0 ? columnsOf(last + 1, to.column + 1) : columnsOf(to.column, first),\n },\n toward: right > 0 ? 'right' : 'left',\n })\n }),\n )\n\n/**\n * The cells a fill writes: each lane of the source (a column for a fill down\n * or up, a row for one right or left) carried on through the target by\n * `series`. Cells on a column that does not edit, or on a row not loaded, are\n * dropped; each kept cell has `from`, the text it showed.\n */\nconst cells = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n fill: FillPlan<Id>,\n options: {\n readonly editable: (column: Id) => boolean\n readonly from: (address: CellAddress<Id>) => string\n },\n): ReadonlyArray<PastedCell<Id>> => {\n const rowsOf = (box: { readonly start: number; readonly end: number }) =>\n Array.from({ length: box.end - box.start }, (_, offset) => box.start + offset)\n const keyAt = (index: number) => projection.rows.keyAt(index)\n const textAt = (index: number, column: Id) =>\n Option.match(keyAt(index), { onNone: () => '', onSome: row => options.from({ row, column }) })\n const cell = (index: number, column: Id, text: string): ReadonlyArray<PastedCell<Id>> =>\n options.editable(column)\n ? Option.match(keyAt(index), {\n onNone: () => [],\n onSome: row => [{ row, column, text, from: options.from({ row, column }) }],\n })\n : []\n const backward = fill.toward === 'up' || fill.toward === 'left'\n // Away from the source, so the series' first text lands next to it.\n const away = <A>(items: ReadonlyArray<A>) => (backward ? [...items].reverse() : items)\n if (fill.toward === 'down' || fill.toward === 'up') {\n const targetRows = away(rowsOf(fill.target.rows))\n return fill.source.columns.flatMap(column => {\n const texts = series(\n rowsOf(fill.source.rows).map(index => textAt(index, column)),\n targetRows.length,\n backward,\n )\n return targetRows.flatMap((index, at) => cell(index, column, texts[at]!))\n })\n }\n const targetColumns = away(fill.target.columns)\n return rowsOf(fill.source.rows).flatMap(index => {\n const texts = series(\n fill.source.columns.map(column => textAt(index, column)),\n targetColumns.length,\n backward,\n )\n return targetColumns.flatMap((column, at) => cell(index, column, texts[at]!))\n })\n}\n\nexport const Fill = { series, plan, cells }\n","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","import { Option, Schema } from 'effect'\nimport { Columns, type ColumnSpec } from './columns.js'\nimport { ColumnLayout } from './layout.js'\n\nexport type Region = 'start' | 'center' | 'end'\n\nconst regions: ReadonlyArray<Region> = ['start', 'center', 'end']\n\n/**\n * Where each column stands and how wide the resized ones are. Widths list only\n * the columns resized; the rest take their spec's. The grid owns it, and it is\n * plain data, so an application can save it and restore it.\n */\nexport interface ColumnState<Id extends string> extends ColumnLayout<Id> {\n readonly widths: ReadonlyArray<{ readonly column: Id; readonly width: number }>\n}\n\n/** What `restore` made of a saved state: the state, and the ids it had to drop. */\nexport interface Restored<Id extends string> {\n readonly state: ColumnState<Id>\n /** Ids the saved state named that these columns do not define, or named twice. */\n readonly dropped: ReadonlyArray<string>\n}\n\nconst Saved = Schema.Struct({\n start: Schema.Array(Schema.String),\n center: Schema.Array(Schema.String),\n end: Schema.Array(Schema.String),\n hidden: Schema.Array(Schema.String),\n widths: Schema.Array(Schema.Struct({ column: Schema.String, width: Schema.Number })),\n})\n\nconst without = <Id extends string>(ids: ReadonlyArray<Id>, id: Id): ReadonlyArray<Id> =>\n ids.filter(each => each !== id)\n\n/**\n * Column state for one grid's columns: its Schema, which decodes only these\n * columns' ids, and the operations a grid's Messages run. Every operation\n * returns the state it was given when it changes nothing, so a no-op draws\n * nothing.\n */\nconst make = <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(\n columns: Columns<Row, Specs>,\n) => {\n type Id = keyof Specs & string\n type State = ColumnState<Id>\n const Ids = Schema.Literals(columns.ids)\n const Model = Schema.Struct({\n start: Schema.Array(Ids),\n center: Schema.Array(Ids),\n end: Schema.Array(Ids),\n hidden: Schema.Array(Ids),\n widths: Schema.Array(Schema.Struct({ column: Ids, width: Schema.Number })),\n })\n\n const spec = (id: Id) => columns.byId[id]\n const isColumn = (id: string): id is Id => Object.hasOwn(columns.byId, id)\n const clampWidth = (id: Id, width: number): number => {\n const { minWidth = Columns.minWidth, maxWidth = Number.POSITIVE_INFINITY } = spec(id)\n return Math.min(Math.max(width, minWidth), maxWidth)\n }\n\n const initial = (): State => ({ ...ColumnLayout.initial(columns), widths: [] })\n\n /** The width each column is drawn at: its resize, else its spec's. Call once per state. */\n const widthOf = (state: State): ((id: Id) => number) => {\n const resized = new Map(state.widths.map(entry => [entry.column, entry.width]))\n return id => resized.get(id) ?? spec(id).width ?? Columns.defaultWidth\n }\n\n const regionOf = (state: State, id: Id): Region =>\n regions.find(region => state[region].includes(id)) ?? 'center'\n\n /** Resizes a resizable column, within its `minWidth` and `maxWidth`. */\n const resize = (state: State, id: Id, width: number): State => {\n if (spec(id).resizable === false || !Number.isFinite(width)) return state\n const clamped = clampWidth(id, width)\n if (clamped === widthOf(state)(id)) return state\n return {\n ...state,\n widths: [\n ...state.widths.filter(entry => entry.column !== id),\n { column: id, width: clamped },\n ],\n }\n }\n\n const visibleCount = (state: State): number => {\n const hidden = new Set(state.hidden)\n return regions.reduce(\n (count, region) => count + state[region].filter(id => !hidden.has(id)).length,\n 0,\n )\n }\n\n /** Hides a hideable column; the last one shown stays, so the grid keeps a cell to focus. */\n const hide = (state: State, id: Id): State => {\n if (spec(id).hideable === false || state.hidden.includes(id) || visibleCount(state) <= 1) {\n return state\n }\n return { ...state, hidden: [...state.hidden, id] }\n }\n\n const show = (state: State, id: Id): State =>\n state.hidden.includes(id) ? { ...state, hidden: without(state.hidden, id) } : state\n\n /**\n * Moves a column to `index` among the columns of `region`, counted with it\n * removed: a reorder within its region, or a pin or an unpin across them.\n */\n const move = (state: State, id: Id, region: Region, index: number): State => {\n const from = regionOf(state, id)\n const target = without(state[region], id)\n const at = Math.min(Math.max(0, Math.trunc(index)), target.length)\n if (from === region && state[region].indexOf(id) === at) return state\n const placed = [...target.slice(0, at), id, ...target.slice(at)]\n return { ...state, [from]: without(state[from], id), [region]: placed }\n }\n\n /**\n * Where a column dragged `delta` pixels toward its region's end lands, as\n * the index `move` takes in that region: past the middle of each shown\n * neighbour it crossed. A column that crosses none stays where it is, so\n * hidden columns keep their places; so do a hidden column and a delta that\n * is not a number.\n */\n const dropAt = (state: State, id: Id, delta: number): number => {\n const order = state[regionOf(state, id)]\n const here = order.indexOf(id)\n const hidden = new Set(state.hidden)\n if (hidden.has(id) || !Number.isFinite(delta)) return here\n const width = widthOf(state)\n const shown: Array<{ readonly id: Id; readonly middle: number }> = []\n let dragged = 0\n let before = 0\n let edge = 0\n for (const each of order) {\n if (hidden.has(each)) continue\n const middle = edge + width(each) / 2\n if (each === id) {\n dragged = middle + delta\n before = shown.length\n } else shown.push({ id: each, middle })\n edge += width(each)\n }\n // How many shown neighbours end up before it, in middle order.\n const passed = shown.filter(other => other.middle <= dragged).length\n if (passed === before) return here\n const others = without(order, id)\n return passed < shown.length\n ? others.indexOf(shown[passed]!.id)\n : others.indexOf(shown[passed - 1]!.id) + 1\n }\n\n /**\n * A saved state read back leniently: an id these columns no longer define,\n * or one named twice, is dropped and listed; a column the save predates\n * takes its initial place; a width is clamped to its column's limits.\n * Input that is not a saved state at all is the initial state, with nothing\n * dropped, since nothing was read.\n */\n const restore = (saved: unknown): Restored<Id> =>\n Option.match(Schema.decodeUnknownOption(Saved)(saved), {\n onNone: () => ({ state: initial(), dropped: [] }),\n onSome: value => {\n const dropped: Array<string> = []\n const saved = new Set<Id>()\n const keep = (ids: ReadonlyArray<string>): Array<Id> =>\n ids.filter((id): id is Id => {\n if (!isColumn(id) || saved.has(id)) {\n dropped.push(id)\n return false\n }\n saved.add(id)\n return true\n })\n const placed = {\n start: keep(value.start),\n center: keep(value.center),\n end: keep(value.end),\n }\n // A column the save predates takes its initial region and visibility.\n const fresh = initial()\n for (const region of regions) {\n for (const id of fresh[region]) if (!saved.has(id)) placed[region].push(id)\n }\n const hidden = new Set<Id>(fresh.hidden.filter(id => !saved.has(id)))\n for (const id of value.hidden) if (isColumn(id)) hidden.add(id)\n const widths = new Map<Id, number>()\n for (const entry of value.widths) {\n if (isColumn(entry.column) && Number.isFinite(entry.width)) {\n widths.set(entry.column, clampWidth(entry.column, entry.width))\n }\n }\n return {\n state: {\n ...placed,\n hidden: [...hidden],\n widths: [...widths].map(([column, width]) => ({ column, width })),\n },\n dropped,\n }\n },\n })\n\n return { Model, initial, widthOf, regionOf, resize, hide, show, move, dropAt, restore }\n}\n\nexport const ColumnState = { make }\n","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","import { Option, Schema } from 'effect'\nimport type { KeyboardModifiers } from 'foldkit/html'\nimport { defineMessageUnion } from 'foldkit/message'\nimport { modifyFields } from 'foldkit/struct'\nimport { Bundle } from 'foldkit-bundle'\nimport type { Columns, ColumnSpec } from './columns.js'\nimport { CellAddress, type GridProjection } from './projection.js'\n\nexport type Direction = 'ltr' | 'rtl'\n\nexport interface KeyOptions<Id extends string> {\n readonly current: Option.Option<CellAddress<Id>>\n readonly key: string\n readonly modifiers: KeyboardModifiers\n /** Default `'ltr'`; under `'rtl'` the left and right arrows swap. */\n readonly direction?: Direction\n /** How many rows PageUp and PageDown move: the rows a viewport shows. */\n readonly pageRows: number\n}\n\nconst sameAddress = <Id extends string>(a: CellAddress<Id>, b: CellAddress<Id>): boolean =>\n a.row === b.row && a.column === b.column\n\n/**\n * The cell that holds the grid's one tab stop: the focused cell while it is\n * shown, and otherwise the first cell. A focused cell whose column was hidden\n * or whose row went away stays in the Model, so focus returns to it if it\n * comes back, but the tab stop moves on until then.\n */\nconst tabStop = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n current: Option.Option<CellAddress<Id>>,\n): Option.Option<CellAddress<Id>> =>\n Option.orElse(\n Option.filter(current, address => Option.isSome(projection.positionOf(address))),\n () => projection.first(),\n )\n\nconst arrows: ReadonlyMap<string, { readonly rows: number; readonly columns: number }> = new Map([\n ['ArrowUp', { rows: -1, columns: 0 }],\n ['ArrowDown', { rows: 1, columns: 0 }],\n ['ArrowLeft', { rows: 0, columns: -1 }],\n ['ArrowRight', { rows: 0, columns: 1 }],\n])\n\n/**\n * The cell a key moves focus to, or none when the key is not the grid's to\n * handle, so the caller leaves it to the page. Arrows step one cell, Home and\n * End go to the row's edges and, with Ctrl, to the grid's corners; PageUp and\n * PageDown move `pageRows`. A key the grid handles always lands somewhere: at\n * an edge, or onto a row that is counted but not loaded, focus stays where it\n * is. Shift, Alt and Meta combinations are left alone: Shift extends a\n * selection, which is not focus's to decide.\n */\nconst target = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n options: KeyOptions<Id>,\n): Option.Option<CellAddress<Id>> => {\n const { key, modifiers } = options\n if (modifiers.shiftKey || modifiers.altKey || modifiers.metaKey) return Option.none()\n return Option.flatMap(tabStop(projection, options.current), from => {\n const stay = (to: Option.Option<CellAddress<Id>>) =>\n Option.some(Option.getOrElse(to, () => from))\n if (key === 'Home')\n return stay(modifiers.ctrlKey ? projection.first() : projection.rowStart(from))\n if (key === 'End') return stay(modifiers.ctrlKey ? projection.last() : projection.rowEnd(from))\n if (modifiers.ctrlKey) return Option.none()\n if (key === 'PageUp') return stay(projection.moveBy(from, { rows: -options.pageRows }))\n if (key === 'PageDown') return stay(projection.moveBy(from, { rows: options.pageRows }))\n const step = arrows.get(key)\n if (step === undefined) return Option.none()\n const flip = options.direction === 'rtl' ? -1 : 1\n return stay(projection.moveBy(from, { rows: step.rows, columns: step.columns * flip }))\n })\n}\n\n/**\n * A cell's DOM id: the grid's id, the row key and the column id, each\n * URI-encoded and joined by `:`, which encoding never leaves in a part, so no\n * two cells share an id. The container points at it with\n * `aria-activedescendant`.\n */\nconst cellId = <Id extends string>(grid: string, address: CellAddress<Id>): string =>\n [grid, address.row, address.column].map(encodeURIComponent).join(':')\n\nconst decode = Option.liftThrowable(decodeURIComponent)\n\n/**\n * The address a `cellId` names, if it is one of this grid's: its row key and\n * its column id as written, for the grid's columns to check. An id from\n * another grid, or with a malformed escape, is none.\n */\nconst cellOf = (\n grid: string,\n id: string,\n): Option.Option<{ readonly row: string; readonly column: string }> =>\n Option.map(partsOf(grid, id, 3), ([row, column]) => ({ row: row!, column: column! }))\n\n/** The parts of one of this grid's ids after the grid's own, when it has `count` parts in all. */\nconst partsOf = (grid: string, id: string, count: number): Option.Option<ReadonlyArray<string>> => {\n const parts = id.split(':')\n if (parts.length !== count) return Option.none()\n return Option.flatMap(Option.all(parts.map(part => decode(part))), ([owner, ...rest]) =>\n owner === grid ? Option.some(rest) : Option.none(),\n )\n}\n\n/**\n * A column header's DOM id: the grid's id and the column id, URI-encoded and\n * joined by `:`. It has two parts where a cell's has three, so the two never\n * meet.\n */\nconst headerId = (grid: string, column: string): string =>\n [grid, column].map(encodeURIComponent).join(':')\n\n/** The column a `headerId` names, if it is one of this grid's, as written. */\nconst headerOf = (grid: string, id: string): Option.Option<string> =>\n Option.map(partsOf(grid, id, 2), ([column]) => column!)\n\n/**\n * Focus for one grid: which cell is current, by identity. Make it once per\n * grid from its columns, so a focus saved in the Model decodes only against\n * columns that exist.\n */\nconst make = <Row, Specs extends Record<string, ColumnSpec<Row, unknown>>>(\n columns: Columns<Row, Specs>,\n) => {\n const Address = CellAddress.schema(columns)\n const Model = Schema.Struct({\n /** The focused cell; stored as `null` when none is. */\n current: Schema.OptionFromNullOr(Address),\n /**\n * The column header focus is on, when it is on the header row. The cell\n * focused before stays in `current`, so going back down returns to it.\n */\n header: Schema.OptionFromNullOr(Address.fields.column),\n })\n type Model = typeof Model.Type\n const Message = defineMessageUnion({\n /** A cell became current: the user focused it, or a key moved there. */\n Focused: { address: Address },\n /** Focus went up to a column's header. */\n HeaderFocused: { column: Address.fields.column },\n })\n const bundle = Bundle.make('GridFocus', {\n Model,\n Message,\n init: () => ({ model: { current: Option.none(), header: Option.none() } }),\n update: (model: Model, message: typeof Message.Type) => ({\n model: Message.match(message, {\n Focused: ({ address }) =>\n Option.isNone(model.header) &&\n Option.isSome(model.current) &&\n sameAddress(model.current.value, address)\n ? model\n : modifyFields(model, {\n current: () => Option.some(address),\n header: () => Option.none(),\n }),\n HeaderFocused: ({ column }) =>\n Option.contains(model.header, column)\n ? model\n : modifyFields(model, { header: () => Option.some(column) }),\n }),\n }),\n })\n return { Address, Model, Message, bundle }\n}\n\nexport const GridFocus = { make, target, tabStop, cellId, cellOf, headerId, headerOf }\n","import { Option, Schema } from 'effect'\nimport { defineTaggedUnion } from 'foldkit/schema'\nimport type { KeyboardModifiers } from 'foldkit/html'\nimport type { Direction } from './focus.js'\nimport type { CellAddress, CellBox, GridProjection } from './projection.js'\n\n/**\n * Which rows are selected. `Keys` names them; `AllExcept` is every row but\n * these, so select-all holds whatever the rows are, loaded or not, and\n * however many there turn out to be.\n */\nexport const RowSelection = defineTaggedUnion({\n Keys: { keys: Schema.Array(Schema.String) },\n AllExcept: { except: Schema.Array(Schema.String) },\n})\nexport type RowSelection = typeof RowSelection.Type\n\nconst none = RowSelection.Keys({ keys: [] })\n\n// One lookup per selection value, so drawing a window of rows asks a Set.\nconst lookups = new WeakMap<RowSelection, (key: string) => boolean>()\n\n/** Whether a row is selected. Call it once per selection: it indexes the keys. */\nconst isSelected = (selection: RowSelection): ((key: string) => boolean) => {\n const cached = lookups.get(selection)\n if (cached !== undefined) return cached\n const lookup = RowSelection.match(selection, {\n Keys: ({ keys }) => {\n const set = new Set(keys)\n return (key: string) => set.has(key)\n },\n AllExcept: ({ except }) => {\n const set = new Set(except)\n return (key: string) => !set.has(key)\n },\n })\n lookups.set(selection, lookup)\n return lookup\n}\n\n/** Selects a row, or deselects it if it is selected. */\nconst toggle = (selection: RowSelection, key: string): RowSelection => {\n const selected = isSelected(selection)(key)\n return RowSelection.match(selection, {\n Keys: ({ keys }) =>\n RowSelection.Keys({ keys: selected ? keys.filter(each => each !== key) : [...keys, key] }),\n AllExcept: ({ except }) =>\n RowSelection.AllExcept({\n except: selected ? [...except, key] : except.filter(each => each !== key),\n }),\n })\n}\n\n/** Selects every row in `keys`, keeping what was selected. */\nconst add = (selection: RowSelection, keys: ReadonlyArray<string>): RowSelection => {\n const selected = isSelected(selection)\n const fresh = keys.filter(key => !selected(key))\n if (fresh.length === 0) return selection\n return RowSelection.match(selection, {\n Keys: ({ keys: held }) => RowSelection.Keys({ keys: [...held, ...new Set(fresh)] }),\n AllExcept: ({ except }) => {\n const adding = new Set(fresh)\n return RowSelection.AllExcept({ except: except.filter(key => !adding.has(key)) })\n },\n })\n}\n\n/** The keys of the rows from `from` to `to`, in the projection's order, both included. */\nconst rowsBetween = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n from: string,\n to: string,\n): ReadonlyArray<string> => {\n const keys: Array<string> = []\n const ends = Option.all([projection.rowIndex(from), projection.rowIndex(to)])\n if (Option.isNone(ends)) return keys\n const [a, b] = ends.value\n for (let index = Math.min(a, b); index <= Math.max(a, b); index++) {\n const key = projection.rows.keyAt(index)\n if (Option.isSome(key)) keys.push(key.value)\n }\n return keys\n}\n\n/** A rectangle of cells, named by its corners, so it survives a re-sort as two cells. */\nexport interface CellRange<Id extends string> {\n readonly anchor: CellAddress<Id>\n readonly focus: CellAddress<Id>\n}\n\n/** The cells a range covers now, or none when a corner is hidden or gone. */\nconst boxOf = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n range: CellRange<Id>,\n): Option.Option<CellBox<Id>> => projection.box(range.anchor, range.focus)\n\nexport interface ExtendOptions<Id extends string> {\n readonly range: Option.Option<CellRange<Id>>\n /** The focused cell: a range grows from it when there is none. */\n readonly current: Option.Option<CellAddress<Id>>\n readonly key: string\n readonly modifiers: KeyboardModifiers\n readonly pageRows: number\n readonly direction?: Direction\n}\n\nconst arrows: ReadonlyMap<string, { readonly rows: number; readonly columns: number }> = new Map([\n ['ArrowUp', { rows: -1, columns: 0 }],\n ['ArrowDown', { rows: 1, columns: 0 }],\n ['ArrowLeft', { rows: 0, columns: -1 }],\n ['ArrowRight', { rows: 0, columns: 1 }],\n])\n\n/** Where a Shift key takes a range's far corner, or none when it is not such a key. */\nconst farCorner = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n focus: CellAddress<Id>,\n options: ExtendOptions<Id>,\n): Option.Option<Option.Option<CellAddress<Id>>> => {\n const step = arrows.get(options.key)\n if (step !== undefined) {\n const flip = options.direction === 'rtl' ? -1 : 1\n return Option.some(projection.moveBy(focus, { rows: step.rows, columns: step.columns * flip }))\n }\n const moves: Readonly<Record<string, () => Option.Option<CellAddress<Id>>>> = {\n PageDown: () => projection.moveBy(focus, { rows: options.pageRows }),\n PageUp: () => projection.moveBy(focus, { rows: -options.pageRows }),\n Home: () => projection.rowStart(focus),\n End: () => projection.rowEnd(focus),\n }\n return Object.hasOwn(moves, options.key) ? Option.some(moves[options.key]!()) : Option.none()\n}\n\n/**\n * The range a Shift key makes, or none when the key is not one: Shift with an\n * arrow moves the range's far corner a cell, with PageUp or PageDown a page,\n * with Home or End to the row's edge. The near corner stays where the range\n * began, the focused cell when there was none. As with focus, a key the grid\n * handles always lands: at an edge, or before a row not loaded, the range\n * stays as it is.\n */\nconst extend = <Row, Id extends string>(\n projection: GridProjection<Row, Id>,\n options: ExtendOptions<Id>,\n): Option.Option<CellRange<Id>> => {\n const { modifiers } = options\n if (!modifiers.shiftKey || modifiers.altKey || modifiers.metaKey || modifiers.ctrlKey) {\n return Option.none()\n }\n const start = Option.orElse(options.range, () =>\n Option.map(options.current, current => ({ anchor: current, focus: current })),\n )\n return Option.flatMap(start, range =>\n Option.map(farCorner(projection, range.focus, options), to =>\n Option.match(to, {\n onNone: () => range,\n onSome: focus => ({ anchor: range.anchor, focus }),\n }),\n ),\n )\n}\n\nexport const GridSelection = { none, isSelected, toggle, add, rowsBetween, boxOf, extend }\n","import { Effect, Queue, Schema, Stream } from 'effect'\nimport type { Command } from 'foldkit/command'\nimport { defineMessageUnion } from 'foldkit/message'\nimport * as Mount from 'foldkit/mount'\nimport { modifyFields } from 'foldkit/struct'\nimport { Bundle } from 'foldkit-bundle'\nimport type { Viewport } from './virtual.js'\n\nconst Model = Schema.Struct({\n top: Schema.Number,\n left: Schema.Number,\n width: Schema.Number,\n height: Schema.Number,\n})\ntype Model = typeof Model.Type\n\nconst Message = defineMessageUnion({\n /** The scroll container moved or changed size; the Mount reports it. */\n Measured: {\n top: Schema.Number,\n left: Schema.Number,\n width: Schema.Number,\n height: Schema.Number,\n },\n /** A reveal set the scroll offsets; the container's own scroll event confirms it later. */\n Revealed: { top: Schema.Number, left: Schema.Number },\n})\ntype Message = typeof Message.Type\n\n// A detached element measures NaN, and an overscroll less than nothing; neither\n// may reach the window math. An unchanged reading returns the Model it was given.\nconst write = (model: Model, next: ReadonlyArray<readonly [keyof Model, number]>): Model => {\n const fields: Partial<Record<keyof Model, () => number>> = {}\n for (const [key, value] of next) {\n const clean = Math.max(0, value)\n if (Number.isFinite(value) && clean !== model[key]) fields[key] = () => clean\n }\n return Object.keys(fields).length === 0 ? model : modifyFields(model, fields)\n}\n\n/**\n * The scroll container's geometry, as the window math reads it. The grid\n * owns no scroll position of its own: the container's is the fact, reported\n * by the `Measure` Mount, and a reveal moves the container.\n */\nconst bundle = Bundle.make('GridViewport', {\n Model,\n Message,\n init: () => ({ model: { top: 0, left: 0, width: 0, height: 0 } }),\n update: (model: Model, message: Message) => ({\n model: Message.match(message, {\n Measured: ({ top, left, width, height }) =>\n write(model, [\n ['top', top],\n ['left', left],\n ['width', width],\n ['height', height],\n ]),\n Revealed: ({ top, left }) =>\n write(model, [\n ['top', top],\n ['left', left],\n ]),\n }),\n }),\n})\n\ninterface Scroller {\n readonly scrollTop: number\n readonly scrollLeft: number\n readonly clientWidth: number\n readonly clientHeight: number\n}\n\ntype ResizeObserverCtor = new (callback: () => void) => ResizeObserver\n\n/**\n * Reports the element's scroll offsets and size: once when it mounts, then on\n * every scroll and every resize. Attach it to the scroll container. Without\n * `ResizeObserver` (a test DOM) it still reports scrolls.\n */\nconst Measure = Mount.defineStream('GridViewportMeasure', {\n messages: [Message.Measured],\n execute: ({ element }) =>\n Stream.callback<typeof Message.Measured.Type>(queue =>\n Effect.gen(function* () {\n const scroller = element as unknown as Scroller\n const report = () =>\n Queue.offerUnsafe(\n queue,\n Message.Measured({\n top: scroller.scrollTop,\n left: scroller.scrollLeft,\n width: scroller.clientWidth,\n height: scroller.clientHeight,\n }),\n )\n const Observer = (globalThis as { ResizeObserver?: ResizeObserverCtor }).ResizeObserver\n yield* Effect.acquireRelease(\n Effect.sync(() => {\n // Built before anything listens, so a constructor that throws leaves nothing attached.\n const observer = Observer === undefined ? undefined : new Observer(report)\n element.addEventListener('scroll', report, { passive: true })\n observer?.observe(element)\n report()\n return observer\n }),\n observer =>\n Effect.sync(() => {\n element.removeEventListener('scroll', report)\n observer?.disconnect()\n }),\n )\n }),\n ),\n})\n\n/**\n * Scrolls the container with this DOM id to `offsets` (from\n * `VirtualGrid.reveal`) and reports `Revealed`, so the next window is drawn\n * from the new offsets at once rather than after the scroll event.\n */\nconst scrollTo = (\n viewportId: string,\n offsets: Pick<Viewport, 'top' | 'left'>,\n): Command<Message> => ({\n name: 'GridViewport.scrollTo',\n args: { viewportId, ...offsets },\n effect: Effect.sync(() => {\n const element = typeof document === 'undefined' ? null : document.getElementById(viewportId)\n // A DOM with no layout (jsdom, in a test) has no scrollTo and nothing to scroll.\n if (element !== null && typeof element.scrollTo === 'function') {\n element.scrollTo({ top: offsets.top, left: offsets.left })\n }\n return Message.Revealed(offsets)\n }),\n})\n\nexport const GridViewport = { Model, Message, bundle, Measure, scrollTo }\n","import { Option } from 'effect'\nimport type { CellPosition, GridProjection } from './projection.js'\nimport { addressableRows } from './rows.js'\n\n/** The scroll container's offsets and size, in pixels. */\nexport interface Viewport {\n readonly top: number\n readonly left: number\n readonly width: number\n readonly height: number\n}\n\n/** Rendered items `[start, end)` on one axis, with the space the rest take before and after. */\nexport interface AxisWindow {\n readonly start: number\n readonly end: number\n readonly before: number\n readonly after: number\n}\n\nexport interface GridWindow<Id extends string> {\n /** Row indexes to render; every row is `rowHeight` tall. */\n readonly rows: AxisWindow\n /** Center columns to render, as indexes into `projection.center`. */\n readonly center: AxisWindow\n /** The center columns in that window, in display order. */\n readonly centerColumns: ReadonlyArray<Id>\n /** Pinned columns are always rendered: they never scroll horizontally. */\n readonly start: ReadonlyArray<Id>\n readonly end: ReadonlyArray<Id>\n /** The scrollable content's full size. */\n readonly width: number\n readonly height: number\n}\n\nexport interface Geometry<Row, Id extends string> {\n readonly projection: GridProjection<Row, Id>\n readonly rowHeight: number\n /** Width of each visible column. */\n readonly width: (column: NoInfer<Id>) => number\n /** Height of the header rows inside the scroll container, above the body. */\n readonly headerHeight?: number\n}\n\nexport interface WindowOptions<Row, Id extends string> extends Geometry<Row, Id> {\n readonly viewport: Viewport\n /** Extra rows and columns rendered beyond each edge, so a fast scroll shows no gap. */\n readonly overscan?: { readonly rows?: number; readonly columns?: number }\n}\n\nconst sum = (values: ReadonlyArray<number>): number =>\n values.reduce((total, value) => total + value, 0)\n\n/** `edges[i]` is where center column `i` begins; `edges[count]` is the center's width. */\nconst edgesOf = <Id extends string>(\n ids: ReadonlyArray<Id>,\n width: (column: Id) => number,\n): Float64Array => {\n const edges = new Float64Array(ids.length + 1)\n ids.forEach((id, index) => {\n edges[index + 1] = edges[index]! + Math.max(0, width(id))\n })\n return edges\n}\n\n/** How many of `0..count-1` satisfy `holds`, which holds for a prefix of them: a binary search. */\nconst prefixWhere = (count: number, holds: (index: number) => boolean): number => {\n let low = 0\n let high = count\n while (low < high) {\n const middle = (low + high) >>> 1\n if (holds(middle)) low = middle + 1\n else high = middle\n }\n return low\n}\n\ninterface Layout<Id extends string> {\n readonly rowCount: number\n readonly bodyHeight: number\n readonly centerWidth: number\n readonly edges: Float64Array\n readonly startWidth: number\n readonly endWidth: number\n readonly center: ReadonlyArray<Id>\n}\n\nconst layoutOf = <Row, Id extends string>(\n geometry: Geometry<Row, Id>,\n viewport: Viewport,\n): Layout<Id> => {\n const { projection, width, rowHeight } = geometry\n if (!(Number.isFinite(rowHeight) && rowHeight > 0)) {\n throw new Error(`VirtualGrid: rowHeight must be a positive number of pixels, not ${rowHeight}.`)\n }\n const startWidth = sum(projection.start.map(id => Math.max(0, width(id))))\n const endWidth = sum(projection.end.map(id => Math.max(0, width(id))))\n return {\n rowCount: addressableRows(projection.rowCount),\n bodyHeight: Math.max(0, viewport.height - (geometry.headerHeight ?? 0)),\n centerWidth: Math.max(0, viewport.width - startWidth - endWidth),\n edges: edgesOf(projection.center, width),\n startWidth,\n endWidth,\n center: projection.center,\n }\n}\n\n/**\n * What to render for a viewport: the rows and center columns it shows, plus\n * overscan, and the space the rest take. Rows are one fixed height, so the\n * row window is arithmetic on the scroll offset and never walks the rows; the\n * column window is a binary search over the center columns' widths. The\n * pinned columns are always rendered, outside the horizontal window.\n */\nconst window = <Row, Id extends string>(options: WindowOptions<Row, Id>): GridWindow<Id> => {\n const { viewport, rowHeight } = options\n const layout = layoutOf(options, viewport)\n const overRows = Math.max(0, Math.trunc(options.overscan?.rows ?? 0))\n const overColumns = Math.max(0, Math.trunc(options.overscan?.columns ?? 0))\n\n const top = Math.max(0, viewport.top)\n const firstRow = Math.floor(top / rowHeight)\n const pastRow = Math.ceil((top + layout.bodyHeight) / rowHeight)\n const rowStart = Math.min(layout.rowCount, Math.max(0, firstRow - overRows))\n const rowEnd = Math.min(layout.rowCount, Math.max(rowStart, pastRow + overRows))\n\n // A column is shown when it ends after the left edge and begins before the right.\n const { edges } = layout\n const count = layout.center.length\n const totalCenter = edges[count]!\n const left = Math.max(0, viewport.left)\n const right = left + layout.centerWidth\n const firstColumn = prefixWhere(count, index => edges[index + 1]! <= left)\n const pastColumn = Math.max(\n firstColumn,\n prefixWhere(count, index => edges[index]! < right),\n )\n const columnStart = Math.max(0, firstColumn - overColumns)\n const columnEnd = Math.min(count, pastColumn + overColumns)\n\n return {\n rows: {\n start: rowStart,\n end: rowEnd,\n before: rowStart * rowHeight,\n after: (layout.rowCount - rowEnd) * rowHeight,\n },\n center: {\n start: columnStart,\n end: columnEnd,\n before: edges[columnStart]!,\n after: totalCenter - edges[columnEnd]!,\n },\n centerColumns: layout.center.slice(columnStart, columnEnd),\n start: options.projection.start,\n end: options.projection.end,\n width: layout.startWidth + totalCenter + layout.endWidth,\n height: (options.headerHeight ?? 0) + layout.rowCount * rowHeight,\n }\n}\n\nexport interface RevealOptions<Row, Id extends string> extends Geometry<Row, Id> {\n readonly viewport: Viewport\n readonly position: CellPosition\n}\n\n/**\n * The scroll offsets that bring a cell fully into view, moving each axis the\n * least it can, or none when it is already in view. A pinned column never\n * scrolls, so only its row is brought in.\n */\nconst reveal = <Row, Id extends string>(\n options: RevealOptions<Row, Id>,\n): Option.Option<{ readonly top: number; readonly left: number }> => {\n const { viewport, position, rowHeight, projection } = options\n const layout = layoutOf(options, viewport)\n // The least scroll that shows `[from, from + size)` in a span of `span` at `offset`.\n const nearest = (offset: number, from: number, size: number, span: number): number => {\n if (from < offset) return from\n if (from + size > offset + span) return Math.max(0, from + size - span)\n return offset\n }\n\n const top = nearest(viewport.top, position.row * rowHeight, rowHeight, layout.bodyHeight)\n const centerIndex = position.column - projection.start.length\n // A pinned column is outside the center, and stays where it is drawn.\n const left =\n layout.center[centerIndex] !== undefined\n ? nearest(\n viewport.left,\n layout.edges[centerIndex]!,\n layout.edges[centerIndex + 1]! - layout.edges[centerIndex]!,\n layout.centerWidth,\n )\n : viewport.left\n return top === viewport.top && left === viewport.left ? Option.none() : Option.some({ top, left })\n}\n\nexport const VirtualGrid = { window, reveal }\n","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":";;;;;;;;AAiBA,MAAM,cAAc;AAEpB,MAAM,SAAS,SACb,YAAY,KAAK,IAAI,IAAI,IAAI,KAAK,WAAW,MAAK,MAAI,EAAE,KAAK;;AAG/D,MAAM,SAAS,SACb,KAAK,KAAI,QAAO,IAAI,IAAI,KAAK,CAAC,CAAC,KAAK,GAAI,CAAC,CAAC,CAAC,KAAK,IAAI;;;;;;AAOtD,MAAM,YAAY,SAAuD;CACvE,MAAM,OAA6B,CAAC;CACpC,IAAI,MAAqB,CAAC;CAC1B,IAAI,OAAO;CACX,IAAI,SAAS;CACb,IAAI,QAAQ;CACZ,MAAM,gBAAgB;EACpB,IAAI,KAAK,IAAI;EACb,OAAO;CACT;CACA,MAAM,eAAe;EACnB,QAAQ;EACR,KAAK,KAAK,GAAG;EACb,MAAM,CAAC;CACT;CACA,OAAO,QAAQ,KAAK,QAAQ;EAC1B,MAAM,OAAO,KAAK;EAClB,IAAI,QAAQ;GACV,IAAI,SAAS,QAAO,KAAK,QAAQ,OAAO,MAAK;IAC3C,QAAQ;IACR,SAAS;IACT;GACF;GACA,IAAI,SAAS,MAAK,SAAS;QACtB,QAAQ;GACb,SAAS;GACT;E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