foldkit-data-grid 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/fill.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"fill.js","names":[],"sources":["../src/fill.ts"],"sourcesContent":["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"],"mappings":";;AAsBA,MAAM,SAAS;;;;;;;;AASf,MAAM,UACJ,QACA,OACA,aAC0B;CAC1B,MAAM,MAAM,UAAkB,QAAS,QAAQ,OAAO,SAAU,OAAO,UAAU,OAAO;CACxF,MAAM,WAAW,MAAM,KAAK,EAAE,QAAQ,MAAM,IAAI,GAAG,UACjD,WAAW,GAAG,KAAK,KAAK,IAAI,GAAG,OAAO,SAAS,KAAK,CACtD;CACA,IAAI,OAAO,SAAS,GAAG,OAAO;CAC9B,MAAM,SAAS,OAAO,KAAI,SAAQ,OAAO,KAAK,KAAK,KAAK,CAAC,CAAC;CAC1D,IAAI,OAAO,MAAK,UAAS,UAAU,IAAI,GAAG,OAAO;CACjD,MAAM,WAAW,KAAK,IAAI,GAAG,OAAO,KAAI,UAAS,MAAO,EAAE,EAAE,UAAU,CAAC,CAAC;CAExE,MAAM,QAAQ,MAAM;CACpB,MAAM,Q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C,KAAI,UAAS,OAAO,OAAO,MAAM,CAAC,GAC3D,WAAW,QACX,QACF;GACA,OAAO,WAAW,SAAS,OAAO,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAI,CAAC;EAC1E,CAAC;CACH;CACA,MAAM,gBAAgB,KAAK,KAAK,OAAO,OAAO;CAC9C,OAAO,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,SAAQ,UAAS;EAC/C,MAAM,QAAQ,OACZ,KAAK,OAAO,QAAQ,KAAI,WAAU,OAAO,OAAO,MAAM,CAAC,GACvD,cAAc,QACd,QACF;EACA,OAAO,cAAc,SAAS,QAAQ,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAI,CAAC;CAC9E,CAAC;AACH;AAEA,MAAa,OAAO;CAAE;CAAQ;CAAM;AAAM"}
1
+ {"version":3,"file":"fill.js","names":[],"sources":["../src/fill.ts"],"sourcesContent":["import { Option } from 'effect'\nimport type { PastedCell } from './clipboard.js'\nimport type { FillLane } from './columns.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+))?$/\nconst day = /^(\\d{4})-(\\d{2})-(\\d{2})$/\n\nconst msPerDay = 86_400_000\n\n// `Date.UTC` maps years 0 to 99 to 1900 and up, and normalizes a day that does\n// not exist, so the date is built by its fields and read back.\nconst utcDate = (year: number, month: number, date: number): Date => {\n const made = new Date(0)\n made.setUTCFullYear(year, month, date)\n return made\n}\n\nconst daysInMonth = (year: number, month: number): number =>\n utcDate(year, month + 1, 0).getUTCDate()\n\ninterface CalendarDay {\n readonly year: number\n readonly month: number\n readonly date: number\n /** Whole days since 1970-01-01. */\n readonly epoch: number\n}\n\nconst calendarDay = (text: string): CalendarDay | undefined => {\n const match = day.exec(text.trim())\n if (match === null) return undefined\n const [year, month, date] = [Number(match[1]), Number(match[2]) - 1, Number(match[3])]\n const made = utcDate(year, month, date)\n if (made.getUTCMonth() !== month || made.getUTCDate() !== date) return undefined\n return { year, month, date, epoch: made.getTime() / msPerDay }\n}\n\nconst dayText = (made: Date): string =>\n `${String(made.getUTCFullYear()).padStart(4, '0')}-${String(made.getUTCMonth() + 1).padStart(2, '0')}-${String(made.getUTCDate()).padStart(2, '0')}`\n\n/**\n * Calendar days continued by months when they share a day of the month and\n * are a constant number of months apart, else by days when a constant\n * number of days apart. Each month's day is the source's, clamped to the\n * month's length. None when the source is not such a series.\n */\nconst daySeries = (\n source: ReadonlyArray<string>,\n count: number,\n backward: boolean,\n): ReadonlyArray<string> | undefined => {\n const days = source.map(calendarDay)\n if (days.some(found => found === undefined)) return undefined\n const known = days as ReadonlyArray<CalendarDay>\n const steps = (read: (found: CalendarDay) => number) =>\n known.slice(1).map((found, index) => read(found) - read(known[index]!))\n const constant = (diffs: ReadonlyArray<number>) =>\n diffs[0] !== 0 && diffs.every(diff => diff === diffs[0])\n const first = known[0]!\n const last = known[known.length - 1]!\n const months = steps(found => found.year * 12 + found.month)\n if (known.every(found => found.date === first.date) && constant(months)) {\n const step = months[0]!\n const from = backward ? first : last\n const origin = from.year * 12 + from.month\n return Array.from({ length: count }, (_, index) => {\n const at = origin + (backward ? -step : step) * (index + 1)\n const year = Math.floor(at / 12)\n const month = at - year * 12\n return dayText(utcDate(year, month, Math.min(first.date, daysInMonth(year, month))))\n })\n }\n const dayDiffs = steps(found => found.epoch)\n if (!constant(dayDiffs)) return undefined\n const step = dayDiffs[0]!\n const from = backward ? first : last\n return Array.from({ length: count }, (_, index) =>\n dayText(new Date((from.epoch + (backward ? -step : step) * (index + 1)) * msPerDay)),\n )\n}\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. Two or more `YYYY-MM-DD`\n * days continue by months when they share a day of the month a constant number\n * of months apart (a 31st clamps to a shorter month and comes back), else by\n * a constant number of days. Anything else repeats, in 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 days = daySeries(source, count, backward)\n if (days !== undefined) return days\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/** A cell a fill writes, or one it could not: `refusal` is why no text was given. */\nexport interface FilledCell<Id extends string> extends PastedCell<Id> {\n readonly refusal?: string\n}\n\nconst noSeriesText = 'The column’s series gave no text here'\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`, or by the column's `custom` series when it answers (fills down\n * and up only). A custom answer shorter than the target leaves the cells past\n * it with a `refusal`. 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 readonly custom?: (column: Id, lane: FillLane) => Option.Option<ReadonlyArray<string>>\n },\n): ReadonlyArray<FilledCell<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 = (\n index: number,\n column: Id,\n text: string | undefined,\n ): ReadonlyArray<FilledCell<Id>> =>\n options.editable(column)\n ? Option.match(keyAt(index), {\n onNone: () => [],\n onSome: row => {\n const from = options.from({ row, column })\n return [\n text === undefined\n ? { row, column, text: '', from, refusal: noSeriesText }\n : { row, column, text, from },\n ]\n },\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 source = rowsOf(fill.source.rows).map(index => textAt(index, column))\n const count = targetRows.length\n const texts = Option.getOrElse(\n options.custom?.(column, { source, count, toward: backward ? 'up' : 'down' }) ??\n Option.none(),\n () => series(source, count, 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"],"mappings":";;AAuBA,MAAM,SAAS;AACf,MAAM,MAAM;AAEZ,MAAM,WAAW;AAIjB,MAAM,WAAW,MAAc,OAAe,SAAuB;CACnE,MAAM,uBAAO,IAAI,KAAK,CAAC;CACvB,KAAK,eAAe,MAAM,OAAO,IAAI;CACrC,OAAO;AACT;AAEA,MAAM,eAAe,MAAc,UACjC,QAAQ,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,WAAW;AAUzC,MAAM,eAAe,SAA0C;CAC7D,MAAM,QAAQ,IAAI,KAAK,KAAK,KAAK,CAAC;CAClC,IAAI,UAAU,MAAM,OAAO,KAAA;CAC3B,MAAM,CAAC,MAAM,OAAO,QAAQ;EAAC,OAAO,MAAM,EAAE;EAAG,OAAO,MAAM,EAAE,IAAI;EAAG,OAAO,MAAM,EAAE;CAAC;CACrF,MAAM,OAAO,QAAQ,MAAM,OAAO,IAAI;CACtC,IAAI,KAAK,YAAY,MAAM,SAAS,KAAK,WAAW,MAAM,MAAM,OAAO,KAAA;CACv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KAAK,SACR,OAAO,QAAQ,OAAO,QAAQ,CACtC;GACA,OAAO,WAAW,SAAS,OAAO,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG,CAAC;EACzE,CAAC;CACH;CACA,MAAM,gBAAgB,KAAK,KAAK,OAAO,OAAO;CAC9C,OAAO,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,SAAQ,UAAS;EAC/C,MAAM,QAAQ,OACZ,KAAK,OAAO,QAAQ,KAAI,WAAU,OAAO,OAAO,MAAM,CAAC,GACvD,cAAc,QACd,QACF;EACA,OAAO,cAAc,SAAS,QAAQ,OAAO,KAAK,OAAO,QAAQ,MAAM,GAAG,CAAC;CAC7E,CAAC;AACH;AAEA,MAAa,OAAO;CAAE;CAAQ;CAAM;AAAM"}
package/dist/filter.d.ts CHANGED
@@ -102,6 +102,12 @@ export declare const FilterForm: Schema.Struct<{
102
102
  }>;
