griddle-effect 0.0.0-stage → 2.0.0-alpha.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.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +40 -2
  3. package/THIRD_PARTY_NOTICES.md +18 -0
  4. package/dist/compose.d.ts +58 -0
  5. package/dist/compose.d.ts.map +1 -0
  6. package/dist/compose.js +144 -0
  7. package/dist/compose.js.map +1 -0
  8. package/dist/core/actions.d.ts +31 -0
  9. package/dist/core/actions.d.ts.map +1 -0
  10. package/dist/core/actions.js +28 -0
  11. package/dist/core/actions.js.map +1 -0
  12. package/dist/core/math.d.ts +42 -0
  13. package/dist/core/math.d.ts.map +1 -0
  14. package/dist/core/math.js +76 -0
  15. package/dist/core/math.js.map +1 -0
  16. package/dist/core/plugin.d.ts +8 -0
  17. package/dist/core/plugin.d.ts.map +1 -0
  18. package/dist/core/plugin.js +131 -0
  19. package/dist/core/plugin.js.map +1 -0
  20. package/dist/core/state.d.ts +88 -0
  21. package/dist/core/state.d.ts.map +1 -0
  22. package/dist/core/state.js +69 -0
  23. package/dist/core/state.js.map +1 -0
  24. package/dist/definition.d.ts +61 -0
  25. package/dist/definition.d.ts.map +1 -0
  26. package/dist/definition.js +63 -0
  27. package/dist/definition.js.map +1 -0
  28. package/dist/headless.d.ts +26 -0
  29. package/dist/headless.d.ts.map +1 -0
  30. package/dist/headless.js +35 -0
  31. package/dist/headless.js.map +1 -0
  32. package/dist/index.d.ts +22 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +14 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/plugin.d.ts +136 -0
  37. package/dist/plugin.d.ts.map +1 -0
  38. package/dist/plugin.js +2 -0
  39. package/dist/plugin.js.map +1 -0
  40. package/dist/plugins/index.d.ts +3 -0
  41. package/dist/plugins/index.d.ts.map +1 -0
  42. package/dist/plugins/index.js +3 -0
  43. package/dist/plugins/index.js.map +1 -0
  44. package/dist/plugins/local.d.ts +7 -0
  45. package/dist/plugins/local.d.ts.map +1 -0
  46. package/dist/plugins/local.js +26 -0
  47. package/dist/plugins/local.js.map +1 -0
  48. package/dist/plugins/virtual.d.ts +19 -0
  49. package/dist/plugins/virtual.d.ts.map +1 -0
  50. package/dist/plugins/virtual.js +42 -0
  51. package/dist/plugins/virtual.js.map +1 -0
  52. package/dist/store.d.ts +41 -0
  53. package/dist/store.d.ts.map +1 -0
  54. package/dist/store.js +57 -0
  55. package/dist/store.js.map +1 -0
  56. package/dist/ui/Griddle.d.ts +198 -0
  57. package/dist/ui/Griddle.d.ts.map +1 -0
  58. package/dist/ui/Griddle.js +70 -0
  59. package/dist/ui/Griddle.js.map +1 -0
  60. package/dist/ui/components.d.ts +4 -0
  61. package/dist/ui/components.d.ts.map +1 -0
  62. package/dist/ui/components.js +69 -0
  63. package/dist/ui/components.js.map +1 -0
  64. package/package.json +56 -4
