griddle-effect 0.0.0-stage → 2.0.0-alpha.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/LICENSE +21 -0
- package/README.md +34 -2
- package/THIRD_PARTY_NOTICES.md +18 -0
- package/dist/compose.d.ts +58 -0
- package/dist/compose.d.ts.map +1 -0
- package/dist/compose.js +144 -0
- package/dist/compose.js.map +1 -0
- package/dist/core/actions.d.ts +31 -0
- package/dist/core/actions.d.ts.map +1 -0
- package/dist/core/actions.js +28 -0
- package/dist/core/actions.js.map +1 -0
- package/dist/core/math.d.ts +42 -0
- package/dist/core/math.d.ts.map +1 -0
- package/dist/core/math.js +76 -0
- package/dist/core/math.js.map +1 -0
- package/dist/core/plugin.d.ts +8 -0
- package/dist/core/plugin.d.ts.map +1 -0
- package/dist/core/plugin.js +131 -0
- package/dist/core/plugin.js.map +1 -0
- package/dist/core/state.d.ts +88 -0
- package/dist/core/state.d.ts.map +1 -0
- package/dist/core/state.js +69 -0
- package/dist/core/state.js.map +1 -0
- package/dist/definition.d.ts +61 -0
- package/dist/definition.d.ts.map +1 -0
- package/dist/definition.js +63 -0
- package/dist/definition.js.map +1 -0
- package/dist/headless.d.ts +26 -0
- package/dist/headless.d.ts.map +1 -0
- package/dist/headless.js +35 -0
- package/dist/headless.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin.d.ts +136 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +2 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugins/index.d.ts +3 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +3 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/local.d.ts +7 -0
- package/dist/plugins/local.d.ts.map +1 -0
- package/dist/plugins/local.js +26 -0
- package/dist/plugins/local.js.map +1 -0
- package/dist/plugins/virtual.d.ts +19 -0
- package/dist/plugins/virtual.d.ts.map +1 -0
- package/dist/plugins/virtual.js +42 -0
- package/dist/plugins/virtual.js.map +1 -0
- package/dist/store.d.ts +41 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +57 -0
- package/dist/store.js.map +1 -0
- package/dist/ui/Griddle.d.ts +198 -0
- package/dist/ui/Griddle.d.ts.map +1 -0
- package/dist/ui/Griddle.js +66 -0
- package/dist/ui/Griddle.js.map +1 -0
- package/dist/ui/components.d.ts +4 -0
- package/dist/ui/components.d.ts.map +1 -0
- package/dist/ui/components.js +69 -0
- package/dist/ui/components.js.map +1 -0
- package/package.json +56 -4
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import * as A from "./actions.js";
|
|
2
|
+
import { MISSING_DATA } from "./state.js";
|
|
3
|
+
import { clampPage, windowRange } from "./math.js";
|
|
4
|
+
const NO_SORT_METHODS = Object.freeze({});
|
|
5
|
+
const sel = (f) => f;
|
|
6
|
+
/**
|
|
7
|
+
* The headless base layer. Like Griddle v1 without LocalPlugin, it is a pass-through:
|
|
8
|
+
* `data` is treated as the already-sorted, already-filtered page. Add `LocalPlugin`
|
|
9
|
+
* to compute those client-side.
|
|
10
|
+
*/
|
|
11
|
+
export const CorePlugin = {
|
|
12
|
+
name: "core",
|
|
13
|
+
events: A.coreActions,
|
|
14
|
+
selectors: {
|
|
15
|
+
data: sel(({ data }) => data),
|
|
16
|
+
loading: sel(({ data }) => data === MISSING_DATA),
|
|
17
|
+
sortMethods: sel(() => NO_SORT_METHODS),
|
|
18
|
+
rowKeyOf: sel(({ state }) => {
|
|
19
|
+
const key = state.rowKey;
|
|
20
|
+
if (key === "")
|
|
21
|
+
return (row, index) => String(row["id"] ?? row["griddleKey"] ?? index);
|
|
22
|
+
return (row) => {
|
|
23
|
+
if (!(key in row))
|
|
24
|
+
throw new Error(`Griddle: rowKey property '${key}' does not exist in row data`);
|
|
25
|
+
return String(row[key]);
|
|
26
|
+
};
|
|
27
|
+
}),
|
|
28
|
+
columnIds: sel(({ state }, s) => {
|
|
29
|
+
if (state.columns.length > 0)
|
|
30
|
+
return state.columns.map((c) => c.id);
|
|
31
|
+
const first = s.data[0];
|
|
32
|
+
return first ? Object.keys(first) : [];
|
|
33
|
+
}),
|
|
34
|
+
columns: sel(({ state }, s) => {
|
|
35
|
+
const props = new Map(state.columns.map((c) => [c.id, c]));
|
|
36
|
+
return s.columnIds
|
|
37
|
+
.map((id, i) => ({ ...props.get(id), id, order: props.get(id)?.order ?? i }))
|
|
38
|
+
.filter((c) => c.visible !== false)
|
|
39
|
+
.sort((a, b) => a.order - b.order)
|
|
40
|
+
.map((c) => ({
|
|
41
|
+
...c,
|
|
42
|
+
title: c.title ?? c.id,
|
|
43
|
+
sortDirection: state.sort.find((x) => x.column === c.id)?.direction ?? null
|
|
44
|
+
}));
|
|
45
|
+
}),
|
|
46
|
+
filteredData: sel((_c, s) => s.data),
|
|
47
|
+
sortedData: sel((_c, s) => s.filteredData),
|
|
48
|
+
total: sel((_c, s) => s.sortedData.length),
|
|
49
|
+
maxPage: sel(() => 1),
|
|
50
|
+
pageData: sel((_c, s) => s.sortedData),
|
|
51
|
+
window: sel(({ state }, s) => state.rowHeight > 0 && state.viewportHeight > 0
|
|
52
|
+
? windowRange({
|
|
53
|
+
total: s.pageData.length,
|
|
54
|
+
scrollTop: state.scrollTop,
|
|
55
|
+
viewportHeight: state.viewportHeight,
|
|
56
|
+
rowHeight: state.rowHeight,
|
|
57
|
+
overscan: state.overscan
|
|
58
|
+
})
|
|
59
|
+
: null),
|
|
60
|
+
visibleRows: sel((_c, s) => {
|
|
61
|
+
const { start, end } = s.window ?? { start: 0, end: s.pageData.length };
|
|
62
|
+
return s.pageData.slice(start, end).map((data, i) => ({ key: s.rowKeyOf(data, start + i), index: start + i, data }));
|
|
63
|
+
}),
|
|
64
|
+
pagination: sel(({ state }, s) => {
|
|
65
|
+
const page = clampPage(state.page, s.maxPage);
|
|
66
|
+
return {
|
|
67
|
+
page,
|
|
68
|
+
pageSize: state.pageSize,
|
|
69
|
+
maxPage: s.maxPage,
|
|
70
|
+
total: s.total,
|
|
71
|
+
hasNext: page < s.maxPage,
|
|
72
|
+
hasPrevious: page > 1
|
|
73
|
+
};
|
|
74
|
+
}),
|
|
75
|
+
view: sel(({ state }, s) => ({
|
|
76
|
+
rows: s.visibleRows,
|
|
77
|
+
columns: s.columns,
|
|
78
|
+
pagination: s.pagination,
|
|
79
|
+
window: s.window,
|
|
80
|
+
filter: state.filter,
|
|
81
|
+
settingsOpen: state.settingsOpen,
|
|
82
|
+
loading: s.loading,
|
|
83
|
+
enableSettings: state.enableSettings,
|
|
84
|
+
text: state.text,
|
|
85
|
+
settings: state.settings,
|
|
86
|
+
state
|
|
87
|
+
}))
|
|
88
|
+
},
|
|
89
|
+
selectorDeps: {
|
|
90
|
+
data: ({ data }) => [data],
|
|
91
|
+
loading: ({ data }) => [data],
|
|
92
|
+
sortMethods: () => [],
|
|
93
|
+
rowKeyOf: ({ state }) => [state.rowKey],
|
|
94
|
+
columnIds: ({ state }, s) => [state.columns, s.data],
|
|
95
|
+
columns: ({ state }, s) => [s.columnIds, state.columns, state.sort],
|
|
96
|
+
filteredData: (_c, s) => [s.data],
|
|
97
|
+
sortedData: (_c, s) => [s.filteredData],
|
|
98
|
+
total: (_c, s) => [s.sortedData],
|
|
99
|
+
maxPage: () => [],
|
|
100
|
+
pageData: (_c, s) => [s.sortedData],
|
|
101
|
+
window: ({ state }, s) => [state.rowHeight, state.viewportHeight, state.scrollTop, state.overscan, s.pageData.length],
|
|
102
|
+
visibleRows: (_c, s) => [s.pageData, s.window, s.rowKeyOf],
|
|
103
|
+
pagination: ({ state }, s) => [state.page, state.pageSize, s.maxPage, s.total]
|
|
104
|
+
},
|
|
105
|
+
reducers: {
|
|
106
|
+
[A.SET_FILTER]: (state, { filter }) => ({ ...state, filter: String(filter ?? ""), page: 1, scrollTop: 0 }),
|
|
107
|
+
[A.SET_PAGE]: (state, { page }, { sel }) => ({ ...state, page: clampPage(Number(page), sel.maxPage), scrollTop: 0 }),
|
|
108
|
+
[A.NEXT_PAGE]: (state, _p, { sel }) => ({ ...state, page: clampPage(state.page + 1, sel.maxPage), scrollTop: 0 }),
|
|
109
|
+
[A.PREVIOUS_PAGE]: (state, _p, { sel }) => ({ ...state, page: clampPage(state.page - 1, sel.maxPage), scrollTop: 0 }),
|
|
110
|
+
[A.SET_PAGE_SIZE]: (state, { pageSize }) => ({ ...state, pageSize: Math.max(1, Math.trunc(Number(pageSize))), page: 1 }),
|
|
111
|
+
[A.TOGGLE_SORT]: (state, { column }) => {
|
|
112
|
+
const current = state.sort.find((s) => s.column === column)?.direction;
|
|
113
|
+
const next = current === undefined
|
|
114
|
+
? [{ column, direction: "asc" }]
|
|
115
|
+
: current === "asc"
|
|
116
|
+
? [{ column, direction: "desc" }]
|
|
117
|
+
: [];
|
|
118
|
+
return { ...state, sort: next };
|
|
119
|
+
},
|
|
120
|
+
[A.SET_SORT]: (state, { sort }) => ({ ...state, sort }),
|
|
121
|
+
[A.SCROLLED]: (state, { top }) => ({ ...state, scrollTop: Math.max(0, Number(top) || 0) }),
|
|
122
|
+
[A.SET_VIEWPORT]: (state, { height }) => ({ ...state, viewportHeight: Math.max(0, Number(height) || 0) }),
|
|
123
|
+
[A.TOGGLE_COLUMN]: (state, { id }, { sel }) => {
|
|
124
|
+
const base = state.columns.length > 0 ? state.columns : sel.columnIds.map((c) => ({ id: c }));
|
|
125
|
+
return { ...state, columns: base.map((c) => (c.id === id ? { ...c, visible: c.visible === false } : c)) };
|
|
126
|
+
},
|
|
127
|
+
[A.TOGGLE_SETTINGS]: (state) => ({ ...state, settingsOpen: !state.settingsOpen }),
|
|
128
|
+
[A.SET_SETTING]: (state, { key, value }) => ({ ...state, settings: { ...state.settings, [key]: value } })
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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F,CAAC,CAAC,CAAC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC;KAC1G;CACF,CAAA"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export declare const SortDirection: Schema.Literals<readonly ["asc", "desc"]>;
|
|
3
|
+
export declare const SortSpec: Schema.Struct<{
|
|
4
|
+
readonly column: Schema.String;
|
|
5
|
+
readonly direction: Schema.Literals<readonly ["asc", "desc"]>;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const ColumnProperties: Schema.Struct<{
|
|
8
|
+
readonly id: Schema.String;
|
|
9
|
+
readonly title: Schema.optional<Schema.String>;
|
|
10
|
+
readonly order: Schema.optional<Schema.Number>;
|
|
11
|
+
readonly visible: Schema.optional<Schema.Boolean>;
|
|
12
|
+
readonly sortable: Schema.optional<Schema.Boolean>;
|
|
13
|
+
readonly filterable: Schema.optional<Schema.Boolean>;
|
|
14
|
+
}>;
|
|
15
|
+
export type ColumnProperties = typeof ColumnProperties.Type;
|
|
16
|
+
export declare const RowSchema: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
17
|
+
export declare const Rows: Schema.$Array<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
18
|
+
/** Stand-in for data that has not arrived (`data` null or undefined). The grid shows its Loading component. */
|
|
19
|
+
export declare const MISSING_DATA: ReadonlyArray<Record<string, unknown>>;
|
|
20
|
+
/** Everything the grid remembers between renders. Plain, serializable data. */
|
|
21
|
+
export declare const GriddleState: Schema.Struct<{
|
|
22
|
+
readonly filter: Schema.String;
|
|
23
|
+
readonly sort: Schema.$Array<Schema.Struct<{
|
|
24
|
+
readonly column: Schema.String;
|
|
25
|
+
readonly direction: Schema.Literals<readonly ["asc", "desc"]>;
|
|
26
|
+
}>>;
|
|
27
|
+
readonly page: Schema.Number;
|
|
28
|
+
readonly pageSize: Schema.Number;
|
|
29
|
+
readonly columns: Schema.$Array<Schema.Struct<{
|
|
30
|
+
readonly id: Schema.String;
|
|
31
|
+
readonly title: Schema.optional<Schema.String>;
|
|
32
|
+
readonly order: Schema.optional<Schema.Number>;
|
|
33
|
+
readonly visible: Schema.optional<Schema.Boolean>;
|
|
34
|
+
readonly sortable: Schema.optional<Schema.Boolean>;
|
|
35
|
+
readonly filterable: Schema.optional<Schema.Boolean>;
|
|
36
|
+
}>>;
|
|
37
|
+
readonly scrollTop: Schema.Number;
|
|
38
|
+
readonly viewportHeight: Schema.Number;
|
|
39
|
+
readonly rowHeight: Schema.Number;
|
|
40
|
+
readonly overscan: Schema.Number;
|
|
41
|
+
readonly settingsOpen: Schema.Boolean;
|
|
42
|
+
/** Property that identifies a row (v1 `RowDefinition rowKey`). Empty: `id`, then `griddleKey`, then the index. */
|
|
43
|
+
readonly rowKey: Schema.String;
|
|
44
|
+
/** Show the settings toggle and panel (v1 `enableSettings`). */
|
|
45
|
+
readonly enableSettings: Schema.Boolean;
|
|
46
|
+
/** Text overrides (v1 `textProperties`): settingsToggle, filterPlaceholder, next, previous, noResults, loading. */
|
|
47
|
+
readonly text: Schema.$Record<Schema.String, Schema.String>;
|
|
48
|
+
/** Plugin-owned state, keyed by whatever the plugin picks (v1's `positionSettings`). */
|
|
49
|
+
readonly settings: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
50
|
+
}>;
|
|
51
|
+
export type GriddleState = typeof GriddleState.Type;
|
|
52
|
+
/** What a caller may set up front. Every field is optional. */
|
|
53
|
+
export declare const GriddleConfig: Schema.Struct<{
|
|
54
|
+
readonly filter: Schema.optional<Schema.String>;
|
|
55
|
+
readonly sort: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
56
|
+
readonly column: Schema.String;
|
|
57
|
+
readonly direction: Schema.Literals<readonly ["asc", "desc"]>;
|
|
58
|
+
}>>>;
|
|
59
|
+
readonly page: Schema.optional<Schema.Number>;
|
|
60
|
+
readonly pageSize: Schema.optional<Schema.Number>;
|
|
61
|
+
readonly columns: Schema.optional<Schema.$Array<Schema.Struct<{
|
|
62
|
+
readonly id: Schema.String;
|
|
63
|
+
readonly title: Schema.optional<Schema.String>;
|
|
64
|
+
readonly order: Schema.optional<Schema.Number>;
|
|
65
|
+
readonly visible: Schema.optional<Schema.Boolean>;
|
|
66
|
+
readonly sortable: Schema.optional<Schema.Boolean>;
|
|
67
|
+
readonly filterable: Schema.optional<Schema.Boolean>;
|
|
68
|
+
}>>>;
|
|
69
|
+
readonly rowHeight: Schema.optional<Schema.Number>;
|
|
70
|
+
readonly viewportHeight: Schema.optional<Schema.Number>;
|
|
71
|
+
readonly overscan: Schema.optional<Schema.Number>;
|
|
72
|
+
readonly rowKey: Schema.optional<Schema.String>;
|
|
73
|
+
readonly enableSettings: Schema.optional<Schema.Boolean>;
|
|
74
|
+
readonly text: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
|
|
75
|
+
readonly settings: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
76
|
+
}>;
|
|
77
|
+
export type GriddleConfig = typeof GriddleConfig.Type;
|
|
78
|
+
export declare const defaultState: GriddleState;
|
|
79
|
+
/** A Redux-ish action. Plugins add their own `type`s. */
|
|
80
|
+
export interface Action {
|
|
81
|
+
readonly type: string;
|
|
82
|
+
readonly payload?: unknown;
|
|
83
|
+
}
|
|
84
|
+
export declare const ActionSchema: Schema.Struct<{
|
|
85
|
+
readonly type: Schema.String;
|
|
86
|
+
readonly payload: Schema.optional<Schema.Unknown>;
|
|
87
|
+
}>;
|
|
88
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/core/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,eAAO,MAAM,aAAa,2CAAmC,CAAA;AAC7D,eAAO,MAAM,QAAQ;;;EAAqE,CAAA;AAE1F,eAAO,MAAM,gBAAgB;;;;;;;EAO3B,CAAA;AACF,MAAM,MAAM,gBAAgB,GAAG,OAAO,gBAAgB,CAAC,IAAI,CAAA;AAE3D,eAAO,MAAM,SAAS,+CAA+C,CAAA;AACrE,eAAO,MAAM,IAAI,8DAA0B,CAAA;AAE3C,+GAA+G;AAC/G,eAAO,MAAM,YAAY,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAqB,CAAA;AAErF,+EAA+E;AAC/E,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;IAWvB,kHAAkH;;IAElH,gEAAgE;;IAEhE,mHAAmH;;IAEnH,wFAAwF;;EAExF,CAAA;AACF,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAA;AAEnD,+DAA+D;AAC/D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;EAaxB,CAAA;AACF,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAC,IAAI,CAAA;AAErD,eAAO,MAAM,YAAY,EAAE,YAe1B,CAAA;AAED,yDAAyD;AACzD,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAC3B;AACD,eAAO,MAAM,YAAY;;;EAAmF,CAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export const SortDirection = Schema.Literals(["asc", "desc"]);
|
|
3
|
+
export const SortSpec = Schema.Struct({ column: Schema.String, direction: SortDirection });
|
|
4
|
+
export const ColumnProperties = Schema.Struct({
|
|
5
|
+
id: Schema.String,
|
|
6
|
+
title: Schema.optional(Schema.String),
|
|
7
|
+
order: Schema.optional(Schema.Number),
|
|
8
|
+
visible: Schema.optional(Schema.Boolean),
|
|
9
|
+
sortable: Schema.optional(Schema.Boolean),
|
|
10
|
+
filterable: Schema.optional(Schema.Boolean)
|
|
11
|
+
});
|
|
12
|
+
export const RowSchema = Schema.Record(Schema.String, Schema.Unknown);
|
|
13
|
+
export const Rows = Schema.Array(RowSchema);
|
|
14
|
+
/** Stand-in for data that has not arrived (`data` null or undefined). The grid shows its Loading component. */
|
|
15
|
+
export const MISSING_DATA = Object.freeze([]);
|
|
16
|
+
/** Everything the grid remembers between renders. Plain, serializable data. */
|
|
17
|
+
export const GriddleState = Schema.Struct({
|
|
18
|
+
filter: Schema.String,
|
|
19
|
+
sort: Schema.Array(SortSpec),
|
|
20
|
+
page: Schema.Number,
|
|
21
|
+
pageSize: Schema.Number,
|
|
22
|
+
columns: Schema.Array(ColumnProperties),
|
|
23
|
+
scrollTop: Schema.Number,
|
|
24
|
+
viewportHeight: Schema.Number,
|
|
25
|
+
rowHeight: Schema.Number,
|
|
26
|
+
overscan: Schema.Number,
|
|
27
|
+
settingsOpen: Schema.Boolean,
|
|
28
|
+
/** Property that identifies a row (v1 `RowDefinition rowKey`). Empty: `id`, then `griddleKey`, then the index. */
|
|
29
|
+
rowKey: Schema.String,
|
|
30
|
+
/** Show the settings toggle and panel (v1 `enableSettings`). */
|
|
31
|
+
enableSettings: Schema.Boolean,
|
|
32
|
+
/** Text overrides (v1 `textProperties`): settingsToggle, filterPlaceholder, next, previous, noResults, loading. */
|
|
33
|
+
text: Schema.Record(Schema.String, Schema.String),
|
|
34
|
+
/** Plugin-owned state, keyed by whatever the plugin picks (v1's `positionSettings`). */
|
|
35
|
+
settings: Schema.Record(Schema.String, Schema.Unknown)
|
|
36
|
+
});
|
|
37
|
+
/** What a caller may set up front. Every field is optional. */
|
|
38
|
+
export const GriddleConfig = Schema.Struct({
|
|
39
|
+
filter: Schema.optional(Schema.String),
|
|
40
|
+
sort: Schema.optional(Schema.Array(SortSpec)),
|
|
41
|
+
page: Schema.optional(Schema.Number),
|
|
42
|
+
pageSize: Schema.optional(Schema.Number),
|
|
43
|
+
columns: Schema.optional(Schema.Array(ColumnProperties)),
|
|
44
|
+
rowHeight: Schema.optional(Schema.Number),
|
|
45
|
+
viewportHeight: Schema.optional(Schema.Number),
|
|
46
|
+
overscan: Schema.optional(Schema.Number),
|
|
47
|
+
rowKey: Schema.optional(Schema.String),
|
|
48
|
+
enableSettings: Schema.optional(Schema.Boolean),
|
|
49
|
+
text: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
50
|
+
settings: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))
|
|
51
|
+
});
|
|
52
|
+
export const defaultState = {
|
|
53
|
+
filter: "",
|
|
54
|
+
sort: [],
|
|
55
|
+
page: 1,
|
|
56
|
+
pageSize: 10,
|
|
57
|
+
columns: [],
|
|
58
|
+
scrollTop: 0,
|
|
59
|
+
viewportHeight: 0,
|
|
60
|
+
rowHeight: 0,
|
|
61
|
+
overscan: 3,
|
|
62
|
+
settingsOpen: false,
|
|
63
|
+
rowKey: "",
|
|
64
|
+
enableSettings: true,
|
|
65
|
+
text: {},
|
|
66
|
+
settings: {}
|
|
67
|
+
};
|
|
68
|
+
export const ActionSchema = Schema.Struct({ type: Schema.String, payload: Schema.optional(Schema.Unknown) });
|
|
69
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../src/core/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAE/B,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAA;AAC7D,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CAAA;AAE1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C,CAAC;IAClE,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;CACxE,CAAC,CAAA;AAGF,MAAM,CAAC,MAAM,YAAY,GAAiB;IACxC,MAAM,EAAE,EAAE;IACV,IAAI,EAAE,EAAE;IACR,IAAI,EAAE,CAAC;IACP,QAAQ,EAAE,EAAE;IACZ,OAAO,EAAE,EAAE;IACX,SAAS,EAAE,CAAC;IACZ,cAAc,EAAE,CAAC;IACjB,SAAS,EAAE,CAAC;IACZ,QAAQ,EAAE,CAAC;IACX,YAAY,EAAE,KAAK;IACnB,MAAM,EAAE,EAAE;IACV,cAAc,EAAE,IAAI;IACpB,IAAI,EAAE,EAAE;IACR,QAAQ,EAAE,EAAE;CACb,CAAA;AAOD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Row } from "./core/math.ts";
|
|
2
|
+
import type { ColumnProperties } from "./core/state.ts";
|
|
3
|
+
import type { CompareFn, GriddlePlugin } from "./plugin.ts";
|
|
4
|
+
/** What a cell renderer receives (v1 `customComponent` props, minus Redux). */
|
|
5
|
+
export interface CellProps {
|
|
6
|
+
readonly value: unknown;
|
|
7
|
+
readonly rowData: Row;
|
|
8
|
+
/** Index in the original data. */
|
|
9
|
+
readonly index: number;
|
|
10
|
+
readonly column: {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly title: string;
|
|
13
|
+
readonly extraData: unknown;
|
|
14
|
+
};
|
|
15
|
+
readonly extraData: unknown;
|
|
16
|
+
}
|
|
17
|
+
/** Renders the contents of a `<td>`. Return a string, a builder, or an array of them. */
|
|
18
|
+
export type CellRenderer = (h: any, props: CellProps) => unknown;
|
|
19
|
+
/** Renders the contents of a `<th>`. */
|
|
20
|
+
export type HeadingRenderer = (h: any, props: {
|
|
21
|
+
readonly column: CellProps["column"];
|
|
22
|
+
readonly extraData: unknown;
|
|
23
|
+
}) => unknown;
|
|
24
|
+
type ClassName<P> = string | ((props: P) => string | undefined);
|
|
25
|
+
/** v1's `<ColumnDefinition />`, as a plain object. Pass a list of them in `RowDefinition({ columns })`. */
|
|
26
|
+
export interface ColumnDefinitionInput extends ColumnProperties {
|
|
27
|
+
/** Class added to every cell in this column. A function receives the cell's props. */
|
|
28
|
+
readonly cssClassName?: ClassName<CellProps>;
|
|
29
|
+
/** Class added to the column heading. */
|
|
30
|
+
readonly headerCssClassName?: ClassName<{
|
|
31
|
+
readonly column: CellProps["column"];
|
|
32
|
+
}>;
|
|
33
|
+
/** Replaces the cell contents. */
|
|
34
|
+
readonly customComponent?: CellRenderer;
|
|
35
|
+
/** Replaces the heading contents (instead of the sort button; wire sorting yourself if you want it). */
|
|
36
|
+
readonly customHeadingComponent?: HeadingRenderer;
|
|
37
|
+
/** Ascending comparator for this column. Used by LocalPlugin when sorting by it. */
|
|
38
|
+
readonly sortMethod?: CompareFn;
|
|
39
|
+
/** Anything you want handed back to `customComponent` and class functions. */
|
|
40
|
+
readonly extraData?: unknown;
|
|
41
|
+
}
|
|
42
|
+
/** v1's `<RowDefinition />`. */
|
|
43
|
+
export interface RowDefinitionInput {
|
|
44
|
+
/** Property that uniquely identifies a row. Throws on rows that lack it. */
|
|
45
|
+
readonly rowKey?: string;
|
|
46
|
+
/** Class added to every row. A function receives the row data and index. */
|
|
47
|
+
readonly cssClassName?: string | ((props: {
|
|
48
|
+
readonly rowData: Row;
|
|
49
|
+
readonly index: number;
|
|
50
|
+
}) => string | undefined);
|
|
51
|
+
readonly columns?: ReadonlyArray<ColumnDefinitionInput>;
|
|
52
|
+
}
|
|
53
|
+
export declare const ColumnDefinition: (definition: ColumnDefinitionInput) => ColumnDefinitionInput;
|
|
54
|
+
export declare const RowDefinition: (definition: RowDefinitionInput) => RowDefinitionInput;
|
|
55
|
+
/**
|
|
56
|
+
* Port of v1's RowDefinition/ColumnDefinition. The serializable parts (id, title, order, visible,
|
|
57
|
+
* sortable, filterable) become initial `columns` state; the functions stay in this plugin.
|
|
58
|
+
*/
|
|
59
|
+
export declare const DefinitionPlugin: (definition: RowDefinitionInput) => GriddlePlugin;
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=definition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.d.ts","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAiB,aAAa,EAAE,MAAM,aAAa,CAAA;AAE1E,+EAA+E;AAC/E,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAA;IACrB,kCAAkC;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAA;IAC7F,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAA;CAC5B;AAED,yFAAyF;AACzF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,KAAK,OAAO,CAAA;AAChE,wCAAwC;AACxC,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE;IAAE,QAAQ,CAA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AG,qBAAmC,CAAA;AACxG,eAAO,MAAM,aAAa,GAAI,YAAY,kBAAkB,KAAG,kBAAgC,CAAA;AAK/F;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,YAAY,kBAAkB,KAAG,aAgDjE,CAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const ColumnDefinition = (definition) => definition;
|
|
2
|
+
export const RowDefinition = (definition) => definition;
|
|
3
|
+
const resolveClass = (c, props) => typeof c === "function" ? c(props) : c;
|
|
4
|
+
/**
|
|
5
|
+
* Port of v1's RowDefinition/ColumnDefinition. The serializable parts (id, title, order, visible,
|
|
6
|
+
* sortable, filterable) become initial `columns` state; the functions stay in this plugin.
|
|
7
|
+
*/
|
|
8
|
+
export const DefinitionPlugin = (definition) => {
|
|
9
|
+
const defs = definition.columns ?? [];
|
|
10
|
+
const byId = new Map(defs.map((d) => [d.id, d]));
|
|
11
|
+
const sortMethods = Object.fromEntries(defs.filter((d) => d.sortMethod).map((d) => [d.id, d.sortMethod]));
|
|
12
|
+
const columns = defs.map(({ id, title, order, visible, sortable, filterable }) => {
|
|
13
|
+
const c = { id };
|
|
14
|
+
if (title !== undefined)
|
|
15
|
+
c["title"] = title;
|
|
16
|
+
if (order !== undefined)
|
|
17
|
+
c["order"] = order;
|
|
18
|
+
if (visible !== undefined)
|
|
19
|
+
c["visible"] = visible;
|
|
20
|
+
if (sortable !== undefined)
|
|
21
|
+
c["sortable"] = sortable;
|
|
22
|
+
if (filterable !== undefined)
|
|
23
|
+
c["filterable"] = filterable;
|
|
24
|
+
return c;
|
|
25
|
+
});
|
|
26
|
+
const withClass = (ctx, only, extra) => extra
|
|
27
|
+
? { ...ctx, cls: (name, ...rest) => ctx.cls(name, ...rest, name === only ? extra : undefined) }
|
|
28
|
+
: ctx;
|
|
29
|
+
return {
|
|
30
|
+
name: "definition",
|
|
31
|
+
initialState: {
|
|
32
|
+
...(columns.length > 0 ? { columns } : {}),
|
|
33
|
+
...(definition.rowKey ? { rowKey: definition.rowKey } : {})
|
|
34
|
+
},
|
|
35
|
+
selectors: { sortMethods: () => sortMethods },
|
|
36
|
+
selectorDeps: { sortMethods: () => [] },
|
|
37
|
+
wrapComponents: {
|
|
38
|
+
Row: (base) => (h, ctx) => base(h, withClass(ctx, "Row", resolveClass(definition.cssClassName, { rowData: ctx["row"].data, index: ctx["row"].index }))),
|
|
39
|
+
Cell: (base) => (h, ctx) => {
|
|
40
|
+
const def = byId.get(ctx["column"].id);
|
|
41
|
+
if (!def)
|
|
42
|
+
return base(h, ctx);
|
|
43
|
+
const column = { id: ctx["column"].id, title: ctx["column"].title, extraData: def.extraData };
|
|
44
|
+
const props = { value: ctx["value"], rowData: ctx["row"].data, index: ctx["row"].index, column, extraData: def.extraData };
|
|
45
|
+
const inner = withClass({ ...ctx, column: { ...ctx["column"], extraData: def.extraData } }, "Cell", resolveClass(def.cssClassName, props));
|
|
46
|
+
if (!def.customComponent)
|
|
47
|
+
return base(h, inner);
|
|
48
|
+
return h.td.class(inner.cls("Cell")).attr("data-column", column.id).children(def.customComponent(h, props));
|
|
49
|
+
},
|
|
50
|
+
HeaderCell: (base) => (h, ctx) => {
|
|
51
|
+
const def = byId.get(ctx["column"].id);
|
|
52
|
+
if (!def)
|
|
53
|
+
return base(h, ctx);
|
|
54
|
+
const column = { id: ctx["column"].id, title: ctx["column"].title, extraData: def.extraData };
|
|
55
|
+
const inner = withClass({ ...ctx, column: { ...ctx["column"], extraData: def.extraData } }, "HeaderCell", resolveClass(def.headerCssClassName, { column }));
|
|
56
|
+
if (!def.customHeadingComponent)
|
|
57
|
+
return base(h, inner);
|
|
58
|
+
return h.th.class(inner.cls("HeaderCell")).attr("data-column", column.id).children(def.customHeadingComponent(h, { column, extraData: def.extraData }));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definition.js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AC,CAAC,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;YACzJ,CAAC;SACF;KACF,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Stream, SubscriptionRef } from "effect";
|
|
2
|
+
import type { HeadlessOptions } from "./store.ts";
|
|
3
|
+
import type { Row } from "./core/math.ts";
|
|
4
|
+
import type { Action, GriddleState } from "./core/state.ts";
|
|
5
|
+
import type { GriddleView } from "./plugin.ts";
|
|
6
|
+
export type { HeadlessOptions } from "./store.ts";
|
|
7
|
+
export { createGriddle } from "./store.ts";
|
|
8
|
+
export interface GriddleHandle {
|
|
9
|
+
readonly state: SubscriptionRef.SubscriptionRef<GriddleState>;
|
|
10
|
+
/** Current plain-data view. */
|
|
11
|
+
readonly view: Effect.Effect<GriddleView>;
|
|
12
|
+
/** Stream of views: the current one, then one per state or data change. */
|
|
13
|
+
readonly changes: Stream.Stream<GriddleView>;
|
|
14
|
+
readonly dispatch: (action: Action) => Effect.Effect<void>;
|
|
15
|
+
readonly setData: (data: ReadonlyArray<Row> | null | undefined) => Effect.Effect<void>;
|
|
16
|
+
/** Core actions and plugin events as Effects: `yield* g.actions.setPage(2)`. */
|
|
17
|
+
readonly actions: Readonly<Record<string, (...args: any[]) => Effect.Effect<void>>>;
|
|
18
|
+
}
|
|
19
|
+
/** Effect API. Same pipeline as `createGriddle`, with state in a `SubscriptionRef`. */
|
|
20
|
+
export declare const make: (options: HeadlessOptions) => Effect.Effect<GriddleHandle>;
|
|
21
|
+
declare const GriddleService_base: Context.ServiceClass<GriddleService, "griddle/Griddle", GriddleHandle>;
|
|
22
|
+
/** The handle as a service, for apps that wire things with Layers. */
|
|
23
|
+
export declare class GriddleService extends GriddleService_base {
|
|
24
|
+
static layer: (options: HeadlessOptions) => Layer.Layer<GriddleService, never, never>;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingUR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,CAAC,CAAC,CAAC,CAAA;CACpF;AAED,uFAAuF;AACvF,eAAO,MAAM,IAAI,GAAI,SAAS,eAAe,KAAG,MAAM,CAAC,MAAM,CAAC,aAAa,CAgCvE,CAAA;;AAEJ,sEAAsE;AACtE,qBAAa,cAAe,SAAQ,mBAAmE;IACrG,MAAM,CAAC,KAAK,GAAI,SAAS,eAAe,+CAAgD;CACzF"}
|
package/dist/headless.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Ref, Stream, SubscriptionRef } from "effect";
|
|
2
|
+
import { composeFor, configPatch } from "./store.js";
|
|
3
|
+
import { createSelectorMemo, initialStateFor, notifyEvents, reduce, resolveView } from "./compose.js";
|
|
4
|
+
import { MISSING_DATA } from "./core/state.js";
|
|
5
|
+
export { createGriddle } from "./store.js";
|
|
6
|
+
/** Effect API. Same pipeline as `createGriddle`, with state in a `SubscriptionRef`. */
|
|
7
|
+
export const make = (options) => Effect.gen(function* () {
|
|
8
|
+
const composed = composeFor(options);
|
|
9
|
+
const memo = createSelectorMemo();
|
|
10
|
+
const data = yield* Ref.make(options.data ?? MISSING_DATA);
|
|
11
|
+
const state = yield* SubscriptionRef.make(initialStateFor(composed, configPatch(options)));
|
|
12
|
+
const viewOf = Effect.all([Ref.get(data), SubscriptionRef.get(state)]).pipe(Effect.map(([d, s]) => resolveView(composed, d, s, memo)));
|
|
13
|
+
const dispatch = (action) => Effect.gen(function* () {
|
|
14
|
+
const d = yield* Ref.get(data);
|
|
15
|
+
yield* SubscriptionRef.update(state, (s) => {
|
|
16
|
+
const next = reduce(composed, s, action, d, memo);
|
|
17
|
+
notifyEvents(options.events, action, next);
|
|
18
|
+
return next;
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
const setData = (d) => Ref.set(data, d ?? MISSING_DATA).pipe(Effect.andThen(SubscriptionRef.update(state, (s) => ({ ...s }))));
|
|
22
|
+
return {
|
|
23
|
+
state,
|
|
24
|
+
view: viewOf,
|
|
25
|
+
changes: SubscriptionRef.changes(state).pipe(Stream.mapEffect(() => viewOf)),
|
|
26
|
+
dispatch,
|
|
27
|
+
setData,
|
|
28
|
+
actions: Object.fromEntries(Object.entries(composed.events).map(([name, create]) => [name, (...args) => dispatch(create(...args))]))
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
/** The handle as a service, for apps that wire things with Layers. */
|
|
32
|
+
export class GriddleService extends Context.Service()("griddle/Griddle") {
|
|
33
|
+
static layer = (options) => Layer.effect(GriddleService, make(options));
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=headless.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headless.js","sourceRoot":"","sources":["../src/headless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AAC7E,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAEpD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAErG,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAK9C,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAc1C,uFAAuF;AACvF,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAAwB,EAAgC,EAAE,CAC7E,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;IACpC,MAAM,IAAI,GAAG,kBAAkB,EAAE,CAAA;IACjC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,CAAqB,OAAO,CAAC,IAAI,IAAI,YAAY,CAAC,CAAA;IAC9E,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,eAAe,CAAC,IAAI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AAM;QACZ,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAC1C,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAC/B;QACD,QAAQ;QACR,OAAO;QACP,OAAO,EAAE,MAAM,CAAC,WAAW,CACzB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,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,CAAC,CAAA;AAEJ,sEAAsE;AACtE,MAAM,OAAO,cAAe,SAAQ,OAAO,CAAC,OAAO,EAAiC,CAAC,iBAAiB,CAAC;IACrG,MAAM,CAAC,KAAK,GAAG,CAAC,OAAwB,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { Griddle, GriddleMessage, GriddleProps, makeGriddle } from "./ui/Griddle.ts";
|
|
2
|
+
export type { GriddleOptions } from "./ui/Griddle.ts";
|
|
3
|
+
export { DefaultComponents } from "./ui/components.ts";
|
|
4
|
+
export { composePlugins, createSelectorMemo, GriddlePlugins, initialStateFor, memoFor, reduce, resolveSelectors, resolveView } from "./compose.ts";
|
|
5
|
+
export type { SelectorMemo } from "./compose.ts";
|
|
6
|
+
export { CorePlugin } from "./core/plugin.ts";
|
|
7
|
+
export * as math from "./core/math.ts";
|
|
8
|
+
export * from "./core/actions.ts";
|
|
9
|
+
export * from "./core/state.ts";
|
|
10
|
+
export type * from "./plugin.ts";
|
|
11
|
+
export { LocalPlugin, VirtualScrollConfig, VirtualScrollPlugin } from "./plugins/index.ts";
|
|
12
|
+
export { createGriddle, composeFor } from "./store.ts";
|
|
13
|
+
export type { Griddle as GriddleStore, HeadlessOptions } from "./store.ts";
|
|
14
|
+
export { GriddleService, make as makeHeadless } from "./headless.ts";
|
|
15
|
+
export type { GriddleHandle } from "./headless.ts";
|
|
16
|
+
export { ColumnDefinition, DefinitionPlugin, RowDefinition } from "./definition.ts";
|
|
17
|
+
export type { CellProps, CellRenderer, ColumnDefinitionInput, HeadingRenderer, RowDefinitionInput } from "./definition.ts";
|
|
18
|
+
export { notifyEvents } from "./compose.ts";
|
|
19
|
+
export type { GriddleEvents } from "./compose.ts";
|
|
20
|
+
export { MISSING_DATA } from "./core/state.ts";
|
|
21
|
+
export type { CompareFn } from "./plugin.ts";
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AACpF,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,cAAc,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAClJ,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAA;AACtC,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA;AAC/B,mBAAmB,aAAa,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAC1F,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACtD,YAAY,EAAE,OAAO,IAAI,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC1E,OAAO,EAAE,cAAc,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM,eAAe,CAAA;AACpE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AACnF,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,qBAAqB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAC1H,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,YAAY,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { Griddle, GriddleMessage, GriddleProps, makeGriddle } from "./ui/Griddle.js";
|
|
2
|
+
export { DefaultComponents } from "./ui/components.js";
|
|
3
|
+
export { composePlugins, createSelectorMemo, GriddlePlugins, initialStateFor, memoFor, reduce, resolveSelectors, resolveView } from "./compose.js";
|
|
4
|
+
export { CorePlugin } from "./core/plugin.js";
|
|
5
|
+
export * as math from "./core/math.js";
|
|
6
|
+
export * from "./core/actions.js";
|
|
7
|
+
export * from "./core/state.js";
|
|
8
|
+
export { LocalPlugin, VirtualScrollConfig, VirtualScrollPlugin } from "./plugins/index.js";
|
|
9
|
+
export { createGriddle, composeFor } from "./store.js";
|
|
10
|
+
export { GriddleService, make as makeHeadless } from "./headless.js";
|
|
11
|
+
export { ColumnDefinition, DefinitionPlugin, RowDefinition } from "./definition.js";
|
|
12
|
+
export { notifyEvents } from "./compose.js";
|
|
13
|
+
export { MISSING_DATA } from "./core/state.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAEpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,cAAc,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAElJ,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAA;AACtC,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA;AAE/B,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAC1F,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEtD,OAAO,EAAE,cAAc,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM,eAAe,CAAA;AAEpE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEnF,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA"}
|