103
103
  export type FilterForm = typeof FilterForm.Type;
104
104
  export declare const emptyForm: FilterForm;
105
+ /**
106
+ * Whether the application's `drawn` filter is one the form itself sent (or
107
+ * opened with): a store that is late, or that trims a text, writes it back, and
108
+ * that is no write from outside the form.
109
+ */
110
+ export declare const isEcho: (sent: ReadonlyArray<Option.Option<ColumnFilter>>, drawn: Option.Option<ColumnFilter>) => boolean;
105
111
  /** The form a filter is drawn as; none is the empty form. */
106
112
  export declare const formOf: (filter: Option.Option<ColumnFilter>) => FilterForm;
107
113
  /** What a form reads as: a filter or none, unless a bound is no number; and whether its bounds cross. */
@@ -1 +1 @@
1
- {"version":3,"file":"filter.d.ts","names":[],"sources":["../src/filter.ts"],"mappings":";;;;;;;;qBAaa,uCAAY;;;IAEX,MAAI,OAAA;;;;IAGd,KAAG,OAAA,iBAAA,OAAA;IACH,KAAG,OAAA,iBAAA,OAAA;;;;IAGI,SAAO,OAAA,OAAA,OAAA;;;IACV,SAAO,OAAA;;;;IAEF,MAAI,OAAA,iBAAA,OAAA;IAAgC,IAAE,OAAA,iBAAA,OAAA;;;YAE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,WAAW;qBAE9B,WAAW;;;;;;qBAkBX,SAAM,MACX,cAAc,OAAO,OAAO,gBAAc,OACzC,OAAO,OAAO;;qBAUV,SAAM,QAAY,OAAO,OAAO,kBAAgB;;iBAgB5C;WACN,QAAQ,OAAO,OAAO;;WAEtB,SAAS;;WAET;;;qBAmBE,WAAQ,MAAU,YAAU,MAAQ,eAAa;;qBAuEjD,SAAM,QAAY,mBAAiB"}
package/dist/filter.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Option, Schema } from "effect";
1
+ import { Equal, Option, Schema } from "effect";
2
2
  import { CellEditor } from "./columns.js";
