zod-collection-ui 0.0.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.
- package/LICENSE +21 -0
- package/README.md +383 -0
- package/dist/collection.d.ts +77 -0
- package/dist/collection.js +273 -0
- package/dist/collection.js.map +1 -0
- package/dist/data-provider.d.ts +65 -0
- package/dist/data-provider.js +185 -0
- package/dist/data-provider.js.map +1 -0
- package/dist/generators.d.ts +118 -0
- package/dist/generators.js +239 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/inference.d.ts +39 -0
- package/dist/inference.js +395 -0
- package/dist/inference.js.map +1 -0
- package/dist/prompt.d.ts +29 -0
- package/dist/prompt.js +247 -0
- package/dist/prompt.js.map +1 -0
- package/dist/store.d.ts +105 -0
- package/dist/store.js +171 -0
- package/dist/store.js.map +1 -0
- package/dist/types.d.ts +205 -0
- package/dist/types.js +16 -0
- package/dist/types.js.map +1 -0
- package/package.json +66 -0
package/dist/prompt.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Prompt Generator: Produce machine-readable descriptions of collections.
|
|
3
|
+
*
|
|
4
|
+
* Follows the json-render `generateCatalogPrompt()` pattern:
|
|
5
|
+
* given a collection definition, produce a structured text that an LLM can
|
|
6
|
+
* consume to understand what UI components to generate, what operations
|
|
7
|
+
* are available, and what constraints exist.
|
|
8
|
+
*
|
|
9
|
+
* Use cases:
|
|
10
|
+
* - Feed to an LLM to generate UI specifications
|
|
11
|
+
* - Feed to an agent to understand available CRUD operations
|
|
12
|
+
* - Generate API documentation from schema
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Generate an AI-consumable prompt describing a collection's affordances.
|
|
16
|
+
*
|
|
17
|
+
* The prompt is structured for LLM consumption: it clearly separates
|
|
18
|
+
* data shape, field capabilities, collection operations, and custom actions.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const prompt = toPrompt(projectCollection);
|
|
23
|
+
* // Feed to an LLM:
|
|
24
|
+
* // "Given the following collection definition, generate a React component..."
|
|
25
|
+
* // + prompt
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function toPrompt(collection) {
|
|
29
|
+
const sections = [];
|
|
30
|
+
// Header
|
|
31
|
+
sections.push('# Collection Definition');
|
|
32
|
+
sections.push('');
|
|
33
|
+
// Identity
|
|
34
|
+
sections.push(`- **ID field**: \`${collection.idField}\``);
|
|
35
|
+
sections.push(`- **Label field**: \`${collection.labelField}\``);
|
|
36
|
+
sections.push(`- **Total fields**: ${Object.keys(collection.fieldAffordances).length}`);
|
|
37
|
+
sections.push('');
|
|
38
|
+
// Data Shape
|
|
39
|
+
sections.push('## Data Shape');
|
|
40
|
+
sections.push('');
|
|
41
|
+
sections.push('| Field | Type | Sortable | Filterable | Searchable | Editable | Notes |');
|
|
42
|
+
sections.push('|-------|------|----------|------------|------------|----------|-------|');
|
|
43
|
+
for (const [key, fa] of Object.entries(collection.fieldAffordances)) {
|
|
44
|
+
const notes = buildFieldNotes(key, fa, collection);
|
|
45
|
+
sections.push(`| \`${key}\` | ${fa.zodType} | ${formatBool(fa.sortable)} | ${formatFilter(fa.filterable)} | ${formatBool(fa.searchable)} | ${formatBool(fa.editable)} | ${notes} |`);
|
|
46
|
+
}
|
|
47
|
+
sections.push('');
|
|
48
|
+
// Collection Capabilities
|
|
49
|
+
sections.push('## Collection Capabilities');
|
|
50
|
+
sections.push('');
|
|
51
|
+
const aff = collection.affordances;
|
|
52
|
+
const capabilities = [];
|
|
53
|
+
if (aff.create)
|
|
54
|
+
capabilities.push('Create new items');
|
|
55
|
+
if (aff.read !== false)
|
|
56
|
+
capabilities.push('Read/view items');
|
|
57
|
+
if (aff.update !== false)
|
|
58
|
+
capabilities.push('Update existing items');
|
|
59
|
+
if (aff.delete)
|
|
60
|
+
capabilities.push('Delete items');
|
|
61
|
+
if (aff.bulkDelete)
|
|
62
|
+
capabilities.push('Bulk delete selected items');
|
|
63
|
+
if (aff.bulkEdit)
|
|
64
|
+
capabilities.push('Bulk edit selected items');
|
|
65
|
+
if (aff.search)
|
|
66
|
+
capabilities.push('Full-text search across searchable fields');
|
|
67
|
+
if (aff.pagination)
|
|
68
|
+
capabilities.push(`Pagination (${describePagination(aff.pagination)})`);
|
|
69
|
+
if (aff.multiSort)
|
|
70
|
+
capabilities.push('Multi-column sorting');
|
|
71
|
+
if (aff.filterPanel)
|
|
72
|
+
capabilities.push('Filter panel');
|
|
73
|
+
if (aff.groupBy)
|
|
74
|
+
capabilities.push('Group by field');
|
|
75
|
+
if (aff.export)
|
|
76
|
+
capabilities.push(`Export (${Array.isArray(aff.export) ? aff.export.join(', ') : 'all formats'})`);
|
|
77
|
+
if (aff.selectable)
|
|
78
|
+
capabilities.push(`Row selection (${aff.selectable === true ? 'multi' : aff.selectable})`);
|
|
79
|
+
if (aff.columnVisibility)
|
|
80
|
+
capabilities.push('Toggle column visibility');
|
|
81
|
+
if (aff.columnOrder)
|
|
82
|
+
capabilities.push('Reorder columns');
|
|
83
|
+
if (aff.refresh)
|
|
84
|
+
capabilities.push('Manual refresh');
|
|
85
|
+
for (const cap of capabilities) {
|
|
86
|
+
sections.push(`- ${cap}`);
|
|
87
|
+
}
|
|
88
|
+
sections.push('');
|
|
89
|
+
// Default sort
|
|
90
|
+
if (aff.defaultSort) {
|
|
91
|
+
const ds = aff.defaultSort;
|
|
92
|
+
sections.push(`**Default sort**: \`${ds.field}\` ${ds.direction}`);
|
|
93
|
+
sections.push('');
|
|
94
|
+
}
|
|
95
|
+
// Search fields
|
|
96
|
+
const searchable = collection.getSearchableFields();
|
|
97
|
+
if (searchable.length > 0) {
|
|
98
|
+
sections.push(`**Searchable fields**: ${searchable.map(f => `\`${f}\``).join(', ')}`);
|
|
99
|
+
sections.push('');
|
|
100
|
+
}
|
|
101
|
+
// Filterable fields detail
|
|
102
|
+
const filterable = collection.getFilterableFields();
|
|
103
|
+
if (filterable.length > 0) {
|
|
104
|
+
sections.push('## Filter Configuration');
|
|
105
|
+
sections.push('');
|
|
106
|
+
for (const { key, affordance } of filterable) {
|
|
107
|
+
const filterType = typeof affordance.filterable === 'string' ? affordance.filterable : 'text';
|
|
108
|
+
let detail = `- \`${key}\` (${filterType})`;
|
|
109
|
+
if (filterType === 'select' || filterType === 'multiSelect') {
|
|
110
|
+
// We'd need enum values — check zodType
|
|
111
|
+
const fa = collection.fieldAffordances[key];
|
|
112
|
+
if (fa.zodType === 'enum') {
|
|
113
|
+
detail += ` — enum field`;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (filterType === 'range') {
|
|
117
|
+
detail += ` — numeric/date range`;
|
|
118
|
+
}
|
|
119
|
+
sections.push(detail);
|
|
120
|
+
}
|
|
121
|
+
sections.push('');
|
|
122
|
+
}
|
|
123
|
+
// Custom operations
|
|
124
|
+
if (collection.operations.length > 0) {
|
|
125
|
+
sections.push('## Custom Operations');
|
|
126
|
+
sections.push('');
|
|
127
|
+
sections.push('| Name | Label | Scope | Confirm | Variant |');
|
|
128
|
+
sections.push('|------|-------|-------|---------|---------|');
|
|
129
|
+
for (const op of collection.operations) {
|
|
130
|
+
sections.push(`| \`${op.name}\` | ${op.label} | ${op.scope} | ${op.confirm ? 'yes' : 'no'} | ${op.variant ?? 'default'} |`);
|
|
131
|
+
}
|
|
132
|
+
sections.push('');
|
|
133
|
+
}
|
|
134
|
+
// Views
|
|
135
|
+
if (aff.views && aff.views.length > 1) {
|
|
136
|
+
sections.push(`**Available views**: ${aff.views.join(', ')}`);
|
|
137
|
+
sections.push(`**Default view**: ${aff.defaultView ?? 'table'}`);
|
|
138
|
+
sections.push('');
|
|
139
|
+
}
|
|
140
|
+
// UI Generation hints
|
|
141
|
+
sections.push('## UI Generation Hints');
|
|
142
|
+
sections.push('');
|
|
143
|
+
sections.push('When generating a UI for this collection:');
|
|
144
|
+
const hints = [];
|
|
145
|
+
const visibleFields = collection.getVisibleFields();
|
|
146
|
+
hints.push(`Show these fields in the table: ${visibleFields.map(f => `\`${f}\``).join(', ')}`);
|
|
147
|
+
const groupable = collection.getGroupableFields();
|
|
148
|
+
if (groupable.length > 0) {
|
|
149
|
+
hints.push(`Fields suitable for grouping: ${groupable.map(f => `\`${f.key}\``).join(', ')}`);
|
|
150
|
+
}
|
|
151
|
+
// Fields with badges
|
|
152
|
+
const badgeFields = Object.entries(collection.fieldAffordances)
|
|
153
|
+
.filter(([_, fa]) => fa.badge)
|
|
154
|
+
.map(([key]) => key);
|
|
155
|
+
if (badgeFields.length > 0) {
|
|
156
|
+
hints.push(`Render as badges: ${badgeFields.map(f => `\`${f}\``).join(', ')}`);
|
|
157
|
+
}
|
|
158
|
+
// Inline editable fields
|
|
159
|
+
const inlineEditable = Object.entries(collection.fieldAffordances)
|
|
160
|
+
.filter(([_, fa]) => fa.inlineEditable)
|
|
161
|
+
.map(([key]) => key);
|
|
162
|
+
if (inlineEditable.length > 0) {
|
|
163
|
+
hints.push(`Inline-editable in table view: ${inlineEditable.map(f => `\`${f}\``).join(', ')}`);
|
|
164
|
+
}
|
|
165
|
+
// Summary fields
|
|
166
|
+
const summaryFields = Object.entries(collection.fieldAffordances)
|
|
167
|
+
.filter(([_, fa]) => fa.summaryField)
|
|
168
|
+
.map(([key]) => key);
|
|
169
|
+
if (summaryFields.length > 0) {
|
|
170
|
+
hints.push(`Summary/title fields: ${summaryFields.map(f => `\`${f}\``).join(', ')}`);
|
|
171
|
+
}
|
|
172
|
+
// Detail-only fields
|
|
173
|
+
const detailOnly = Object.entries(collection.fieldAffordances)
|
|
174
|
+
.filter(([_, fa]) => fa.detailOnly)
|
|
175
|
+
.map(([key]) => key);
|
|
176
|
+
if (detailOnly.length > 0) {
|
|
177
|
+
hints.push(`Show only in detail view: ${detailOnly.map(f => `\`${f}\``).join(', ')}`);
|
|
178
|
+
}
|
|
179
|
+
for (const hint of hints) {
|
|
180
|
+
sections.push(`- ${hint}`);
|
|
181
|
+
}
|
|
182
|
+
return sections.join('\n');
|
|
183
|
+
}
|
|
184
|
+
// ============================================================================
|
|
185
|
+
// Helpers
|
|
186
|
+
// ============================================================================
|
|
187
|
+
function formatBool(value) {
|
|
188
|
+
if (value === true || value === 'both' || value === 'asc' || value === 'desc')
|
|
189
|
+
return 'yes';
|
|
190
|
+
if (value === false || value === 'none')
|
|
191
|
+
return 'no';
|
|
192
|
+
return String(value ?? 'no');
|
|
193
|
+
}
|
|
194
|
+
function formatFilter(value) {
|
|
195
|
+
if (value === false)
|
|
196
|
+
return 'no';
|
|
197
|
+
if (value === true)
|
|
198
|
+
return 'yes';
|
|
199
|
+
if (typeof value === 'string')
|
|
200
|
+
return value;
|
|
201
|
+
return 'no';
|
|
202
|
+
}
|
|
203
|
+
function buildFieldNotes(key, fa, collection) {
|
|
204
|
+
const notes = [];
|
|
205
|
+
if (key === collection.idField)
|
|
206
|
+
notes.push('ID');
|
|
207
|
+
if (key === collection.labelField)
|
|
208
|
+
notes.push('Label');
|
|
209
|
+
if (fa.summaryField)
|
|
210
|
+
notes.push('Summary');
|
|
211
|
+
if (fa.hidden)
|
|
212
|
+
notes.push('Hidden');
|
|
213
|
+
if (fa.visible === false)
|
|
214
|
+
notes.push('Not visible');
|
|
215
|
+
if (fa.detailOnly)
|
|
216
|
+
notes.push('Detail only');
|
|
217
|
+
if (fa.groupable)
|
|
218
|
+
notes.push('Groupable');
|
|
219
|
+
if (fa.inlineEditable)
|
|
220
|
+
notes.push('Inline edit');
|
|
221
|
+
if (fa.badge)
|
|
222
|
+
notes.push('Badge');
|
|
223
|
+
if (fa.copyable)
|
|
224
|
+
notes.push('Copyable');
|
|
225
|
+
if (fa.truncate)
|
|
226
|
+
notes.push(`Truncate@${fa.truncate}`);
|
|
227
|
+
if (fa.editWidget && fa.editWidget !== 'text')
|
|
228
|
+
notes.push(`Widget: ${fa.editWidget}`);
|
|
229
|
+
return notes.join(', ');
|
|
230
|
+
}
|
|
231
|
+
function describePagination(pagination) {
|
|
232
|
+
if (typeof pagination === 'boolean')
|
|
233
|
+
return 'enabled';
|
|
234
|
+
if (typeof pagination === 'object' && pagination !== null) {
|
|
235
|
+
const p = pagination;
|
|
236
|
+
const parts = [];
|
|
237
|
+
if (p.defaultPageSize)
|
|
238
|
+
parts.push(`${p.defaultPageSize}/page`);
|
|
239
|
+
if (p.style)
|
|
240
|
+
parts.push(p.style);
|
|
241
|
+
if (p.serverSide)
|
|
242
|
+
parts.push('server-side');
|
|
243
|
+
return parts.join(', ') || 'enabled';
|
|
244
|
+
}
|
|
245
|
+
return 'enabled';
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AASH;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,QAAQ,CAAC,UAAqC;IAC5D,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,SAAS;IACT,QAAQ,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IACzC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAElB,WAAW;IACX,QAAQ,CAAC,IAAI,CAAC,qBAAqB,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;IAC3D,QAAQ,CAAC,IAAI,CAAC,wBAAwB,UAAU,CAAC,UAAU,IAAI,CAAC,CAAC;IACjE,QAAQ,CAAC,IAAI,CAAC,uBAAuB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IACxF,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAElB,aAAa;IACb,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAClB,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AAS,kBAAkB,CAAC,UAAmB;IAC7C,IAAI,OAAO,UAAU,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACtD,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QAC1D,MAAM,CAAC,GAAG,UAAiB,CAAC;QAC5B,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAI,CAAC,CAAC,eAAe;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,eAAe,OAAO,CAAC,CAAC;QAC/D,IAAI,CAAC,CAAC,KAAK;YAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,CAAC,UAAU;YAAE,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC5C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,SAAS,CAAC;IACvC,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
package/dist/store.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collection Store: Framework-agnostic state factory.
|
|
3
|
+
*
|
|
4
|
+
* Creates a state object + action functions for managing collection UI state.
|
|
5
|
+
* This is headless — it doesn't depend on React, Zustand, or any framework.
|
|
6
|
+
* You can:
|
|
7
|
+
* - Use it directly as a plain object
|
|
8
|
+
* - Feed its shape into Zustand's `create()`
|
|
9
|
+
* - Feed its shape into a React `useReducer`
|
|
10
|
+
* - Feed its shape into any state management library
|
|
11
|
+
*
|
|
12
|
+
* Design: follows the "thin glue" philosophy — produces data, not components.
|
|
13
|
+
*/
|
|
14
|
+
import type { CollectionDefinition } from './collection.js';
|
|
15
|
+
export interface SortingState {
|
|
16
|
+
id: string;
|
|
17
|
+
desc: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface ColumnFilter {
|
|
20
|
+
id: string;
|
|
21
|
+
value: unknown;
|
|
22
|
+
}
|
|
23
|
+
export interface PaginationState {
|
|
24
|
+
pageIndex: number;
|
|
25
|
+
pageSize: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The full state shape for a collection UI.
|
|
29
|
+
* Compatible with TanStack Table's state model.
|
|
30
|
+
*/
|
|
31
|
+
export interface CollectionState<T> {
|
|
32
|
+
items: T[];
|
|
33
|
+
totalCount: number;
|
|
34
|
+
loading: boolean;
|
|
35
|
+
error: string | null;
|
|
36
|
+
sorting: SortingState[];
|
|
37
|
+
columnFilters: ColumnFilter[];
|
|
38
|
+
globalFilter: string;
|
|
39
|
+
pagination: PaginationState;
|
|
40
|
+
rowSelection: Record<string, boolean>;
|
|
41
|
+
columnVisibility: Record<string, boolean>;
|
|
42
|
+
columnOrder: string[];
|
|
43
|
+
grouping: string[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Actions that modify collection state.
|
|
47
|
+
* Each action takes the current state and returns a new state (pure functions).
|
|
48
|
+
*/
|
|
49
|
+
export interface CollectionActions<T> {
|
|
50
|
+
setItems(state: CollectionState<T>, items: T[], total?: number): CollectionState<T>;
|
|
51
|
+
setSorting(state: CollectionState<T>, sorting: SortingState[]): CollectionState<T>;
|
|
52
|
+
setColumnFilters(state: CollectionState<T>, filters: ColumnFilter[]): CollectionState<T>;
|
|
53
|
+
setGlobalFilter(state: CollectionState<T>, filter: string): CollectionState<T>;
|
|
54
|
+
setPagination(state: CollectionState<T>, pagination: PaginationState): CollectionState<T>;
|
|
55
|
+
setRowSelection(state: CollectionState<T>, selection: Record<string, boolean>): CollectionState<T>;
|
|
56
|
+
setColumnVisibility(state: CollectionState<T>, visibility: Record<string, boolean>): CollectionState<T>;
|
|
57
|
+
setColumnOrder(state: CollectionState<T>, order: string[]): CollectionState<T>;
|
|
58
|
+
setGrouping(state: CollectionState<T>, grouping: string[]): CollectionState<T>;
|
|
59
|
+
setLoading(state: CollectionState<T>, loading: boolean): CollectionState<T>;
|
|
60
|
+
setError(state: CollectionState<T>, error: string | null): CollectionState<T>;
|
|
61
|
+
clearSelection(state: CollectionState<T>): CollectionState<T>;
|
|
62
|
+
selectAll(state: CollectionState<T>): CollectionState<T>;
|
|
63
|
+
reset(state: CollectionState<T>): CollectionState<T>;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A collection store: initial state + pure action functions + derived selectors.
|
|
67
|
+
*/
|
|
68
|
+
export interface CollectionStore<T> {
|
|
69
|
+
/** The initial state, derived from the collection definition. */
|
|
70
|
+
initialState: CollectionState<T>;
|
|
71
|
+
/** Pure functions that produce new state from old state + args. */
|
|
72
|
+
actions: CollectionActions<T>;
|
|
73
|
+
/** Derived data selectors (computed from state). */
|
|
74
|
+
selectors: {
|
|
75
|
+
getSelectedItems(state: CollectionState<T>): T[];
|
|
76
|
+
getSelectedCount(state: CollectionState<T>): number;
|
|
77
|
+
getPageCount(state: CollectionState<T>): number;
|
|
78
|
+
isAllSelected(state: CollectionState<T>): boolean;
|
|
79
|
+
hasSelection(state: CollectionState<T>): boolean;
|
|
80
|
+
getVisibleItems(state: CollectionState<T>): T[];
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create a collection store from a CollectionDefinition.
|
|
85
|
+
*
|
|
86
|
+
* Returns initial state, pure action functions, and derived selectors.
|
|
87
|
+
* Framework-agnostic: use with Zustand, Redux, useReducer, or plain objects.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* const store = createCollectionStore(projectCollection);
|
|
92
|
+
*
|
|
93
|
+
* // Use directly:
|
|
94
|
+
* let state = store.initialState;
|
|
95
|
+
* state = store.actions.setItems(state, projects, 100);
|
|
96
|
+
* const selected = store.selectors.getSelectedItems(state);
|
|
97
|
+
*
|
|
98
|
+
* // Or feed into Zustand:
|
|
99
|
+
* const useStore = create(() => ({
|
|
100
|
+
* ...store.initialState,
|
|
101
|
+
* setItems: (items, total) => set(s => store.actions.setItems(s, items, total)),
|
|
102
|
+
* }));
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function createCollectionStore<T>(collection: CollectionDefinition<any>): CollectionStore<T>;
|
package/dist/store.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collection Store: Framework-agnostic state factory.
|
|
3
|
+
*
|
|
4
|
+
* Creates a state object + action functions for managing collection UI state.
|
|
5
|
+
* This is headless — it doesn't depend on React, Zustand, or any framework.
|
|
6
|
+
* You can:
|
|
7
|
+
* - Use it directly as a plain object
|
|
8
|
+
* - Feed its shape into Zustand's `create()`
|
|
9
|
+
* - Feed its shape into a React `useReducer`
|
|
10
|
+
* - Feed its shape into any state management library
|
|
11
|
+
*
|
|
12
|
+
* Design: follows the "thin glue" philosophy — produces data, not components.
|
|
13
|
+
*/
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// createCollectionStore
|
|
16
|
+
// ============================================================================
|
|
17
|
+
/**
|
|
18
|
+
* Create a collection store from a CollectionDefinition.
|
|
19
|
+
*
|
|
20
|
+
* Returns initial state, pure action functions, and derived selectors.
|
|
21
|
+
* Framework-agnostic: use with Zustand, Redux, useReducer, or plain objects.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const store = createCollectionStore(projectCollection);
|
|
26
|
+
*
|
|
27
|
+
* // Use directly:
|
|
28
|
+
* let state = store.initialState;
|
|
29
|
+
* state = store.actions.setItems(state, projects, 100);
|
|
30
|
+
* const selected = store.selectors.getSelectedItems(state);
|
|
31
|
+
*
|
|
32
|
+
* // Or feed into Zustand:
|
|
33
|
+
* const useStore = create(() => ({
|
|
34
|
+
* ...store.initialState,
|
|
35
|
+
* setItems: (items, total) => set(s => store.actions.setItems(s, items, total)),
|
|
36
|
+
* }));
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function createCollectionStore(collection) {
|
|
40
|
+
// Build initial state from collection affordances
|
|
41
|
+
const paginationConfig = collection.affordances.pagination;
|
|
42
|
+
const defaultPageSize = paginationConfig && typeof paginationConfig === 'object'
|
|
43
|
+
? paginationConfig.defaultPageSize ?? 25
|
|
44
|
+
: 25;
|
|
45
|
+
const defaultSort = collection.affordances.defaultSort;
|
|
46
|
+
const initialState = {
|
|
47
|
+
items: [],
|
|
48
|
+
totalCount: 0,
|
|
49
|
+
loading: false,
|
|
50
|
+
error: null,
|
|
51
|
+
sorting: defaultSort
|
|
52
|
+
? [{ id: defaultSort.field, desc: defaultSort.direction === 'desc' }]
|
|
53
|
+
: [],
|
|
54
|
+
columnFilters: [],
|
|
55
|
+
globalFilter: '',
|
|
56
|
+
pagination: {
|
|
57
|
+
pageIndex: 0,
|
|
58
|
+
pageSize: defaultPageSize,
|
|
59
|
+
},
|
|
60
|
+
rowSelection: {},
|
|
61
|
+
columnVisibility: buildInitialVisibility(collection),
|
|
62
|
+
columnOrder: buildInitialOrder(collection),
|
|
63
|
+
grouping: [],
|
|
64
|
+
};
|
|
65
|
+
// Pure action functions (state, args) → newState
|
|
66
|
+
const actions = {
|
|
67
|
+
setItems(state, items, total) {
|
|
68
|
+
return { ...state, items, totalCount: total ?? items.length };
|
|
69
|
+
},
|
|
70
|
+
setSorting(state, sorting) {
|
|
71
|
+
return { ...state, sorting };
|
|
72
|
+
},
|
|
73
|
+
setColumnFilters(state, filters) {
|
|
74
|
+
return { ...state, columnFilters: filters, pagination: { ...state.pagination, pageIndex: 0 } };
|
|
75
|
+
},
|
|
76
|
+
setGlobalFilter(state, filter) {
|
|
77
|
+
return { ...state, globalFilter: filter, pagination: { ...state.pagination, pageIndex: 0 } };
|
|
78
|
+
},
|
|
79
|
+
setPagination(state, pagination) {
|
|
80
|
+
return { ...state, pagination };
|
|
81
|
+
},
|
|
82
|
+
setRowSelection(state, selection) {
|
|
83
|
+
return { ...state, rowSelection: selection };
|
|
84
|
+
},
|
|
85
|
+
setColumnVisibility(state, visibility) {
|
|
86
|
+
return { ...state, columnVisibility: visibility };
|
|
87
|
+
},
|
|
88
|
+
setColumnOrder(state, order) {
|
|
89
|
+
return { ...state, columnOrder: order };
|
|
90
|
+
},
|
|
91
|
+
setGrouping(state, grouping) {
|
|
92
|
+
return { ...state, grouping };
|
|
93
|
+
},
|
|
94
|
+
setLoading(state, loading) {
|
|
95
|
+
return { ...state, loading };
|
|
96
|
+
},
|
|
97
|
+
setError(state, error) {
|
|
98
|
+
return { ...state, error };
|
|
99
|
+
},
|
|
100
|
+
clearSelection(state) {
|
|
101
|
+
return { ...state, rowSelection: {} };
|
|
102
|
+
},
|
|
103
|
+
selectAll(state) {
|
|
104
|
+
const selection = {};
|
|
105
|
+
for (let i = 0; i < state.items.length; i++) {
|
|
106
|
+
selection[String(i)] = true;
|
|
107
|
+
}
|
|
108
|
+
return { ...state, rowSelection: selection };
|
|
109
|
+
},
|
|
110
|
+
reset(state) {
|
|
111
|
+
return {
|
|
112
|
+
...state,
|
|
113
|
+
sorting: initialState.sorting,
|
|
114
|
+
columnFilters: [],
|
|
115
|
+
globalFilter: '',
|
|
116
|
+
pagination: { pageIndex: 0, pageSize: state.pagination.pageSize },
|
|
117
|
+
rowSelection: {},
|
|
118
|
+
grouping: [],
|
|
119
|
+
};
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
// Derived selectors
|
|
123
|
+
const selectors = {
|
|
124
|
+
getSelectedItems(state) {
|
|
125
|
+
return Object.entries(state.rowSelection)
|
|
126
|
+
.filter(([_, selected]) => selected)
|
|
127
|
+
.map(([idx]) => state.items[parseInt(idx)])
|
|
128
|
+
.filter(Boolean);
|
|
129
|
+
},
|
|
130
|
+
getSelectedCount(state) {
|
|
131
|
+
return Object.values(state.rowSelection).filter(Boolean).length;
|
|
132
|
+
},
|
|
133
|
+
getPageCount(state) {
|
|
134
|
+
if (state.pagination.pageSize === 0)
|
|
135
|
+
return 0;
|
|
136
|
+
return Math.ceil(state.totalCount / state.pagination.pageSize);
|
|
137
|
+
},
|
|
138
|
+
isAllSelected(state) {
|
|
139
|
+
if (state.items.length === 0)
|
|
140
|
+
return false;
|
|
141
|
+
return Object.values(state.rowSelection).filter(Boolean).length === state.items.length;
|
|
142
|
+
},
|
|
143
|
+
hasSelection(state) {
|
|
144
|
+
return Object.values(state.rowSelection).some(Boolean);
|
|
145
|
+
},
|
|
146
|
+
getVisibleItems(state) {
|
|
147
|
+
// For client-side pagination, slice the items array
|
|
148
|
+
const { pageIndex, pageSize } = state.pagination;
|
|
149
|
+
return state.items.slice(pageIndex * pageSize, (pageIndex + 1) * pageSize);
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
return { initialState, actions, selectors };
|
|
153
|
+
}
|
|
154
|
+
// ============================================================================
|
|
155
|
+
// Helpers
|
|
156
|
+
// ============================================================================
|
|
157
|
+
function buildInitialVisibility(collection) {
|
|
158
|
+
const visibility = {};
|
|
159
|
+
for (const [key, fa] of Object.entries(collection.fieldAffordances)) {
|
|
160
|
+
if (fa.visible === false || fa.hidden) {
|
|
161
|
+
visibility[key] = false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return visibility;
|
|
165
|
+
}
|
|
166
|
+
function buildInitialOrder(collection) {
|
|
167
|
+
return Object.entries(collection.fieldAffordances)
|
|
168
|
+
.sort(([, a], [, b]) => (a.order ?? 999) - (b.order ?? 999))
|
|
169
|
+
.map(([key]) => key);
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAsFH,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAAqC;IAErC,kDAAkD;IAClD,MAAM,gBAAgB,GAAG,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC;IAC3D,MAAM,eAAe,GACnB,gBAA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