@@ -0,0 +1,136 @@
1
+ import type { Action, ColumnProperties, GriddleState } from "./core/state.ts";
2
+ import type { Row, RowWindow, SortDirection } from "./core/math.ts";
3
+ export type ComponentName = "Layout" | "Table" | "TableHead" | "HeaderCell" | "TableBody" | "Row" | "Cell" | "Filter" | "Pagination" | "PageDropdown" | "Settings" | "NoResults" | "Loading";
4
+ /** One visible row, plain data. `index` is the row's index in the original data. */
5
+ export interface RowView {
6
+ readonly key: string;
7
+ readonly index: number;
8
+ readonly data: Row;
9
+ }
10
+ export interface ColumnView extends ColumnProperties {
11
+ readonly title: string;
12
+ readonly sortDirection: SortDirection | null;
13
+ }
14
+ export interface PaginationView {
15
+ readonly page: number;
16
+ readonly pageSize: number;
17
+ readonly maxPage: number;
18
+ readonly total: number;
19
+ readonly hasNext: boolean;
20
+ readonly hasPrevious: boolean;
21
+ }
22
+ /** What the headless core hands back: plain data, no UI. */
23
+ export interface GriddleView {
24
+ readonly rows: ReadonlyArray<RowView>;
25
+ readonly columns: ReadonlyArray<ColumnView>;
26
+ readonly pagination: PaginationView;
27
+ readonly window: RowWindow | null;
28
+ readonly filter: string;
29
+ readonly settingsOpen: boolean;
30
+ /** True when `data` is null or undefined: the data has not arrived yet. */
31
+ readonly loading: boolean;
32
+ readonly enableSettings: boolean;
33
+ readonly text: Readonly<Record<string, string>>;
34
+ readonly settings: Readonly<Record<string, unknown>>;
35
+ readonly state: GriddleState;
36
+ }
37
+ /** Every selector a plugin may define or override. `view` is the one callers read. */
38
+ export interface Selectors {
39
+ readonly data: ReadonlyArray<Row>;
40
+ readonly columnIds: ReadonlyArray<string>;
41
+ readonly columns: ReadonlyArray<ColumnView>;
42
+ readonly filteredData: ReadonlyArray<Row>;
43
+ readonly sortedData: ReadonlyArray<Row>;
44
+ readonly maxPage: number;
45
+ readonly total: number;
46
+ readonly pageData: ReadonlyArray<Row>;
47
+ readonly window: RowWindow | null;
48
+ readonly visibleRows: ReadonlyArray<RowView>;
49
+ readonly pagination: PaginationView;
50
+ readonly view: GriddleView;
51
+ /** Row key function: honors `state.rowKey`, else `id`, `griddleKey`, then the index. */
52
+ readonly rowKeyOf: (row: Row, index: number) => string;
53
+ /** Per-column compare functions, plus `"*"` for a default. Used by LocalPlugin's sort. */
54
+ readonly sortMethods: Readonly<Record<string, CompareFn>>;
55
+ readonly loading: boolean;
56
+ readonly [name: string]: unknown;
57
+ }
58
+ /** Ascending comparator for one column. `a`/`b` are the cell values; the rows are passed too. */
59
+ export type CompareFn = (a: unknown, b: unknown, rowA: Row, rowB: Row) => number;
60
+ export interface SelectorContext {
61
+ readonly data: ReadonlyArray<Row>;
62
+ readonly state: GriddleState;
63
+ }
64
+ /**
65
+ * `sel` is the final composed selector set (so overriding `sortedData` also changes
66
+ * `pageData`). `base` is the previous layer's version of this same selector.
67
+ */
68
+ export type SelectorImpl<T = unknown> = (ctx: SelectorContext, sel: Selectors, base: () => T) => T;
69
+ /**
70
+ * Declares what a selector reads, so its result can be reused while those inputs keep the same
71
+ * identity. Return the state fields and upstream selectors the selector depends on.
72
+ */
73
+ export type SelectorDeps = (ctx: SelectorContext, sel: Selectors) => ReadonlyArray<unknown>;
74
+ export interface ReducerEnv {
75
+ readonly data: ReadonlyArray<Row>;
76
+ /** Selectors resolved against the state the reducer received. */
77
+ readonly sel: Selectors;
78
+ /** The previous layer's reducer for this action type. */
79
+ readonly base: (state: GriddleState, payload?: unknown) => GriddleState;
80
+ }
81
+ export type Reducer = (state: GriddleState, payload: any, env: ReducerEnv) => GriddleState;
82
+ /** Props every default (and overriding) component receives. `h` is the Effect UI builder. */
83
+ export interface ComponentContext {
84
+ readonly view: GriddleView;
85
+ readonly sel: Selectors;
86
+ /** Message builders: `ctx.msg.setPage(2)` is the value to give `.on("click", ...)`. */
87
+ readonly msg: Readonly<Record<string, (...args: any[]) => unknown>>;
88
+ /** Class name for a component after plugin style merging. */
89
+ readonly cls: (name: string, ...extra: Array<string | undefined>) => string;
90
+ /** The component set after plugin merging, to call children by name. */
91
+ readonly components: Readonly<Record<ComponentName, ComponentImpl>>;
92
+ /** Per-component extras: a row, a column, a cell value... */
93
+ readonly [extra: string]: any;
94
+ }
95
+ export type ComponentImpl = (h: any, ctx: ComponentContext) => any;
96
+ /** The v1 plugin shape, plus Effect-friendly spots. Every field is optional. */
97
+ export interface GriddlePlugin {
98
+ readonly name?: string;
99
+ /** Merged over the default state; `settings` is deep-merged one level. */
100
+ readonly initialState?: Partial<Omit<GriddleState, "settings">> & {
101
+ readonly settings?: Record<string, unknown>;
102
+ };
103
+ readonly components?: Partial<Record<ComponentName, ComponentImpl>>;
104
+ /**
105
+ * Wrap the component built so far (v1's `RowEnhancer`/`CellEnhancer` idea): `Cell: (base) => (h, ctx) => ...`.
106
+ * Applied after `components` of the same plugin, in plugin order.
107
+ */
108
+ readonly wrapComponents?: Partial<Record<ComponentName, (base: ComponentImpl) => ComponentImpl>>;
109
+ /** Class names per component, joined across plugins in order. */
110
+ readonly styles?: Partial<Record<ComponentName | (string & {}), string>>;
111
+ /** Reducers by action type. Later plugins win; `env.base` reaches the earlier one. */
112
+ readonly reducers?: Readonly<Record<string, Reducer>>;
113
+ readonly selectors?: Readonly<Record<string, SelectorImpl<any>>>;
114
+ /**
115
+ * Optional dependencies per selector. A selector with deps is memoized per grid instance and only
116
+ * recomputed when a dep changes identity. A selector without deps always recomputes, so a plugin
117
+ * that overrides a selector without declaring deps switches memoization off for that selector.
118
+ * `"inherit"` keeps the previous layer's deps, for a wrapper whose result depends only on `base()`.
119
+ */
120
+ readonly selectorDeps?: Readonly<Record<string, SelectorDeps | "inherit">>;
121
+ /** Extra action creators. They show up in `actions` (headless) and `ctx.msg` (UI). */
122
+ readonly events?: Readonly<Record<string, (...args: any[]) => Action>>;
123
+ }
124
+ /** A plugin, or a function that makes one. Both work in `plugins=[...]`. */
125
+ export type PluginInput = GriddlePlugin | (() => GriddlePlugin);
126
+ export interface ComposedPlugins {
127
+ readonly plugins: ReadonlyArray<GriddlePlugin>;
128
+ readonly initialState: GriddleState;
129
+ readonly components: Readonly<Record<ComponentName, ComponentImpl>>;
130
+ readonly styles: Readonly<Record<string, string>>;
131
+ readonly reducers: Readonly<Record<string, Reducer>>;
132
+ readonly selectors: Readonly<Record<string, SelectorImpl<any>>>;
133
+ readonly selectorDeps: Readonly<Record<string, SelectorDeps>>;
134
+ readonly events: Readonly<Record<string, (...args: any[]) => Action>>;
135
+ }
136
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC7E,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnE,MAAM,MAAM,aAAa,GACrB,QAAQ,GAAG,OAAO,GAAG,WAAW,GAAG,YAAY,GAAG,WAAW,GAAG,KAAK,GAAG,MAAM,GAC9E,QAAQ,GA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2 @@
1
+ export {};
2
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export { LocalPlugin } from "./local.ts";
2
+ export { VirtualScrollConfig, VirtualScrollPlugin } from "./virtual.ts";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,3 @@
1
+ export { LocalPlugin } from "./local.js";
2
+ export { VirtualScrollConfig, VirtualScrollPlugin } from "./virtual.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,7 @@
1
+ import type { GriddlePlugin } from "../plugin.ts";
2
+ /**
3
+ * Port of Griddle v1's LocalPlugin: sort, filter and paginate `data` client-side.
4
+ * It only overrides selectors, exactly like v1; the core reducers stay as they are.
5
+ */
6
+ export declare const LocalPlugin: () => GriddlePlugin;
7
+ //# sourceMappingURL=local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../src/plugins/local.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEjD;;;GAGG;AACH,eAAO,MAAM,WAAW,QAAO,aAmB7B,CAAA"}
@@ -0,0 +1,26 @@
1
+ import { filterRows, maxPage, paginate, sortRows } from "../core/math.js";
2
+ /**
3
+ * Port of Griddle v1's LocalPlugin: sort, filter and paginate `data` client-side.
4
+ * It only overrides selectors, exactly like v1; the core reducers stay as they are.
5
+ */
6
+ export const LocalPlugin = () => ({
7
+ name: "local",
8
+ selectors: {
9
+ filteredData: ({ state }, s) => {
10
+ const props = new Map(state.columns.map((c) => [c.id, c]));
11
+ return filterRows(s.data, state.filter, (col) => props.get(col)?.filterable !== false && col !== "griddleKey");
12
+ },
13
+ sortedData: ({ state }, s) => sortRows(s.filteredData, state.sort, s.sortMethods),
14
+ total: (_c, s) => s.sortedData.length,
15
+ maxPage: ({ state }, s) => maxPage(s.total, state.pageSize),
16
+ pageData: ({ state }, s) => paginate(s.sortedData, state.page, state.pageSize)
17
+ },
18
+ selectorDeps: {
19
+ filteredData: ({ state }, s) => [s.data, state.filter, state.columns],
20
+ sortedData: ({ state }, s) => [s.filteredData, state.sort, s.sortMethods],
21
+ total: (_c, s) => [s.sortedData],
22
+ maxPage: ({ state }, s) => [s.total, state.pageSize],
23
+ pageData: ({ state }, s) => [s.sortedData, state.page, state.pageSize]
24
+ }
25
+ });
26
+ //# sourceMappingURL=local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local.js","sourceRoot":"","sources":["../../src/plugins/local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAGzE;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAkB,EAAE,CAAC,CAAC;IAC/C,IAAI,EAAE,OAAO;IACb,SAAS,EAAE;QACT,YAAY,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;YAC7B,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,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E,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC;QACpD,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC;KACvE;CACF,CAAC,CAAA"}
@@ -0,0 +1,19 @@
1
+ import { Schema } from "effect";
2
+ import type { GriddlePlugin } from "../plugin.ts";
3
+ export declare const VirtualScrollConfig: Schema.Struct<{
4
+ readonly rowHeight: Schema.Number;
5
+ readonly viewportHeight: Schema.Number;
6
+ readonly overscan: Schema.optional<Schema.Number>;
7
+ }>;
8
+ export type VirtualScrollConfig = typeof VirtualScrollConfig.Type;
9
+ /**
10
+ * Port of Griddle v1's position/virtual scrolling. Config is a Schema, so a bad value fails at
11
+ * plugin creation. In the UI the rows are windowed by Effect UI's `VirtualList` (from `effect/ui/kit`)
12
+ * drawn as a `<tbody>`: it owns scrolling, overscan, focus retention and the spacer rows, so a scroll
13
+ * never goes through the grid's own update. The windowing math in the core (`window`, `visibleRows`)
14
+ * stays for headless use, where there is no DOM to scroll.
15
+ *
16
+ * Rows are fixed height (`rowHeight`), so the list runs with `measure: false` and needs no measuring.
17
+ */
18
+ export declare const VirtualScrollPlugin: (config: VirtualScrollConfig) => GriddlePlugin;
19
+ //# sourceMappingURL=virtual.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"virtual.d.ts","sourceRoot":"","sources":["../../src/plugins/virtual.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEjD,eAAO,MAAM,mBAAmB;;;;EAI9B,CAAA;AACF,MAAM,MAAM,mBAAmB,GAAG,OAAO,mBAAmB,CAAC,IAAI,CAAA;AAEjE;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAAI,QAAQ,mBAAmB,KAAG,aAkCjE,CAAA"}
@@ -0,0 +1,42 @@
1
+ import { Schema } from "effect";
2
+ import { VirtualList } from "effect/ui/kit";
3
+ export const VirtualScrollConfig = Schema.Struct({
4
+ rowHeight: Schema.Number,
5
+ viewportHeight: Schema.Number,
6
+ overscan: Schema.optional(Schema.Number)
7
+ });
8
+ /**
9
+ * Port of Griddle v1's position/virtual scrolling. Config is a Schema, so a bad value fails at
10
+ * plugin creation. In the UI the rows are windowed by Effect UI's `VirtualList` (from `effect/ui/kit`)
11
+ * drawn as a `<tbody>`: it owns scrolling, overscan, focus retention and the spacer rows, so a scroll
12
+ * never goes through the grid's own update. The windowing math in the core (`window`, `visibleRows`)
13
+ * stays for headless use, where there is no DOM to scroll.
14
+ *
15
+ * Rows are fixed height (`rowHeight`), so the list runs with `measure: false` and needs no measuring.
16
+ */
17
+ export const VirtualScrollPlugin = (config) => {
18
+ const c = Schema.decodeUnknownSync(VirtualScrollConfig)(config);
19
+ return {
20
+ name: "virtual-scroll",
21
+ initialState: { rowHeight: c.rowHeight, viewportHeight: c.viewportHeight, overscan: c.overscan ?? 3 },
22
+ styles: { Table: "griddle-virtual" },
23
+ components: {
24
+ Table: (h, ctx) => {
25
+ const rows = ctx.sel.pageData;
26
+ const keyOf = (row, i) => String(row["id"] ?? row["griddleKey"] ?? i);
27
+ return VirtualList(h, {
28
+ key: "griddle-virtual-list",
29
+ props: { count: rows.length, itemSize: c.rowHeight, measure: false, overscan: c.overscan ?? 3 },
30
+ view: (list) => list.viewport(h.div.class(ctx.cls("Table")).attr("data-virtual", "true").attr("style", `height:${c.viewportHeight}px;overflow:auto;`)).children(list.table(h.table.class(ctx.cls("TableInner")).attr("style", "width:100%;border-collapse:collapse;")).children(ctx.components.TableHead(h, ctx), list.list(h.tbody).children(list.items.map((index) => {
31
+ const data = rows[index];
32
+ const row = { key: keyOf(data, index), index, data };
33
+ // The Row component builds the <tr>, so a Row override applies in virtual mode too.
34
+ const element = ctx.components.Row(h, { ...ctx, row }).key(row.key);
35
+ return list.item({ element, index });
36
+ }))))
37
+ });
38
+ }
39
+ }
40
+ };
41
+ };
42
+ //# sourceMappingURL=virtual.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"virtual.js","sourceRoot":"","sources":["../../src/plugins/virtual.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAG3C,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/C,SAAS,EAAE,MAAM,CAAC,MAAM;IACxB,cAAc,EAAE,MAAM,CAAC,MAAM;IAC7B,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;CACzC,CAAC,CAAA;AAGF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAA2B,EAAiB,EAAE;IAChF,MAAM,CAAC,GAAG,MAAM,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAA;IAC/D,OAAO;QACL,IAAI,EAAE,gBAAgB;QACtB,YAAY,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,EAAE,cAAc,EAAE,CAAC,CAAC,cAAc,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,CAAC,EAAE;QACrG,MAAM,EAAE,EAAE,KAAK,EAAE,iBAAiB,EAAE;QACpC,UAAU,EAAE;YACV,KAAK,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;gBAChB,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,QAAkD,CAAA;gBACvE,MAAM,KAAK,GAAG,CAAC,GAA4B,EAAE,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,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AAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;wBACnE,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAA;oBACtC,CAAC,CAAC,CACH,CACF,CACF;iBACJ,CAAC,CAAA;YACJ,CAAC;SACF;KACF,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,41 @@
1
+ import type { GriddleEvents } from "./compose.ts";
2
+ import type { RowDefinitionInput } from "./definition.ts";
3
+ import type { Row } from "./core/math.ts";
4
+ import type { Action, GriddleConfig, GriddleState } from "./core/state.ts";
5
+ import type { ComposedPlugins, GriddleView, PluginInput } from "./plugin.ts";
6
+ export interface HeadlessOptions extends GriddleConfig {
7
+ /** `null` or `undefined` means the data has not arrived yet (`view.loading` is true). */
8
+ readonly data?: ReadonlyArray<Row> | null;
9
+ readonly plugins?: ReadonlyArray<PluginInput>;
10
+ /** Set `false` for server-side data: skips LocalPlugin so `data` is used as the finished page. */
11
+ readonly local?: boolean;
12
+ readonly definition?: RowDefinitionInput;
13
+ readonly events?: GriddleEvents;
14
+ }
15
+ export declare const composeFor: (options: Pick<HeadlessOptions, "plugins" | "local" | "definition">) => ComposedPlugins;
16
+ /** Config fields only, as the initial state patch. */
17
+ export declare const configPatch: (o: GriddleConfig) => Partial<GriddleState> & {
18
+ settings?: Record<string, unknown>;
19
+ };
20
+ type Handlers = Readonly<Record<string, (...args: any[]) => void>>;
21
+ export interface Griddle {
22
+ readonly getState: () => GriddleState;
23
+ /** The plain-data result: rows, columns, pagination, window. Render it however you like. */
24
+ readonly getView: () => GriddleView;
25
+ readonly setData: (data: ReadonlyArray<Row> | null | undefined) => void;
26
+ readonly dispatch: (action: Action) => void;
27
+ /** Subscribe to view changes. Returns an unsubscribe function. */
28
+ readonly subscribe: (listener: (view: GriddleView) => void) => () => void;
29
+ /** Core actions and plugin events, bound to dispatch: `handlers.setPage(2)`. */
30
+ readonly handlers: Handlers;
31
+ }
32
+ /**
33
+ * The simple, non-Effect entry: a tiny store with the same pipeline as the Effect API.
34
+ *
35
+ * const g = createGriddle({ data, pageSize: 20, plugins: [...] })
36
+ * g.handlers.toggleSort("name")
37
+ * g.getView().rows
38
+ */
39
+ export declare const createGriddle: (options: HeadlessOptions) => Griddle;
40
+ export {};
41
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAGzD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE5E,MAAM,WAAW,eAAgB,SAAQ,aAAa;IACpD,yFAAyF;IACzF,QAAQ,CAAC,IAAI,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,IAAI,CAAA;IACzC,QAAQ,CAAC,OAAO,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAA;IAC7C,kGAAkG;IAClG,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,kBAAkB,CAAA;IACxC,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAA;CAChC;AAED,eAAO,MAAM,UAAU,GAAI,SAAS,IAAI,CAAC,eAAe,EAAE,SAAS,GAAG,OAAO,GAAG,YAAY,CAAC,KAAG,eAK5F,CAAA;AAEJ,sDAAsD;AACtD,eAAO,MAAM,WAAW,GAAI,GAAG,aAAa,KAEuF,OAAO,CAAC,YAAY,CAAC,GAAG;IACvJ,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAErC,CAAA;AAED,KAAK,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC,CAAA;AAElE,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,YAAY,CAAA;IACrC,4FAA4F;IAC5F,QAAQ,CAAC,OAAO,EAAE,MAAM,WAAW,CAAA;IACnC,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,KAAK,IAAI,CAAA;IACvE,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3C,kEAAkE;IAClE,QAAQ,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,KAAK,MAAM,IAAI,CAAA;IACzE,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;CAC5B;AAED;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,eAAe,KAAG,OAkCxD,CAAA"}
package/dist/store.js ADDED
@@ -0,0 +1,57 @@
1
+ import { composePlugins, createSelectorMemo, initialStateFor, notifyEvents, reduce, resolveView } from "./compose.js";
2
+ import { DefinitionPlugin } from "./definition.js";
3
+ import { MISSING_DATA } from "./core/state.js";
4
+ import { LocalPlugin } from "./plugins/local.js";
5
+ export const composeFor = (options) => composePlugins([
6
+ ...(options.local === false ? [] : [LocalPlugin()]),
7
+ ...(options.definition ? [DefinitionPlugin(options.definition)] : []),
8
+ ...(options.plugins ?? [])
9
+ ]);
10
+ /** Config fields only, as the initial state patch. */
11
+ export const configPatch = (o) => {
12
+ const { filter, sort, page, pageSize, columns, rowHeight, viewportHeight, overscan, settings, rowKey, enableSettings, text } = o;
13
+ return { filter, sort, page, pageSize, columns, rowHeight, viewportHeight, overscan, settings, rowKey, enableSettings, text };
14
+ };
15
+ /**
16
+ * The simple, non-Effect entry: a tiny store with the same pipeline as the Effect API.
17
+ *
18
+ * const g = createGriddle({ data, pageSize: 20, plugins: [...] })
19
+ * g.handlers.toggleSort("name")
20
+ * g.getView().rows
21
+ */
22
+ export const createGriddle = (options) => {
23
+ const composed = composeFor(options);
24
+ const memo = createSelectorMemo();
25
+ let data = options.data ?? MISSING_DATA;
26
+ let state = initialStateFor(composed, configPatch(options));
27
+ const listeners = new Set();
28
+ const dispatch = (action) => {
29
+ const next = reduce(composed, state, action, data, memo);
30
+ if (next === state)
31
+ return;
32
+ state = next;
33
+ notifyEvents(options.events, action, next);
34
+ notify();
35
+ };
36
+ const notify = () => {
37
+ if (listeners.size === 0)
38
+ return;
39
+ const v = resolveView(composed, data, state, memo);
40
+ listeners.forEach((l) => l(v));
41
+ };
42
+ return {
43
+ getState: () => state,
44
+ getView: () => resolveView(composed, data, state, memo),
45
+ setData: (d) => {
46
+ data = d ?? MISSING_DATA;
47
+ notify();
48
+ },
49
+ dispatch,
50
+ subscribe: (l) => {
51
+ listeners.add(l);
52
+ return () => listeners.delete(l);
53
+ },
54
+ handlers: Object.fromEntries(Object.entries(composed.events).map(([name, create]) => [name, (...args) => dispatch(create(...args))]))
55
+ };
56
+ };
57
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAErH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAehD,MAAM,CA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EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAC/G;KACF,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,198 @@
1
+ import { UiSchema } from "effect/ui";
2
+ import { Html } from "effect/ui/html";
3
+ import { Schema } from "effect";
4
+ import type { GriddleEvents } from "../compose.ts";
5
+ import type { RowDefinitionInput } from "../definition.ts";
6
+ import type { PluginInput } from "../plugin.ts";
7
+ export declare const GriddleMessage: UiSchema.TaggedEnum<{
8
+ readonly Dispatched: Schema.TaggedStruct<"Dispatched", {
9
+ readonly action: Schema.Struct<{
10
+ readonly type: Schema.String;
11
+ readonly payload: Schema.optional<Schema.Unknown>;
12
+ }>;
13
+ }>;
14
+ }>;
15
+ export declare const GriddleProps: Schema.Struct<{
16
+ /** `null` or missing means the data has not arrived: the grid shows its Loading component. */
17
+ readonly data: Schema.optional<Schema.NullOr<Schema.$Array<Schema.$Record<Schema.String, Schema.Unknown>>>>;
18
+ readonly config: Schema.optional<Schema.Struct<{
19
+ readonly filter: Schema.optional<Schema.String>;
20
+ readonly sort: Schema.optional<Schema.$Array<Schema.Struct<{
21
+ readonly column: Schema.String;
22
+ readonly direction: Schema.Literals<readonly ["asc", "desc"]>;
23
+ }>>>;
24
+ readonly page: Schema.optional<Schema.Number>;
25
+ readonly pageSize: Schema.optional<Schema.Number>;
26
+ readonly columns: Schema.optional<Schema.$Array<Schema.Struct<{
27
+ readonly id: Schema.String;
28
+ readonly title: Schema.optional<Schema.String>;
29
+ readonly order: Schema.optional<Schema.Number>;
30
+ readonly visible: Schema.optional<Schema.Boolean>;
31
+ readonly sortable: Schema.optional<Schema.Boolean>;
32
+ readonly filterable: Schema.optional<Schema.Boolean>;
33
+ }>>>;
34
+ readonly rowHeight: Schema.optional<Schema.Number>;
35
+ readonly viewportHeight: Schema.optional<Schema.Number>;
36
+ readonly overscan: Schema.optional<Schema.Number>;
37
+ readonly rowKey: Schema.optional<Schema.String>;
38
+ readonly enableSettings: Schema.optional<Schema.Boolean>;
39
+ readonly text: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
40
+ readonly settings: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
41
+ }>>;
42
+ }>;
43
+ export interface GriddleOptions {
44
+ /** v1-style: later plugins override earlier ones. */
45
+ readonly plugins?: ReadonlyArray<PluginInput>;
46
+ /** `false` for server-side data; skips LocalPlugin. */
47
+ readonly local?: boolean;
48
+ readonly name?: string;
49
+ /** v1's `RowDefinition` / `ColumnDefinition`: declarative columns, rowKey, custom cells, sort methods. */
50
+ readonly definition?: RowDefinitionInput;
51
+ /** v1's `events`: callbacks fired after filter, sort and paging actions. */
52
+ readonly events?: GriddleEvents;
53
+ }
54
+ /**
55
+ * Build a Griddle Effect UI component. Plugins are chosen here, data and config
56
+ * come in as props:
57
+ *
58
+ * const Grid = makeGriddle({ plugins: [VirtualScrollPlugin({ rowHeight: 28, viewportHeight: 280 })] })
59
+ * Grid(h, { props: { data } })
60
+ */
61
+ export declare const makeGriddle: (options?: GriddleOptions) => import("effect/ui/Component").Component<string, {
62
+ readonly data?: readonly {
63
+ readonly [x: string]: unknown;
64
+ }[] | null | undefined;
65
+ readonly config?: {
66
+ readonly sort?: readonly {
67
+ readonly column: string;
68
+ readonly direction: "asc" | "desc";
69
+ }[] | undefined;
70
+ readonly columns?: readonly {
71
+ readonly id: string;
72
+ readonly title?: string | undefined;
73
+ readonly order?: number | undefined;
74
+ readonly visible?: boolean | undefined;
75
+ readonly sortable?: boolean | undefined;
76
+ readonly filterable?: boolean | undefined;
77
+ }[] | undefined;
78
+ readonly text?: {
79
+ readonly [x: string]: string;
80
+ } | undefined;
81
+ readonly settings?: {
82
+ readonly [x: string]: unknown;
83
+ } | undefined;
84
+ readonly filter?: string | undefined;
85
+ readonly page?: number | undefined;
86
+ readonly pageSize?: number | undefined;
87
+ readonly viewportHeight?: number | undefined;
88
+ readonly rowHeight?: number | undefined;
89
+ readonly overscan?: number | undefined;
90
+ readonly rowKey?: string | undefined;
91
+ readonly enableSettings?: boolean | undefined;
92
+ } | undefined;
93
+ }, {
94
+ readonly filter: string;
95
+ readonly sort: readonly {
96
+ readonly column: string;
97
+ readonly direction: "asc" | "desc";
98
+ }[];
99
+ readonly page: number;
100
+ readonly pageSize: number;
101
+ readonly columns: readonly {
102
+ readonly id: string;
103
+ readonly title?: string | undefined;
104
+ readonly order?: number | undefined;
105
+ readonly visible?: boolean | undefined;
106
+ readonly sortable?: boolean | undefined;
107
+ readonly filterable?: boolean | undefined;
108
+ }[];
109
+ readonly scrollTop: number;
110
+ readonly viewportHeight: number;
111
+ readonly rowHeight: number;
112
+ readonly overscan: number;
113
+ readonly settingsOpen: boolean;
114
+ readonly rowKey: string;
115
+ readonly enableSettings: boolean;
116
+ readonly text: {
117
+ readonly [x: string]: string;
118
+ };
119
+ readonly settings: {
120
+ readonly [x: string]: unknown;
121
+ };
122
+ }, {
123
+ readonly _tag: "Dispatched";
124
+ readonly action: {
125
+ readonly type: string;
126
+ readonly payload?: unknown;
127
+ };
128
+ }, never, never, Html.Elements, {}, never>;
129
+ /** Default Griddle: client-side sort / filter / paging with the default components. */
130
+ export declare const Griddle: import("effect/ui/Component").Component<string, {
131
+ readonly data?: readonly {
132
+ readonly [x: string]: unknown;
133
+ }[] | null | undefined;
134
+ readonly config?: {
135
+ readonly sort?: readonly {
136
+ readonly column: string;
137
+ readonly direction: "asc" | "desc";
138
+ }[] | undefined;
139
+ readonly columns?: readonly {
140
+ readonly id: string;
141
+ readonly title?: string | undefined;
142
+ readonly order?: number | undefined;
143
+ readonly visible?: boolean | undefined;
144
+ readonly sortable?: boolean | undefined;
145
+ readonly filterable?: boolean | undefined;
146
+ }[] | undefined;
147
+ readonly text?: {
148
+ readonly [x: string]: string;
149
+ } | undefined;
150
+ readonly settings?: {
151
+ readonly [x: string]: unknown;
152
+ } | undefined;
153
+ readonly filter?: string | undefined;
154
+ readonly page?: number | undefined;
155
+ readonly pageSize?: number | undefined;
156
+ readonly viewportHeight?: number | undefined;
157
+ readonly rowHeight?: number | undefined;
158
+ readonly overscan?: number | undefined;
159
+ readonly rowKey?: string | undefined;
160
+ readonly enableSettings?: boolean | undefined;
161
+ } | undefined;
162
+ }, {
163
+ readonly filter: string;
164
+ readonly sort: readonly {
165
+ readonly column: string;
166
+ readonly direction: "asc" | "desc";
167
+ }[];
168
+ readonly page: number;
169
+ readonly pageSize: number;
170
+ readonly columns: readonly {
171
+ readonly id: string;
172
+ readonly title?: string | undefined;
173
+ readonly order?: number | undefined;
174
+ readonly visible?: boolean | undefined;
175
+ readonly sortable?: boolean | undefined;
176
+ readonly filterable?: boolean | undefined;
177
+ }[];
178
+ readonly scrollTop: number;
179
+ readonly viewportHeight: number;
180
+ readonly rowHeight: number;
181
+ readonly overscan: number;
182
+ readonly settingsOpen: boolean;
183
+ readonly rowKey: string;
184
+ readonly enableSettings: boolean;
185
+ readonly text: {
186
+ readonly [x: string]: string;
187
+ };
188
+ readonly settings: {
189
+ readonly [x: string]: unknown;
190
+ };
191
+ }, {
192
+ readonly _tag: "Dispatched";
193
+ readonly action: {
194
+ readonly type: string;
195
+ readonly payload?: unknown;
196
+ };
197
+ }, never, never, Html.Elements, {}, never>;
198
+ //# sourceMappingURL=Griddle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Griddle.d.ts","sourceRoot":"","sources":["../../src/ui/Griddle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAQ,MAAM,WAAW,CAAA;AAC1C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAK1D,OAAO,KAAK,EAAm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