3
3
  import { defineTaggedUnion } from "foldkit/schema";
4
4
  // src/filter.ts
@@ -72,6 +72,16 @@ const shown = (value) => Option.match(value, {
72
72
  onNone: () => "",
73
73
  onSome: String
74
74
  });
75
+ /**
76
+ * Whether the application's `drawn` filter is one the form itself sent (or
77
+ * opened with): a store that is late, or that trims a text, writes it back, and
78
+ * that is no write from outside the form.
79
+ */
80
+ const isEcho = (sent, drawn) => {
81
+ const trimmed = (filter) => Option.map(filter, (each) => ColumnFilter.guards.Contains(each) ? ColumnFilter.Contains({ text: each.text.trim() }) : each);
82
+ const wanted = trimmed(drawn);
83
+ return sent.some((each) => Equal.equals(trimmed(each), wanted));
84
+ };
75
85
  /** The form a filter is drawn as; none is the empty form. */
76
86
  const formOf = (filter) => Option.match(filter, {
77
87
  onNone: () => emptyForm,
@@ -186,6 +196,6 @@ const testOf = (filter) => ColumnFilter.match(filter, {
186
196
  return unlessNone(from, (low) => at >= low) && unlessNone(to, (high) => at <= high);
187
197
  }
188
198
  });
189
- export { ColumnFilter, FilterForm, emptyForm, filterSchemaOf, formOf, readForm, testOf };
199
+ export { ColumnFilter, FilterForm, emptyForm, filterSchemaOf, formOf, isEcho, readForm, testOf };
190
200
 
191
201
  //# sourceMappingURL=filter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"filter.js","names":[],"sources":["../src/filter.ts"],"sourcesContent":["import { Option, Schema } from 'effect'\nimport { defineTaggedUnion } from 'foldkit/schema'\nimport { CellEditor } from './columns.js'\n\n/** A local calendar day, `YYYY-MM-DD`, as a date input reads it. */\nconst Day = Schema.String.check(Schema.isPattern(/^\\d{4}-\\d{2}-\\d{2}$/))\n\n/**\n * What one column is filtered by: the application's to hold and to apply.\n * One variant per kind of column: text `Contains`, a number `Range`, a choice\n * `OneOf`, a checkbox `Is`, a date `Between`. A filter that keeps every row\n * is never one of these: it is none.\n */\nexport const ColumnFilter = defineTaggedUnion({\n /** The text holds this, folding ASCII case, as `Expr.contains` does. */\n Contains: { text: Schema.String },\n /** At least `min`, at most `max`, each when given. */\n Range: {\n min: Schema.OptionFromNullOr(Schema.Finite),\n max: Schema.OptionFromNullOr(Schema.Finite),\n },\n /** One of these literals. */\n OneOf: { options: Schema.Array(Schema.String) },\n Is: { checked: Schema.Boolean },\n /** On or after `from`, on or before `to`: local days, each when given. */\n Between: { from: Schema.OptionFromNullOr(Day), to: Schema.OptionFromNullOr(Day) },\n})\nexport type ColumnFilter = typeof ColumnFilter.Type\n\ntype Contains = typeof ColumnFilter.Contains.Type\ntype Range = typeof ColumnFilter.Range.Type\ntype Is = typeof ColumnFilter.Is.Type\ntype Between = typeof ColumnFilter.Between.Type\n/** A choice's filter, its options the column's own literals. */\nexport type OneOf<V extends string> = {\n readonly _tag: 'OneOf'\n readonly options: ReadonlyArray<V>\n}\n\ntype IsTextLiteral<M> = M extends string\n ? string extends M\n ? false\n : // A template literal or a branded string keys an index signature, which `{}` fits.\n {} extends Record<M, 1>\n ? false\n : true\n : false\ntype AllTextLiterals<V> = [V] extends [string]\n ? false extends (V extends unknown ? IsTextLiteral<V> : never)\n ? false\n : true\n : false\n/** What `filterKindOf` reads from a schema's decoded side, at the type level. */\nexport type KindOfValue<V> = [V] extends [boolean]\n ? 'Checkbox'\n : [V] extends [Date]\n ? 'Date'\n : [V] extends [number]\n ? 'Number'\n : AllTextLiterals<V> extends true\n ? 'Choice'\n : 'Text'\n/** A column's filter kind, as the grid reads it at run time. */\nexport type FilterKind<Spec> = Spec extends { readonly filter: infer F }\n ? F extends true\n ? Spec extends { readonly edit: { readonly schema: Schema.Codec<infer V, string> } }\n ? KindOfValue<V>\n : 'Text'\n : F extends { readonly _tag: infer T }\n ? T\n : never\n : never\n// Inferred in two steps: matched against `filter: true` and the schema at\n// once, a spec that is an intersection (`GridCrud.columns`) infers `unknown`.\ntype ChoiceOf<Spec> = Spec extends { readonly filter: true }\n ? Spec extends { readonly edit: { readonly schema: Schema.Codec<infer V, string> } }\n ? V & string\n : string\n : string\n/** The filter of a column, by its spec: the variant its kind takes. */\nexport type FilterOf<Spec> = {\n Text: Contains\n Number: Range\n Choice: OneOf<ChoiceOf<Spec>>\n Checkbox: Is\n Date: Between\n}[FilterKind<Spec> & ('Text' | 'Number' | 'Choice' | 'Checkbox' | 'Date')]\n/** What `keeps` reads from a row for a filter: a Range a number, a Between a `Date`. */\nexport type FilterValue<F> = F extends Contains\n ? string\n : F extends Range\n ? number\n : F extends OneOf<infer V>\n ? V\n : F extends Is\n ? boolean\n : F extends Between\n ? Date\n : never\n/** The ids of the columns that filter. */\nexport type FilterableId<Specs> = {\n [K in keyof Specs]: Specs[K] extends { readonly filter: true | CellEditor } ? K : never\n}[keyof Specs] &\n string\n/** Every filterable column's filter, none where it filters nothing: the application's value. */\nexport type Filters<Specs> = {\n readonly [K in FilterableId<Specs>]: Option.Option<FilterOf<Specs[K]>>\n}\n/** What `Out.Filtered` carries: one case per filterable column, its filter that column's variant. */\nexport type FilterChange<Specs> = {\n [K in FilterableId<Specs>]: {\n readonly column: K\n readonly filter: Option.Option<FilterOf<Specs[K]>>\n }\n}[FilterableId<Specs>]\n\n/**\n * The stored form of one column's filter: its own variant, never one that\n * keeps every row, a choice only of its literals, each once, and bounds\n * that are finite numbers.\n */\nexport const filterSchemaOf = (kind: CellEditor): Schema.Codec<ColumnFilter, unknown> => {\n // A Range or a Between with neither bound keeps every row: that is none.\n const someBound = (a: Option.Option<unknown>, b: Option.Option<unknown>) =>\n Option.isSome(a) || Option.isSome(b)\n const schema: Schema.Top = CellEditor.match(kind, {\n Text: () =>\n Schema.TaggedStruct('Contains', { text: Schema.String.check(Schema.isMinLength(1)) }),\n Number: () =>\n ColumnFilter.Range.check(\n Schema.makeFilter<Range>(({ min, max }) => someBound(min, max), { expected: 'a bound' }),\n ),\n Choice: ({ options }) =>\n Schema.TaggedStruct('OneOf', {\n options: Schema.Array(Schema.Literals(options)).check(\n Schema.isMinLength(1),\n Schema.isUnique(),\n ),\n }),\n Checkbox: () => ColumnFilter.Is,\n Date: () =>\n ColumnFilter.Between.check(\n Schema.makeFilter<Between>(({ from, to }) => someBound(from, to), { expected: 'a bound' }),\n ),\n })\n // Each case decodes to its variant of `ColumnFilter`, from JSON.\n return schema as unknown as Schema.Codec<ColumnFilter, unknown>\n}\n\n/**\n * An open filter form as typed: each kind reads its own fields, and a bound\n * is text, so it holds `1.` while it is typed.\n */\nexport const FilterForm = Schema.Struct({\n text: Schema.String,\n min: Schema.String,\n max: Schema.String,\n options: Schema.Array(Schema.String),\n checked: Schema.Literals(['any', 'true', 'false']),\n from: Schema.String,\n to: Schema.String,\n})\nexport type FilterForm = typeof FilterForm.Type\n\nexport const emptyForm: FilterForm = {\n text: '',\n min: '',\n max: '',\n options: [],\n checked: 'any',\n from: '',\n to: '',\n}\n\nconst shown = (value: Option.Option<number | string>): string =>\n Option.match(value, { onNone: () => '', onSome: String })\n\n/** The form a filter is drawn as; none is the empty form. */\nexport const formOf = (filter: Option.Option<ColumnFilter>): FilterForm =>\n Option.match(filter, {\n onNone: () => emptyForm,\n onSome: ColumnFilter.match({\n Contains: ({ text }) => ({ ...emptyForm, text }),\n Range: ({ min, max }) => ({ ...emptyForm, min: shown(min), max: shown(max) }),\n OneOf: ({ options }) => ({ ...emptyForm, options }),\n Is: ({ checked }) => ({\n ...emptyForm,\n checked: checked ? ('true' as const) : ('false' as const),\n }),\n Between: ({ from, to }) => ({ ...emptyForm, from: shown(from), to: shown(to) }),\n }),\n })\n\n/** What a form reads as: a filter or none, unless a bound is no number; and whether its bounds cross. */\nexport interface FormReading {\n readonly filter: Option.Option<ColumnFilter>\n /** The bounds that are not numbers (or days): while any is, nothing is reported. */\n readonly invalid: ReadonlyArray<'min' | 'max' | 'from' | 'to'>\n /** The lower bound is above the upper: reported, and it keeps no row. */\n readonly crossed: boolean\n}\n\nconst decimal = /^[+-]?(\\d+(\\.\\d*)?|\\.\\d+)$/\nconst day = /^\\d{4}-\\d{2}-\\d{2}$/\n// A number as typed, and finite: 309 digits read as Infinity, which no Range stores.\nconst isNumber = (text: string): boolean => decimal.test(text) && Number.isFinite(Number(text))\nconst isDay = (text: string): boolean => day.test(text)\n/** A bound as typed: none when empty, refused (the outer none) when it is not one. */\nconst bound = (\n text: string,\n accepts: (trimmed: string) => boolean,\n): Option.Option<Option.Option<string>> => {\n const trimmed = text.trim()\n if (trimmed === '') return Option.some(Option.none())\n return accepts(trimmed) ? Option.some(Option.some(trimmed)) : Option.none()\n}\n\n/** A kind's form read as its filter. */\nexport const readForm = (kind: CellEditor, form: FilterForm): FormReading => {\n const none = { filter: Option.none(), invalid: [], crossed: false } as const\n const range = <F extends 'min' | 'from', T extends 'max' | 'to'>(\n lowField: F,\n highField: T,\n accepts: (trimmed: string) => boolean,\n make: (low: Option.Option<string>, high: Option.Option<string>) => ColumnFilter,\n above: (low: string, high: string) => boolean,\n ): FormReading => {\n const low = bound(form[lowField], accepts)\n const high = bound(form[highField], accepts)\n const invalid = [\n ...(Option.isNone(low) ? [lowField] : []),\n ...(Option.isNone(high) ? [highField] : []),\n ]\n if (Option.isNone(low) || Option.isNone(high)) return { ...none, invalid }\n if (Option.isNone(low.value) && Option.isNone(high.value)) return none\n const crossed =\n Option.isSome(low.value) &&\n Option.isSome(high.value) &&\n above(low.value.value, high.value.value)\n return { filter: Option.some(make(low.value, high.value)), invalid: [], crossed }\n }\n return CellEditor.match(kind, {\n Text: () =>\n form.text === ''\n ? none\n : { ...none, filter: Option.some(ColumnFilter.Contains({ text: form.text })) },\n Number: () =>\n range(\n 'min',\n 'max',\n isNumber,\n (min, max) =>\n ColumnFilter.Range({ min: Option.map(min, Number), max: Option.map(max, Number) }),\n (low, high) => Number(low) > Number(high),\n ),\n Choice: () =>\n form.options.length === 0\n ? none\n : { ...none, filter: Option.some(ColumnFilter.OneOf({ options: form.options })) },\n Checkbox: () =>\n form.checked === 'any'\n ? none\n : { ...none, filter: Option.some(ColumnFilter.Is({ checked: form.checked === 'true' })) },\n Date: () =>\n range(\n 'from',\n 'to',\n isDay,\n (from, to) => ColumnFilter.Between({ from, to }),\n (low, high) => low > high,\n ),\n })\n}\n\n/** Whether `test` holds of the value, or there is none to test. */\nconst unlessNone = <A>(value: Option.Option<A>, test: (a: A) => boolean): boolean =>\n Option.match(value, { onNone: () => true, onSome: test })\n\n// ASCII only, as `Expr.contains` folds on every backend.\nconst fold = (text: string): string =>\n text.replace(/[A-Z]/g, letter => String.fromCharCode(letter.charCodeAt(0) + 32))\n\nconst localDay = (date: Date): string => {\n const month = String(date.getMonth() + 1).padStart(2, '0')\n const day = String(date.getDate()).padStart(2, '0')\n return `${date.getFullYear()}-${month}-${day}`\n}\n\n/** Whether one filter keeps a value read from a row. */\nexport const testOf = (filter: ColumnFilter): ((value: unknown) => boolean) =>\n ColumnFilter.match(filter, {\n Contains: ({ text }) => {\n const wanted = fold(text)\n return (value: unknown) => fold(value as string).includes(wanted)\n },\n Range:\n ({ min, max }) =>\n (value: unknown) =>\n unlessNone(min, low => (value as number) >= low) &&\n unlessNone(max, high => (value as number) <= high),\n OneOf: ({ options }) => {\n const among = new Set<unknown>(options)\n return (value: unknown) => among.has(value)\n },\n Is:\n ({ checked }) =>\n (value: unknown) =>\n value === checked,\n Between:\n ({ from, to }) =>\n (value: unknown) => {\n const date = value as Date\n if (Number.isNaN(date.getTime())) return false\n const at = localDay(date)\n return unlessNone(from, low => at >= low) && unlessNone(to, high => at <= high)\n },\n })\n"],"mappings":";;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I;CAChF;AACJ,CAAC"}
1
+ {"version":3,"file":"filter.js","names":[],"sources":["../src/filter.ts"],"sourcesContent":["import { Equal, Option, Schema } from 'effect'\nimport { defineTaggedUnion } from 'foldkit/schema'\nimport { CellEditor } from './columns.js'\n\n/** A local calendar day, `YYYY-MM-DD`, as a date input reads it. */\nconst Day = Schema.String.check(Schema.isPattern(/^\\d{4}-\\d{2}-\\d{2}$/))\n\n/**\n * What one column is filtered by: the application's to hold and to apply.\n * One variant per kind of column: text `Contains`, a number `Range`, a choice\n * `OneOf`, a checkbox `Is`, a date `Between`. A filter that keeps every row\n * is never one of these: it is none.\n */\nexport const ColumnFilter = defineTaggedUnion({\n /** The text holds this, folding ASCII case, as `Expr.contains` does. */\n Contains: { text: Schema.String },\n /** At least `min`, at most `max`, each when given. */\n Range: {\n min: Schema.OptionFromNullOr(Schema.Finite),\n max: Schema.OptionFromNullOr(Schema.Finite),\n },\n /** One of these literals. */\n OneOf: { options: Schema.Array(Schema.String) },\n Is: { checked: Schema.Boolean },\n /** On or after `from`, on or before `to`: local days, each when given. */\n Between: { from: Schema.OptionFromNullOr(Day), to: Schema.OptionFromNullOr(Day) },\n})\nexport type ColumnFilter = typeof ColumnFilter.Type\n\ntype Contains = typeof ColumnFilter.Contains.Type\ntype Range = typeof ColumnFilter.Range.Type\ntype Is = typeof ColumnFilter.Is.Type\ntype Between = typeof ColumnFilter.Between.Type\n/** A choice's filter, its options the column's own literals. */\nexport type OneOf<V extends string> = {\n readonly _tag: 'OneOf'\n readonly options: ReadonlyArray<V>\n}\n\ntype IsTextLiteral<M> = M extends string\n ? string extends M\n ? false\n : // A template literal or a branded string keys an index signature, which `{}` fits.\n {} extends Record<M, 1>\n ? false\n : true\n : false\ntype AllTextLiterals<V> = [V] extends [string]\n ? false extends (V extends unknown ? IsTextLiteral<V> : never)\n ? false\n : true\n : false\n/** What `filterKindOf` reads from a schema's decoded side, at the type level. */\nexport type KindOfValue<V> = [V] extends [boolean]\n ? 'Checkbox'\n : [V] extends [Date]\n ? 'Date'\n : [V] extends [number]\n ? 'Number'\n : AllTextLiterals<V> extends true\n ? 'Choice'\n : 'Text'\n/** A column's filter kind, as the grid reads it at run time. */\nexport type FilterKind<Spec> = Spec extends { readonly filter: infer F }\n ? F extends true\n ? Spec extends { readonly edit: { readonly schema: Schema.Codec<infer V, string> } }\n ? KindOfValue<V>\n : 'Text'\n : F extends { readonly _tag: infer T }\n ? T\n : never\n : never\n// Inferred in two steps: matched against `filter: true` and the schema at\n// once, a spec that is an intersection (`GridCrud.columns`) infers `unknown`.\ntype ChoiceOf<Spec> = Spec extends { readonly filter: true }\n ? Spec extends { readonly edit: { readonly schema: Schema.Codec<infer V, string> } }\n ? V & string\n : string\n : string\n/** The filter of a column, by its spec: the variant its kind takes. */\nexport type FilterOf<Spec> = {\n Text: Contains\n Number: Range\n Choice: OneOf<ChoiceOf<Spec>>\n Checkbox: Is\n Date: Between\n}[FilterKind<Spec> & ('Text' | 'Number' | 'Choice' | 'Checkbox' | 'Date')]\n/** What `keeps` reads from a row for a filter: a Range a number, a Between a `Date`. */\nexport type FilterValue<F> = F extends Contains\n ? string\n : F extends Range\n ? number\n : F extends OneOf<infer V>\n ? V\n : F extends Is\n ? boolean\n : F extends Between\n ? Date\n : never\n/** The ids of the columns that filter. */\nexport type FilterableId<Specs> = {\n [K in keyof Specs]: Specs[K] extends { readonly filter: true | CellEditor } ? K : never\n}[keyof Specs] &\n string\n/** Every filterable column's filter, none where it filters nothing: the application's value. */\nexport type Filters<Specs> = {\n readonly [K in FilterableId<Specs>]: Option.Option<FilterOf<Specs[K]>>\n}\n/** What `Out.Filtered` carries: one case per filterable column, its filter that column's variant. */\nexport type FilterChange<Specs> = {\n [K in FilterableId<Specs>]: {\n readonly column: K\n readonly filter: Option.Option<FilterOf<Specs[K]>>\n }\n}[FilterableId<Specs>]\n\n/**\n * The stored form of one column's filter: its own variant, never one that\n * keeps every row, a choice only of its literals, each once, and bounds\n * that are finite numbers.\n */\nexport const filterSchemaOf = (kind: CellEditor): Schema.Codec<ColumnFilter, unknown> => {\n // A Range or a Between with neither bound keeps every row: that is none.\n const someBound = (a: Option.Option<unknown>, b: Option.Option<unknown>) =>\n Option.isSome(a) || Option.isSome(b)\n const schema: Schema.Top = CellEditor.match(kind, {\n Text: () =>\n Schema.TaggedStruct('Contains', { text: Schema.String.check(Schema.isMinLength(1)) }),\n Number: () =>\n ColumnFilter.Range.check(\n Schema.makeFilter<Range>(({ min, max }) => someBound(min, max), { expected: 'a bound' }),\n ),\n Choice: ({ options }) =>\n Schema.TaggedStruct('OneOf', {\n options: Schema.Array(Schema.Literals(options)).check(\n Schema.isMinLength(1),\n Schema.isUnique(),\n ),\n }),\n Checkbox: () => ColumnFilter.Is,\n Date: () =>\n ColumnFilter.Between.check(\n Schema.makeFilter<Between>(({ from, to }) => someBound(from, to), { expected: 'a bound' }),\n ),\n })\n // Each case decodes to its variant of `ColumnFilter`, from JSON.\n return schema as unknown as Schema.Codec<ColumnFilter, unknown>\n}\n\n/**\n * An open filter form as typed: each kind reads its own fields, and a bound\n * is text, so it holds `1.` while it is typed.\n */\nexport const FilterForm = Schema.Struct({\n text: Schema.String,\n min: Schema.String,\n max: Schema.String,\n options: Schema.Array(Schema.String),\n checked: Schema.Literals(['any', 'true', 'false']),\n from: Schema.String,\n to: Schema.String,\n})\nexport type FilterForm = typeof FilterForm.Type\n\nexport const emptyForm: FilterForm = {\n text: '',\n min: '',\n max: '',\n options: [],\n checked: 'any',\n from: '',\n to: '',\n}\n\nconst shown = (value: Option.Option<number | string>): string =>\n Option.match(value, { onNone: () => '', onSome: String })\n\n/**\n * Whether the application's `drawn` filter is one the form itself sent (or\n * opened with): a store that is late, or that trims a text, writes it back, and\n * that is no write from outside the form.\n */\nexport const isEcho = (\n sent: ReadonlyArray<Option.Option<ColumnFilter>>,\n drawn: Option.Option<ColumnFilter>,\n): boolean => {\n const trimmed = (filter: Option.Option<ColumnFilter>) =>\n Option.map(filter, each =>\n ColumnFilter.guards.Contains(each) ? ColumnFilter.Contains({ text: each.text.trim() }) : each,\n )\n const wanted = trimmed(drawn)\n return sent.some(each => Equal.equals(trimmed(each), wanted))\n}\n/** The form a filter is drawn as; none is the empty form. */\nexport const formOf = (filter: Option.Option<ColumnFilter>): FilterForm =>\n Option.match(filter, {\n onNone: () => emptyForm,\n onSome: ColumnFilter.match({\n Contains: ({ text }) => ({ ...emptyForm, text }),\n Range: ({ min, max }) => ({ ...emptyForm, min: shown(min), max: shown(max) }),\n OneOf: ({ options }) => ({ ...emptyForm, options }),\n Is: ({ checked }) => ({\n ...emptyForm,\n checked: checked ? ('true' as const) : ('false' as const),\n }),\n Between: ({ from, to }) => ({ ...emptyForm, from: shown(from), to: shown(to) }),\n }),\n })\n\n/** What a form reads as: a filter or none, unless a bound is no number; and whether its bounds cross. */\nexport interface FormReading {\n readonly filter: Option.Option<ColumnFilter>\n /** The bounds that are not numbers (or days): while any is, nothing is reported. */\n readonly invalid: ReadonlyArray<'min' | 'max' | 'from' | 'to'>\n /** The lower bound is above the upper: reported, and it keeps no row. */\n readonly crossed: boolean\n}\n\nconst decimal = /^[+-]?(\\d+(\\.\\d*)?|\\.\\d+)$/\nconst day = /^\\d{4}-\\d{2}-\\d{2}$/\n// A number as typed, and finite: 309 digits read as Infinity, which no Range stores.\nconst isNumber = (text: string): boolean => decimal.test(text) && Number.isFinite(Number(text))\nconst isDay = (text: string): boolean => day.test(text)\n/** A bound as typed: none when empty, refused (the outer none) when it is not one. */\nconst bound = (\n text: string,\n accepts: (trimmed: string) => boolean,\n): Option.Option<Option.Option<string>> => {\n const trimmed = text.trim()\n if (trimmed === '') return Option.some(Option.none())\n return accepts(trimmed) ? Option.some(Option.some(trimmed)) : Option.none()\n}\n\n/** A kind's form read as its filter. */\nexport const readForm = (kind: CellEditor, form: FilterForm): FormReading => {\n const none = { filter: Option.none(), invalid: [], crossed: false } as const\n const range = <F extends 'min' | 'from', T extends 'max' | 'to'>(\n lowField: F,\n highField: T,\n accepts: (trimmed: string) => boolean,\n make: (low: Option.Option<string>, high: Option.Option<string>) => ColumnFilter,\n above: (low: string, high: string) => boolean,\n ): FormReading => {\n const low = bound(form[lowField], accepts)\n const high = bound(form[highField], accepts)\n const invalid = [\n ...(Option.isNone(low) ? [lowField] : []),\n ...(Option.isNone(high) ? [highField] : []),\n ]\n if (Option.isNone(low) || Option.isNone(high)) return { ...none, invalid }\n if (Option.isNone(low.value) && Option.isNone(high.value)) return none\n const crossed =\n Option.isSome(low.value) &&\n Option.isSome(high.value) &&\n above(low.value.value, high.value.value)\n return { filter: Option.some(make(low.value, high.value)), invalid: [], crossed }\n }\n return CellEditor.match(kind, {\n Text: () =>\n form.text === ''\n ? none\n : { ...none, filter: Option.some(ColumnFilter.Contains({ text: form.text })) },\n Number: () =>\n range(\n 'min',\n 'max',\n isNumber,\n (min, max) =>\n ColumnFilter.Range({ min: Option.map(min, Number), max: Option.map(max, Number) }),\n (low, high) => Number(low) > Number(high),\n ),\n Choice: () =>\n form.options.length === 0\n ? none\n : { ...none, filter: Option.some(ColumnFilter.OneOf({ options: form.options })) },\n Checkbox: () =>\n form.checked === 'any'\n ? none\n : { ...none, filter: Option.some(ColumnFilter.Is({ checked: form.checked === 'true' })) },\n Date: () =>\n range(\n 'from',\n 'to',\n isDay,\n (from, to) => ColumnFilter.Between({ from, to }),\n (low, high) => low > high,\n ),\n })\n}\n\n/** Whether `test` holds of the value, or there is none to test. */\nconst unlessNone = <A>(value: Option.Option<A>, test: (a: A) => boolean): boolean =>\n Option.match(value, { onNone: () => true, onSome: test })\n\n// ASCII only, as `Expr.contains` folds on every backend.\nconst fold = (text: string): string =>\n text.replace(/[A-Z]/g, letter => String.fromCharCode(letter.charCodeAt(0) + 32))\n\nconst localDay = (date: Date): string => {\n const month = String(date.getMonth() + 1).padStart(2, '0')\n const day = String(date.getDate()).padStart(2, '0')\n return `${date.getFullYear()}-${month}-${day}`\n}\n\n/** Whether one filter keeps a value read from a row. */\nexport const testOf = (filter: ColumnFilter): ((value: unknown) => boolean) =>\n ColumnFilter.match(filter, {\n Contains: ({ text }) => {\n const wanted = fold(text)\n return (value: unknown) => fold(value as string).includes(wanted)\n },\n Range:\n ({ min, max }) =>\n (value: unknown) =>\n unlessNone(min, low => (value as number) >= low) &&\n unlessNone(max, high => (value as number) <= high),\n OneOf: ({ options }) => {\n const among = new Set<unknown>(options)\n return (value: unknown) => among.has(value)\n },\n Is:\n ({ checked }) =>\n (value: unknown) =>\n value === checked,\n Between:\n ({ from, to }) =>\n (value: unknown) => {\n const date = value as Date\n if (Number.isNaN(date.getTime())) return false\n const at = localDay(date)\n return unlessNone(from, low => at >= low) && unlessNone(to, high => at <= high)\n },\n })\n"],"mappings":";;;;;AAKA,MAAM,MAAM,OAAO,OAAO,MAAM,OAAO,UAAU,qBAAqB,CAAC;;;;;;;AAQvE,MAAa,eAAe,kBAAkB;;CAE5C,UAAU,EAAE,MAAM,OAAO,OAAO;;CAEhC,OAAO;EACL,KAAK,OAAO,iBAAiB,OAAO,MAAM;EAC1C,KAAK,OAAO,iBAAiB,OAAO,MAAM;CAC5C;;CAEA,OAAO,EAAE,SAAS,OAAO,MAAM,OAAO,MAAM,EAAE;CAC9C,IAAI,EAAE,SAAS,OAAO,QAAQ;;CAE9B,SAAS;EAAE,MAAM,OAAO,iBAAiB,GAAG;EAAG,IAAI,OAAO,iBAAiB,GAAG;CAAE;AAClF,CAAC;;;;;;AA+FD,MAAa,kBAAkB,SAA0D;CAEvF,MAAM,aAAa,GAA2B,MAC5C,OAAO,OAAO,CAAC,KAAK,OAAO,OAAO,CAAC;CAsBrC,OArB2B,WAAW,MAAM,MAAM;EAChD,YACE,OAAO,aAAa,YAAY,EAAE,MAAM,OAAO,OAAO,MAAM,OAAO,YAAY,CAAC,CAAC,EAAE,CAAC;EACtF,cACE,aAAa,MAAM,MACjB,OAAO,YAAmB,EAAE,KAAK,UAAU,UAAU,KAAK,GAAG,GAAG,EAAE,UAAU,UAAU,CAAC,CACzF;EACF,SAAS,E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