@cervio/plugin-sdk 2.2.0 → 2.3.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/README.md +62 -0
- package/dist/forms/index.d.ts +360 -0
- package/dist/forms/index.js +416 -0
- package/dist/forms/react.d.ts +381 -0
- package/dist/forms/react.js +1159 -0
- package/dist/index.d.ts +12 -1
- package/dist/views/index.d.ts +450 -0
- package/dist/views/index.js +570 -0
- package/dist/views/react.d.ts +406 -0
- package/dist/views/react.js +1368 -0
- package/package.json +22 -2
package/dist/index.d.ts
CHANGED
|
@@ -244,8 +244,16 @@ interface CervioUiTaskSummary {
|
|
|
244
244
|
entityDataId: string | null;
|
|
245
245
|
canComplete: boolean;
|
|
246
246
|
blockReason: string | null;
|
|
247
|
+
/** True when the task cannot be decided from a route plugin: open it with `task.open` instead. */
|
|
247
248
|
requiresFullView: boolean;
|
|
249
|
+
/**
|
|
250
|
+
* Why the task has to be completed in its own screen in Cervio, or `null` when
|
|
251
|
+
* `task.complete` may decide it. Same rule as the REST API and MCP. Older hosts omit it.
|
|
252
|
+
*/
|
|
253
|
+
completeInAppReason?: CervioUiTaskCompleteInAppReason | null;
|
|
248
254
|
}
|
|
255
|
+
/** Reasons a task can only be completed in Cervio (its own screen), never from a route plugin. */
|
|
256
|
+
type CervioUiTaskCompleteInAppReason = 'plugin' | 'required_fields' | 'claim' | 'blocked' | 'no_outcomes' | 'not_open';
|
|
249
257
|
interface CervioUiTaskListItem {
|
|
250
258
|
id: string;
|
|
251
259
|
title: string;
|
|
@@ -476,6 +484,9 @@ interface CervioUI {
|
|
|
476
484
|
* Rejects with `{ code, message }` for Unauthorized | Forbidden | task_not_open |
|
|
477
485
|
* already_responded | reassigned | workflow_not_active | invalid_outcome |
|
|
478
486
|
* variable_required | document_upload_required | record_link_required | in_flight.
|
|
487
|
+
* `complete` also rejects with `{ code: 'complete_in_app', reason, message }` when the
|
|
488
|
+
* task has to be completed in its own screen (`reason` as in
|
|
489
|
+
* `CervioUiTaskSummary.completeInAppReason`): check `get` first and offer `open`.
|
|
479
490
|
*/
|
|
480
491
|
task: {
|
|
481
492
|
get(opts: {
|
|
@@ -989,4 +1000,4 @@ interface CervioI18n {
|
|
|
989
1000
|
declare function createI18n(opts: CreateI18nOptions): CervioI18n;
|
|
990
1001
|
|
|
991
1002
|
export { CERVIO_UI_API_VERSION, CervioApiError, createCervioClient, createCervioSessionClient, createI18n, ensureExternalConnection, findEntityByName, getCervioUI, getCurrentTheme, getPluginContext, getTaskPluginContext, isCervioUIAvailable, isInsideCervioSandbox, markReady, onThemeChange, openExternalAuth, resolveApiBaseUrl, resolvePluginLocale, setTaskDraft, submitTaskOutcome };
|
|
992
|
-
export type { CervioClient, CervioClientOptions, CervioColorScheme, CervioHostThemeMessage, CervioI18n, CervioI18nCatalog, CervioI18nMessages, CervioPluginContext, CervioPluginRuntimeSettings, CervioSessionClient, CervioSessionClientOptions, CervioTaskDraftResult, CervioTaskOutcome, CervioTaskPluginBoot, CervioTaskPluginContextData, CervioTaskSubmitResult, CervioThemeChangeHandler, CervioThemeSnapshot, CervioUI, CervioUiActionSheetAction, CervioUiActionSheetOpenOptions, CervioUiAlertOptions, CervioUiBarcodeScanOptions, CervioUiBarcodeScanResult, CervioUiCameraOpenOptions, CervioUiConfirmOptions, CervioUiDateOpenOptions, CervioUiDialogVariant, CervioUiDomainPickOption, CervioUiEntityPickOptions, CervioUiExportDownloadOptions, CervioUiFileMeta, CervioUiFilesCaptureOptions, CervioUiFilesPickOptions, CervioUiFilesPickResult, CervioUiFilesUploadOptions, CervioUiFilesUploadResult, CervioUiFormatSnapshot, CervioUiFrameClosedEvent, CervioUiFrameMetricsEvent, CervioUiFrameOpenOptions, CervioUiFrameSize, CervioUiFrameSlot, CervioUiGroupPickOptions, CervioUiHeaderActionEvent, CervioUiHeaderActionOptions, CervioUiHeaderEventMap, CervioUiHeaderState, CervioUiHeaderTabEvent, CervioUiHeaderText, CervioUiHeaderUpdateOptions, CervioUiHostEvent, CervioUiLocationPickOptions, CervioUiLocationResult, CervioUiNavConfirmLeaveOptions, CervioUiPrintOpenOptions, CervioUiProgressShowOptions, CervioUiProgressUpdateOptions, CervioUiRecordPickOptions, CervioUiSelectOpenOptions, CervioUiSelectOption, CervioUiShareOpenOptions, CervioUiShareResult, CervioUiSheetAction, CervioUiSheetOpenOptions, CervioUiSurfaceClosedEvent, CervioUiSurfaceMessageEvent, CervioUiSurfaceOpenOptions, CervioUiSurfaceOpenedEvent, CervioUiTaskCompleteOptions, CervioUiTaskCompleteResult, CervioUiTaskListItem, CervioUiTaskOpenResult, CervioUiTaskOutcome, CervioUiTaskSummary, CervioUiThemeSnapshot, CervioUiToastOptions, CervioUiToastType, CervioUiUserPickOptions, CreateI18nOptions, Entity, EntityCapabilities, EntityRecord, ExternalConnectionStatus, ExternalProxyInput, Identity, ListViewRecordsOptions, RecordWriteOptions, ResolvePluginLocaleOptions, UpdateRecordOptions, ViewRecordsPage };
|
|
1003
|
+
export type { CervioClient, CervioClientOptions, CervioColorScheme, CervioHostThemeMessage, CervioI18n, CervioI18nCatalog, CervioI18nMessages, CervioPluginContext, CervioPluginRuntimeSettings, CervioSessionClient, CervioSessionClientOptions, CervioTaskDraftResult, CervioTaskOutcome, CervioTaskPluginBoot, CervioTaskPluginContextData, CervioTaskSubmitResult, CervioThemeChangeHandler, CervioThemeSnapshot, CervioUI, CervioUiActionSheetAction, CervioUiActionSheetOpenOptions, CervioUiAlertOptions, CervioUiBarcodeScanOptions, CervioUiBarcodeScanResult, CervioUiCameraOpenOptions, CervioUiConfirmOptions, CervioUiDateOpenOptions, CervioUiDialogVariant, CervioUiDomainPickOption, CervioUiEntityPickOptions, CervioUiExportDownloadOptions, CervioUiFileMeta, CervioUiFilesCaptureOptions, CervioUiFilesPickOptions, CervioUiFilesPickResult, CervioUiFilesUploadOptions, CervioUiFilesUploadResult, CervioUiFormatSnapshot, CervioUiFrameClosedEvent, CervioUiFrameMetricsEvent, CervioUiFrameOpenOptions, CervioUiFrameSize, CervioUiFrameSlot, CervioUiGroupPickOptions, CervioUiHeaderActionEvent, CervioUiHeaderActionOptions, CervioUiHeaderEventMap, CervioUiHeaderState, CervioUiHeaderTabEvent, CervioUiHeaderText, CervioUiHeaderUpdateOptions, CervioUiHostEvent, CervioUiLocationPickOptions, CervioUiLocationResult, CervioUiNavConfirmLeaveOptions, CervioUiPrintOpenOptions, CervioUiProgressShowOptions, CervioUiProgressUpdateOptions, CervioUiRecordPickOptions, CervioUiSelectOpenOptions, CervioUiSelectOption, CervioUiShareOpenOptions, CervioUiShareResult, CervioUiSheetAction, CervioUiSheetOpenOptions, CervioUiSurfaceClosedEvent, CervioUiSurfaceMessageEvent, CervioUiSurfaceOpenOptions, CervioUiSurfaceOpenedEvent, CervioUiTaskCompleteInAppReason, CervioUiTaskCompleteOptions, CervioUiTaskCompleteResult, CervioUiTaskListItem, CervioUiTaskOpenResult, CervioUiTaskOutcome, CervioUiTaskSummary, CervioUiThemeSnapshot, CervioUiToastOptions, CervioUiToastType, CervioUiUserPickOptions, CreateI18nOptions, Entity, EntityCapabilities, EntityRecord, ExternalConnectionStatus, ExternalProxyInput, Identity, ListViewRecordsOptions, RecordWriteOptions, ResolvePluginLocaleOptions, UpdateRecordOptions, ViewRecordsPage };
|
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wire types of the Cervio view API (`/api/v1/views/{viewId}`, `/query`,
|
|
3
|
+
* `/api/v1/me/view-prefs/{viewId}`). They mirror the host responses: the host
|
|
4
|
+
* repository documents them in its OpenAPI description.
|
|
5
|
+
*/
|
|
6
|
+
type ViewFilterType = 'text' | 'number' | 'date' | 'relation' | 'boolean';
|
|
7
|
+
/** One column of `GET /api/v1/views/{viewId}`. */
|
|
8
|
+
interface ViewColumn {
|
|
9
|
+
/** Key of this column's value in `records[].data`; also the key of layout prefs. */
|
|
10
|
+
key: string;
|
|
11
|
+
/** Name to use in query filters; null for lookup columns. */
|
|
12
|
+
field: string | null;
|
|
13
|
+
field_id: string | null;
|
|
14
|
+
label: string;
|
|
15
|
+
/** Cervio field type (`text`, `number`, `currency`, `date`, `select`, `relation`, …). */
|
|
16
|
+
type: string;
|
|
17
|
+
display_type: string | null;
|
|
18
|
+
lookup: boolean;
|
|
19
|
+
/** Choices of a list field, labels already in the response locale. */
|
|
20
|
+
options?: Array<{
|
|
21
|
+
value: string;
|
|
22
|
+
label: string;
|
|
23
|
+
}>;
|
|
24
|
+
/** How the column can be filtered; null: not filterable. */
|
|
25
|
+
filter: {
|
|
26
|
+
type: ViewFilterType;
|
|
27
|
+
operators: string[];
|
|
28
|
+
} | null;
|
|
29
|
+
}
|
|
30
|
+
interface ViewDefinition {
|
|
31
|
+
view: {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
label: string;
|
|
35
|
+
entity: {
|
|
36
|
+
id: string;
|
|
37
|
+
name: string;
|
|
38
|
+
label: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
columns: ViewColumn[];
|
|
42
|
+
search: boolean;
|
|
43
|
+
page: {
|
|
44
|
+
size: number;
|
|
45
|
+
max_size: number;
|
|
46
|
+
};
|
|
47
|
+
locale: string;
|
|
48
|
+
}
|
|
49
|
+
/** A record as `/records` and `/query` return it: values keyed by `ViewColumn.key`. */
|
|
50
|
+
interface ViewRecord {
|
|
51
|
+
id: string;
|
|
52
|
+
data: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
/** One filter of `POST /api/v1/views/{viewId}/query` (`field` = `ViewColumn.field`). */
|
|
55
|
+
type ViewQueryFilter = {
|
|
56
|
+
field: string;
|
|
57
|
+
operator: 'equals';
|
|
58
|
+
values: string[];
|
|
59
|
+
} | {
|
|
60
|
+
field: string;
|
|
61
|
+
operator: 'contains';
|
|
62
|
+
value: string;
|
|
63
|
+
} | {
|
|
64
|
+
field: string;
|
|
65
|
+
operator: 'equals' | 'gt' | 'gte' | 'lt' | 'lte';
|
|
66
|
+
value: number | string;
|
|
67
|
+
} | {
|
|
68
|
+
field: string;
|
|
69
|
+
operator: 'between';
|
|
70
|
+
min?: number;
|
|
71
|
+
max?: number;
|
|
72
|
+
} | {
|
|
73
|
+
field: string;
|
|
74
|
+
operator: 'between';
|
|
75
|
+
from?: string;
|
|
76
|
+
to?: string;
|
|
77
|
+
}
|
|
78
|
+
/** Relation: linked record ids. */
|
|
79
|
+
| {
|
|
80
|
+
field: string;
|
|
81
|
+
operator: 'equals';
|
|
82
|
+
values: string[];
|
|
83
|
+
}
|
|
84
|
+
/** Boolean. */
|
|
85
|
+
| {
|
|
86
|
+
field: string;
|
|
87
|
+
operator: 'equals';
|
|
88
|
+
value: boolean;
|
|
89
|
+
};
|
|
90
|
+
interface ViewQueryRequest {
|
|
91
|
+
filters?: ViewQueryFilter[];
|
|
92
|
+
search?: string;
|
|
93
|
+
limit?: number;
|
|
94
|
+
cursor?: string;
|
|
95
|
+
count?: boolean;
|
|
96
|
+
options?: 'labels' | 'slugs' | 'both';
|
|
97
|
+
relations?: 'labels' | 'uuids' | 'both';
|
|
98
|
+
locale?: string;
|
|
99
|
+
}
|
|
100
|
+
interface ViewQueryResponse {
|
|
101
|
+
records: ViewRecord[];
|
|
102
|
+
page: {
|
|
103
|
+
limit: number;
|
|
104
|
+
has_more: boolean;
|
|
105
|
+
next_cursor?: string;
|
|
106
|
+
};
|
|
107
|
+
total?: number;
|
|
108
|
+
locale: string;
|
|
109
|
+
}
|
|
110
|
+
/** Column layout, keyed by `ViewColumn.key`. Same shapes as TanStack Table's state. */
|
|
111
|
+
interface ViewLayout {
|
|
112
|
+
sizing?: Record<string, number>;
|
|
113
|
+
order?: string[];
|
|
114
|
+
visibility?: Record<string, boolean>;
|
|
115
|
+
pinning?: {
|
|
116
|
+
left: string[];
|
|
117
|
+
right: string[];
|
|
118
|
+
};
|
|
119
|
+
sorting?: Array<{
|
|
120
|
+
key: string;
|
|
121
|
+
desc: boolean;
|
|
122
|
+
}>;
|
|
123
|
+
/** Columns the rows are grouped by, outermost first (at most 3). */
|
|
124
|
+
grouping?: string[];
|
|
125
|
+
}
|
|
126
|
+
/** Choices of a relation filter (`GET /api/v1/views/{viewId}/columns/{key}/options`). */
|
|
127
|
+
interface ViewFilterOptions {
|
|
128
|
+
options: Array<{
|
|
129
|
+
value: string;
|
|
130
|
+
label: string;
|
|
131
|
+
}>;
|
|
132
|
+
has_more: boolean;
|
|
133
|
+
/** Pass back as `cursor` for the next page (same search). */
|
|
134
|
+
next_cursor?: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Where the layout is saved: `shared` is the view's layout in Cervio; `plugin:<key>`
|
|
138
|
+
* a separate one for that plugin (never changes the view in Cervio).
|
|
139
|
+
*/
|
|
140
|
+
type ViewLayoutScope = 'shared' | `plugin:${string}`;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Filter model of the Cervio list filter bar, without UI: one value per column,
|
|
144
|
+
* keyed by field name. Extracted from Cervio (`lib/entity-filters/oda-filters.ts`)
|
|
145
|
+
* so Cervio and plugins share one definition.
|
|
146
|
+
*
|
|
147
|
+
* `filtersToQuery` turns it into `POST /api/v1/views/{viewId}/query` filters;
|
|
148
|
+
* Cervio's own list RPCs read the same rule shape (`filtersStateToRules`).
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
type NumberFilterOp = 'equals' | 'gt' | 'gte' | 'lt' | 'lte' | 'between';
|
|
152
|
+
type DateFilterOp = 'equals' | 'gt' | 'gte' | 'lt' | 'lte' | 'between';
|
|
153
|
+
type FilterValue = {
|
|
154
|
+
type: 'text';
|
|
155
|
+
operator: 'equals';
|
|
156
|
+
values: string[];
|
|
157
|
+
} | {
|
|
158
|
+
type: 'text';
|
|
159
|
+
operator: 'contains';
|
|
160
|
+
value: string;
|
|
161
|
+
} | {
|
|
162
|
+
type: 'number';
|
|
163
|
+
operator: 'equals';
|
|
164
|
+
value?: number;
|
|
165
|
+
} | {
|
|
166
|
+
type: 'number';
|
|
167
|
+
operator: 'gt';
|
|
168
|
+
value?: number;
|
|
169
|
+
} | {
|
|
170
|
+
type: 'number';
|
|
171
|
+
operator: 'gte';
|
|
172
|
+
value?: number;
|
|
173
|
+
} | {
|
|
174
|
+
type: 'number';
|
|
175
|
+
operator: 'lt';
|
|
176
|
+
value?: number;
|
|
177
|
+
} | {
|
|
178
|
+
type: 'number';
|
|
179
|
+
operator: 'lte';
|
|
180
|
+
value?: number;
|
|
181
|
+
} | {
|
|
182
|
+
type: 'number';
|
|
183
|
+
operator: 'between';
|
|
184
|
+
min?: number;
|
|
185
|
+
max?: number;
|
|
186
|
+
} | {
|
|
187
|
+
type: 'date';
|
|
188
|
+
operator: 'equals';
|
|
189
|
+
value?: string;
|
|
190
|
+
} | {
|
|
191
|
+
type: 'date';
|
|
192
|
+
operator: 'gt';
|
|
193
|
+
value?: string;
|
|
194
|
+
} | {
|
|
195
|
+
type: 'date';
|
|
196
|
+
operator: 'gte';
|
|
197
|
+
value?: string;
|
|
198
|
+
} | {
|
|
199
|
+
type: 'date';
|
|
200
|
+
operator: 'lt';
|
|
201
|
+
value?: string;
|
|
202
|
+
} | {
|
|
203
|
+
type: 'date';
|
|
204
|
+
operator: 'lte';
|
|
205
|
+
value?: string;
|
|
206
|
+
} | {
|
|
207
|
+
type: 'date';
|
|
208
|
+
operator: 'between';
|
|
209
|
+
from?: string;
|
|
210
|
+
to?: string;
|
|
211
|
+
}
|
|
212
|
+
/** Linked record ids; `labels` only keeps the names to show (never sent). */
|
|
213
|
+
| {
|
|
214
|
+
type: 'relation';
|
|
215
|
+
operator: 'equals';
|
|
216
|
+
values: string[];
|
|
217
|
+
labels?: Record<string, string>;
|
|
218
|
+
} | {
|
|
219
|
+
type: 'boolean';
|
|
220
|
+
operator: 'equals';
|
|
221
|
+
value?: boolean;
|
|
222
|
+
};
|
|
223
|
+
/** Filters of a view, keyed by field name (`ViewColumn.field`). */
|
|
224
|
+
type FiltersState = Record<string, FilterValue>;
|
|
225
|
+
/** True when the filter would narrow the rows (an empty filter is ignored, never sent). */
|
|
226
|
+
declare function isFilterValueActive(f: FilterValue): boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Active filters as list rules `[{ field, type, operator, value | values | min | max | from | to }]`,
|
|
229
|
+
* the shape Cervio's list RPCs read. Inactive filters are left out (they would
|
|
230
|
+
* wrongly exclude rows).
|
|
231
|
+
*/
|
|
232
|
+
declare function filtersStateToRules(state: FiltersState): Array<Record<string, unknown>>;
|
|
233
|
+
/** Active filters as `POST /query` filters (the host takes the type from the column). */
|
|
234
|
+
declare function filtersToQuery(state: FiltersState): ViewQueryFilter[];
|
|
235
|
+
/** Number of active filters (for a "Filters (2)" badge). */
|
|
236
|
+
declare function activeFilterCount(state: FiltersState): number;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* How the engine reaches the view API. The default works for any `fetch`: inside a
|
|
240
|
+
* plugin pass the SDK's relayed fetch, in Cervio the session one, in Node a token.
|
|
241
|
+
*/
|
|
242
|
+
|
|
243
|
+
interface ViewTransport {
|
|
244
|
+
getDefinition(viewId: string, signal?: AbortSignal): Promise<ViewDefinition>;
|
|
245
|
+
query(viewId: string, body: ViewQueryRequest, signal?: AbortSignal): Promise<ViewQueryResponse>;
|
|
246
|
+
getLayout(viewId: string, scope: ViewLayoutScope): Promise<ViewLayout>;
|
|
247
|
+
/** Save the keys of `layout` (the host merges widths and visibility per column). */
|
|
248
|
+
putLayout(viewId: string, scope: ViewLayoutScope, layout: ViewLayout): Promise<ViewLayout>;
|
|
249
|
+
/** Choices of a relation filter (records of the linked entity the user can read). */
|
|
250
|
+
getFilterOptions?(viewId: string, key: string, opts: {
|
|
251
|
+
search?: string;
|
|
252
|
+
limit?: number;
|
|
253
|
+
cursor?: string;
|
|
254
|
+
}, signal?: AbortSignal): Promise<ViewFilterOptions>;
|
|
255
|
+
}
|
|
256
|
+
declare class ViewApiError extends Error {
|
|
257
|
+
readonly status: number;
|
|
258
|
+
readonly code: string;
|
|
259
|
+
constructor(status: number, code: string, message: string);
|
|
260
|
+
}
|
|
261
|
+
interface FetchTransportOptions {
|
|
262
|
+
/** Origin of the Cervio host (e.g. `https://acme.cervio.app`); '' for same-origin. */
|
|
263
|
+
baseUrl?: string;
|
|
264
|
+
fetchImpl?: typeof fetch;
|
|
265
|
+
/** Extra headers on every request (e.g. `Authorization` outside a session). */
|
|
266
|
+
headers?: Record<string, string>;
|
|
267
|
+
/** `include` with a session cookie (Cervio shell, plugin relay). Default `include`. */
|
|
268
|
+
credentials?: RequestCredentials;
|
|
269
|
+
}
|
|
270
|
+
declare function createFetchTransport(opts?: FetchTransportOptions): ViewTransport;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Sorting and grouping of the loaded rows, as the Cervio grid does them (the list
|
|
274
|
+
* RPCs do not sort on the server yet): values compare by what the user reads
|
|
275
|
+
* (option and relation labels), numbers as numbers, empty values last.
|
|
276
|
+
*
|
|
277
|
+
* Pure functions: the controller applies them to `state.rows` / `state.groups`,
|
|
278
|
+
* any other UI can call them too.
|
|
279
|
+
*/
|
|
280
|
+
|
|
281
|
+
type ViewSorting = NonNullable<ViewLayout['sorting']>;
|
|
282
|
+
/** One group of rows; `groups` holds the next level when grouping by more columns. */
|
|
283
|
+
interface ViewGroup {
|
|
284
|
+
/** Column key the rows are grouped by. */
|
|
285
|
+
column: string;
|
|
286
|
+
/** Stored value of the group (option value, relation id, text); '' for empty. */
|
|
287
|
+
value: string;
|
|
288
|
+
/** What the user reads for the group ('' for empty). */
|
|
289
|
+
label: string;
|
|
290
|
+
/** Rows in this group (all levels below included). */
|
|
291
|
+
count: number;
|
|
292
|
+
rows: ViewRecord[];
|
|
293
|
+
groups?: ViewGroup[];
|
|
294
|
+
}
|
|
295
|
+
/** Stored value of a cell (option value, relation id) as a string. */
|
|
296
|
+
declare function cellRawValue(v: unknown): string;
|
|
297
|
+
/** What the user reads in a cell, for sorting and group titles. */
|
|
298
|
+
declare function cellLabel(column: ViewColumn | undefined, v: unknown): string;
|
|
299
|
+
/** Rows sorted by `sorting` (first key wins, then the next); stable. Empty values last. */
|
|
300
|
+
declare function sortRows(rows: ViewRecord[], columns: ViewColumn[], sorting: ViewSorting, locale?: string): ViewRecord[];
|
|
301
|
+
/**
|
|
302
|
+
* Rows grouped by the `grouping` columns, outermost first. Groups follow the
|
|
303
|
+
* column's sorting when it is sorted, else their label (empty group last); rows
|
|
304
|
+
* keep their order inside each group.
|
|
305
|
+
*/
|
|
306
|
+
declare function groupRows(rows: ViewRecord[], columns: ViewColumn[], grouping: string[], sorting?: ViewSorting, locale?: string): ViewGroup[];
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* `createViewController`: the state of one Cervio view without any UI. It loads the
|
|
310
|
+
* definition and the saved column layout, runs the query for the current filters and
|
|
311
|
+
* search, pages, and saves layout changes. Any interface (a table, cards, a kanban,
|
|
312
|
+
* another grid library) renders `getState()` and calls the setters.
|
|
313
|
+
*
|
|
314
|
+
* Framework-agnostic: `subscribe` + `getState` fit React's `useSyncExternalStore`,
|
|
315
|
+
* Vue/Svelte stores or plain callbacks.
|
|
316
|
+
*/
|
|
317
|
+
|
|
318
|
+
interface ViewControllerOptions {
|
|
319
|
+
/** View id (`views.id`). */
|
|
320
|
+
view: string;
|
|
321
|
+
transport: ViewTransport;
|
|
322
|
+
/** Rows per page (default: the view's own page size). */
|
|
323
|
+
pageSize?: number;
|
|
324
|
+
/** Where the column layout is loaded and saved; null: not persisted. Default `shared`. */
|
|
325
|
+
layoutScope?: ViewLayoutScope | null;
|
|
326
|
+
initialFilters?: FiltersState;
|
|
327
|
+
initialSearch?: string;
|
|
328
|
+
/** Ask the host for `total` on the first page (not with a search). Default true. */
|
|
329
|
+
count?: boolean;
|
|
330
|
+
/** Wait before a new search runs (typing). Default 250 ms; 0 runs at once. */
|
|
331
|
+
searchDebounceMs?: number;
|
|
332
|
+
/** Wait before layout changes are saved (dragging a column edge). Default 400 ms. */
|
|
333
|
+
saveLayoutDelayMs?: number;
|
|
334
|
+
locale?: string;
|
|
335
|
+
options?: ViewQueryRequest['options'];
|
|
336
|
+
relations?: ViewQueryRequest['relations'];
|
|
337
|
+
/**
|
|
338
|
+
* With a sorting or a grouping the order must cover every row, so the controller
|
|
339
|
+
* loads the remaining pages, up to this many rows (default 1000). Above it the
|
|
340
|
+
* order covers the loaded rows only (`state.complete` is false).
|
|
341
|
+
*/
|
|
342
|
+
arrangeLoadLimit?: number;
|
|
343
|
+
}
|
|
344
|
+
/** A column with its layout applied. */
|
|
345
|
+
interface ViewStateColumn extends ViewColumn {
|
|
346
|
+
width: number | undefined;
|
|
347
|
+
visible: boolean;
|
|
348
|
+
pinned: 'left' | 'right' | false;
|
|
349
|
+
}
|
|
350
|
+
interface ViewState {
|
|
351
|
+
status: 'loading' | 'ready' | 'error';
|
|
352
|
+
/** Last load or query error; the previous rows stay. */
|
|
353
|
+
error: Error | null;
|
|
354
|
+
definition: ViewDefinition | null;
|
|
355
|
+
/** All columns in layout order. */
|
|
356
|
+
columns: ViewStateColumn[];
|
|
357
|
+
/** Columns to draw: visible, left-pinned first, right-pinned last. */
|
|
358
|
+
visibleColumns: ViewStateColumn[];
|
|
359
|
+
/** Loaded rows, in the sorting of the layout (server order when not sorted). */
|
|
360
|
+
rows: ViewRecord[];
|
|
361
|
+
/** `rows` grouped by the layout's grouping; null when not grouped. */
|
|
362
|
+
groups: ViewGroup[] | null;
|
|
363
|
+
/** Same as `layout.sorting` / `layout.grouping` (never undefined). */
|
|
364
|
+
sorting: ViewSorting;
|
|
365
|
+
grouping: string[];
|
|
366
|
+
/** Every row of the query is loaded (no more pages). */
|
|
367
|
+
complete: boolean;
|
|
368
|
+
/** Loading the remaining pages for a sorting or grouping. */
|
|
369
|
+
loadingAll: boolean;
|
|
370
|
+
/** Rows matching the filters, when the host counted them (no search). */
|
|
371
|
+
total: number | null;
|
|
372
|
+
hasMore: boolean;
|
|
373
|
+
/** A first page is loading (start, new filters or search). */
|
|
374
|
+
loading: boolean;
|
|
375
|
+
loadingMore: boolean;
|
|
376
|
+
filters: FiltersState;
|
|
377
|
+
search: string;
|
|
378
|
+
layout: ViewLayout;
|
|
379
|
+
/** Last failed layout save; the layout stays applied locally. */
|
|
380
|
+
layoutSaveError: Error | null;
|
|
381
|
+
}
|
|
382
|
+
interface ViewController {
|
|
383
|
+
/** Resolves after the definition, the layout and the first page (rejects on error). */
|
|
384
|
+
readonly ready: Promise<void>;
|
|
385
|
+
getState(): ViewState;
|
|
386
|
+
subscribe(listener: (state: ViewState) => void): () => void;
|
|
387
|
+
/** Set or clear (null) the filter of one column. Only filterable columns (`column.filter`). */
|
|
388
|
+
setFilter(field: string, value: FilterValue | null): void;
|
|
389
|
+
setFilters(filters: FiltersState): void;
|
|
390
|
+
clearFilters(): void;
|
|
391
|
+
setSearch(text: string): void;
|
|
392
|
+
refresh(): Promise<void>;
|
|
393
|
+
loadMore(): Promise<void>;
|
|
394
|
+
setColumnSize(key: string, width: number): void;
|
|
395
|
+
setColumnOrder(keys: string[]): void;
|
|
396
|
+
setColumnVisibility(key: string, visible: boolean): void;
|
|
397
|
+
setColumnPinning(pinning: {
|
|
398
|
+
left: string[];
|
|
399
|
+
right: string[];
|
|
400
|
+
}): void;
|
|
401
|
+
/** Sort by these columns (first wins); [] for the server order. Saved with the layout. */
|
|
402
|
+
setSorting(sorting: ViewSorting): void;
|
|
403
|
+
/** Header click: ascending, then descending, then off. `multi` adds to the current sorting. */
|
|
404
|
+
toggleSort(key: string, multi?: boolean): void;
|
|
405
|
+
/** Group by these columns (outermost first, at most 3); [] for no grouping. Saved with the layout. */
|
|
406
|
+
setGrouping(keys: string[]): void;
|
|
407
|
+
/** Choices of a relation filter (records of the linked entity the user can read). */
|
|
408
|
+
filterOptions(key: string, opts?: {
|
|
409
|
+
search?: string;
|
|
410
|
+
limit?: number;
|
|
411
|
+
cursor?: string;
|
|
412
|
+
}): Promise<ViewFilterOptions>;
|
|
413
|
+
/** Write a pending layout change now (e.g. before leaving). */
|
|
414
|
+
flushLayout(): Promise<void>;
|
|
415
|
+
destroy(): void;
|
|
416
|
+
}
|
|
417
|
+
declare function createViewController(opts: ViewControllerOptions): ViewController;
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* `@cervio/plugin-sdk/views`: Cervio views inside a plugin, without UI.
|
|
421
|
+
*
|
|
422
|
+
* Re-exports the engine of `@cervio/view-core` and adds
|
|
423
|
+
* `createPluginViewController`, wired for the plugin sandbox: the API goes through
|
|
424
|
+
* the host relay (declare `/api/v1/views` and `/api/v1/me/view-prefs` in the
|
|
425
|
+
* manifest `cervio_apis`), and the column layout is saved for this plugin only
|
|
426
|
+
* (`plugin:<plugin_key>`), so it never changes the view in Cervio.
|
|
427
|
+
*
|
|
428
|
+
* React users: `useCervioView` from `@cervio/plugin-sdk/views/react`.
|
|
429
|
+
*/
|
|
430
|
+
|
|
431
|
+
type PluginViewControllerOptions = Omit<ViewControllerOptions, 'transport' | 'layoutScope'> & {
|
|
432
|
+
/**
|
|
433
|
+
* Where the column layout is saved. Default: `plugin:<plugin_key>` of this plugin
|
|
434
|
+
* (not saved when the key is unknown, e.g. in a local preview); null never saves.
|
|
435
|
+
* The host refuses `shared` and other plugins' scopes for calls from a plugin
|
|
436
|
+
* (403 `plugin_scope_required`).
|
|
437
|
+
*/
|
|
438
|
+
layoutScope?: ViewLayoutScope | null;
|
|
439
|
+
/** Default: the host origin from the plugin context. */
|
|
440
|
+
baseUrl?: string;
|
|
441
|
+
fetchImpl?: typeof fetch;
|
|
442
|
+
/** Replace the HTTP transport entirely (tests, custom backends). */
|
|
443
|
+
transport?: ViewTransport;
|
|
444
|
+
};
|
|
445
|
+
/** The layout scope of this plugin, or null outside the sandbox. */
|
|
446
|
+
declare function pluginLayoutScope(): ViewLayoutScope | null;
|
|
447
|
+
declare function createPluginViewController(opts: PluginViewControllerOptions): ViewController;
|
|
448
|
+
|
|
449
|
+
export { ViewApiError, activeFilterCount, cellLabel, cellRawValue, createFetchTransport, createPluginViewController, createViewController, filtersStateToRules, filtersToQuery, groupRows, isFilterValueActive, pluginLayoutScope, sortRows };
|
|
450
|
+
export type { DateFilterOp, FetchTransportOptions, FilterValue, FiltersState, NumberFilterOp, PluginViewControllerOptions, ViewColumn, ViewController, ViewControllerOptions, ViewDefinition, ViewFilterOptions, ViewFilterType, ViewGroup, ViewLayout, ViewLayoutScope, ViewQueryFilter, ViewQueryRequest, ViewQueryResponse, ViewRecord, ViewSorting, ViewState, ViewStateColumn, ViewTransport };
|