@shikiform/hooks 0.1.0 → 0.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.
@@ -1,522 +0,0 @@
1
- import { ArrayKey, useArrayAt } from '@shikiform/react/internal';
2
- import { FormInstance, EffectDef, FormOptions, FieldPath, PathValue, FieldError, EnumOption } from '@shikiform/core/internal';
3
-
4
- /**
5
- * Arguments passed to {@link UseQueryTableOptions.request}.
6
- * `params` is the submitted filter value. `page` / `pageSize` are the form fields.
7
- * In client mode `page` is omitted from submit and a page change does not call `request` again.
8
- */
9
- interface QueryRequestArgs<TParams> {
10
- params: TParams;
11
- page: number;
12
- pageSize: number;
13
- /** Table sort, in priority order. Empty when the table is unsorted. */
14
- sorter: QuerySort[];
15
- /** Table column filters with at least one value, keyed by column key. */
16
- filters: QueryFilters;
17
- signal: AbortSignal;
18
- }
19
- /** One sorted column: the column key (antd `columnKey`, else `dataIndex`) and its direction. */
20
- interface QuerySort {
21
- field: string;
22
- order: 'ascend' | 'descend';
23
- }
24
- /** Column filters keyed by column key. Only columns with a selected value appear. */
25
- type QueryFilters = Record<string, Array<string | number | boolean>>;
26
- /**
27
- * The parts of an antd `Table` `onChange` sorter result the hook reads. Structural, so the hook does not import antd.
28
- * `columnKey` wins over `field` (`dataIndex`); an array `field` is joined with `.`.
29
- */
30
- interface TableSorterLike {
31
- columnKey?: unknown;
32
- field?: unknown;
33
- order?: 'ascend' | 'descend' | null;
34
- }
35
- /** `data` is the rows for this response. `total` is the unpaged count in server mode. */
36
- interface QueryRequestResult<TRow> {
37
- data: TRow[];
38
- total: number;
39
- }
40
- /**
41
- * What a TanStack Query `useQuery` (or a compatible hook) should accept.
42
- * This package does not import `@tanstack/react-query`.
43
- * Forward `placeholderData` to keep the previous rows visible while the next request is in flight.
44
- *
45
- * Pass the same hook on every render. Omit it to use the built-in request runner, which already keeps the previous result.
46
- */
47
- interface QueryHookArgs<TRow> {
48
- queryKey: readonly unknown[];
49
- queryFn: (ctx: {
50
- signal: AbortSignal;
51
- }) => Promise<QueryRequestResult<TRow>>;
52
- placeholderData: <T>(previous: T | undefined) => T | undefined;
53
- }
54
- /** Result shape a compatible `useQuery` hook should return to {@link useQueryTable}. */
55
- interface QueryHookResult<TRow> {
56
- data: QueryRequestResult<TRow> | undefined;
57
- isFetching: boolean;
58
- isPlaceholderData?: boolean;
59
- }
60
- interface UseQueryTableOptions<TValues, TParams, TRow> {
61
- /** Existing form. When omitted, one is created from `initialValues`. */
62
- form?: FormInstance<TValues>;
63
- initialValues?: TValues;
64
- effects?: EffectDef<TValues>[];
65
- fields?: FormOptions<TValues>['fields'];
66
- /**
67
- * Filter payload. A field path (`'params'`) or `(values) => filters`.
68
- * Omit to use the whole form value. `TParams` is that payload; `TRow` is one element of `request`'s `data`.
69
- */
70
- params?: FieldPath<TValues> | ((values: TValues) => TParams);
71
- /** Page field. Default `'page'`. Client mode omits it from submit; server mode leaves the caller's display alone. */
72
- page?: FieldPath<TValues>;
73
- /** Page size field. Default `'pageSize'`. */
74
- pageSize?: FieldPath<TValues>;
75
- /** Selection field, omitted from submit. Default `'selectedKeys'`. Survives page changes. Cleared by submit and reset. */
76
- selectedKeys?: FieldPath<TValues>;
77
- /**
78
- * `server` (default) refetches on submit, reset, refresh, and page change.
79
- * `client` refetches when filters are submitted and slices the cached rows. `page` is omitted from submit.
80
- */
81
- mode?: 'server' | 'client';
82
- request: (args: QueryRequestArgs<TParams>) => Promise<QueryRequestResult<TRow>>;
83
- /**
84
- * Optional TanStack Query (or compatible) hook.
85
- *
86
- * ```tsx
87
- * useQuery: (args) => {
88
- * const query = useQuery({ queryKey: args.queryKey, queryFn: args.queryFn, placeholderData: args.placeholderData })
89
- * return { data: query.data, isFetching: query.isFetching, isPlaceholderData: query.isPlaceholderData }
90
- * }
91
- * ```
92
- */
93
- useQuery?: (args: QueryHookArgs<TRow>) => QueryHookResult<TRow>;
94
- defaultPageSize?: number;
95
- /**
96
- * Array field that receives each response's rows (`data`), so the page can be edited in place
97
- * (`QueryList` in `@shikiform/antd`). Each response also becomes the initial value of that path,
98
- * so the form is not `dirty` (or `edited`) until the user changes a row.
99
- */
100
- rows?: FieldPath<TValues>;
101
- }
102
- interface QueryTableApi<TValues, TParams, TRow> {
103
- form: FormInstance<TValues>;
104
- /** The `rows` option: the array field each page is written into (`undefined` without it). `QueryList` renders it. */
105
- rows?: string;
106
- /** Rows for the current page. The previous page stays up while the next request is in flight. */
107
- data: TRow[];
108
- total: number;
109
- loading: boolean;
110
- fetching: boolean;
111
- isPlaceholderData: boolean;
112
- page: number;
113
- pageSize: number;
114
- selectedKeys: string[];
115
- /** Apply the current filters, go to page 1, clear the selection, reload. */
116
- submit: () => void;
117
- /** Restore initial values, clear the selection, reload. */
118
- reset: () => void;
119
- /** Reload the current page. Filters and selection stay. */
120
- refresh: () => void;
121
- /** Change page. Filters and the selection stay. A new search is what returns to page 1. */
122
- onPageChange: (page: number, pageSize?: number) => void;
123
- setSelectedKeys: (keys: string[]) => void;
124
- /** Current table sort, sent to `request` as `sorter`. */
125
- sorter: QuerySort[];
126
- /** Current column filters, sent to `request` as `filters`. */
127
- filters: QueryFilters;
128
- /** Sort by these columns: back to page 1, reload. The selection stays (the result set is the same rows). */
129
- setSorter: (sorter: QuerySort[]) => void;
130
- /** Filter by these columns: back to page 1, clear the selection, reload. */
131
- setFilters: (filters: QueryFilters | Record<string, unknown>) => void;
132
- /**
133
- * Pass to antd `Table` `onChange` (or call with the same arguments). Sort and filter changes go through
134
- * {@link QueryTableApi.setSorter} / {@link QueryTableApi.setFilters}; a `paginate` action is ignored here, since the
135
- * pager's own `onChange` calls {@link QueryTableApi.onPageChange}.
136
- */
137
- onTableChange: (pagination: unknown, filters?: Record<string, unknown>, sorter?: unknown, extra?: {
138
- action?: string;
139
- }) => void;
140
- /** Controlled `sortOrder` for a column key (`null` when unsorted). */
141
- sortOrderOf: (key: string) => 'ascend' | 'descend' | null;
142
- /** Controlled `filteredValue` for a column key (`null` when unfiltered). */
143
- filteredValueOf: (key: string) => Array<string | number | boolean> | null;
144
- }
145
- /**
146
- * Headless query form + table, in the shape of ProTable / ahooks `useAntdTable`, built on ShikiForm.
147
- * No UI dependency. `QueryList` in `@shikiform/antd` renders it (pass `rows`).
148
- *
149
- * `TValues` is inferred from `initialValues` or `form`. `TRow` is inferred from `request`'s `data`.
150
- * `params: 'filters'` types the request payload as that field's value.
151
- * `params: (values) => ...` types it as the function's return. Omit `params` to send the whole form value.
152
- * `page` is omitted from submit in `client` mode and left alone in `server` mode (a caller's `hidden` / `none` stays).
153
- * `selectedKeys` is always omitted from submit. Neither write touches the field's display.
154
- */
155
- /**
156
- * `useQueryTable<Values>()({ initialValues, … })` fixes the form type (so `[]` / `{}` / union literals are checked
157
- * against `Values`) and still infers the row and the `params` payload. `useQueryTable<Values>(options)` does not:
158
- * one explicit type argument stops inference of the rest.
159
- */
160
- declare function useQueryTable<TValues>(): {
161
- <TRow, const P extends FieldPath<TValues>>(options: UseQueryTableOptions<TValues, PathValue<TValues, P & string>, TRow> & {
162
- params: P;
163
- }): QueryTableApi<TValues, PathValue<TValues, P & string>, TRow>;
164
- <TParams, TRow>(options: UseQueryTableOptions<TValues, TParams, TRow> & {
165
- params: (values: TValues) => TParams;
166
- }): QueryTableApi<TValues, TParams, TRow>;
167
- <TRow = unknown>(options: Omit<UseQueryTableOptions<TValues, TValues, TRow>, 'params'> & {
168
- params?: undefined;
169
- }): QueryTableApi<TValues, TValues, TRow>;
170
- };
171
- declare function useQueryTable<TValues, TRow, const P extends FieldPath<TValues>>(options: UseQueryTableOptions<TValues, PathValue<TValues, P & string>, TRow> & {
172
- params: P;
173
- }): QueryTableApi<TValues, PathValue<TValues, P & string>, TRow>;
174
- declare function useQueryTable<TValues, TParams, TRow>(options: UseQueryTableOptions<TValues, TParams, TRow> & {
175
- params: (values: TValues) => TParams;
176
- }): QueryTableApi<TValues, TParams, TRow>;
177
- declare function useQueryTable<TValues, TRow = unknown>(options: Omit<UseQueryTableOptions<TValues, TValues, TRow>, 'params'> & {
178
- params?: undefined;
179
- }): QueryTableApi<TValues, TValues, TRow>;
180
- /** Built-in runner. Keeps the previous `data` while `isFetching` is true. */
181
- declare function useBuiltinQuery<TRow>(args: QueryHookArgs<TRow>): QueryHookResult<TRow>;
182
-
183
- /** Client pagination (slice the array) or, when `total` is given, a controlled server page. */
184
- interface ArrayTablePagination {
185
- /** Rows per page. Default 10. */
186
- pageSize?: number;
187
- /** Controlled page (server mode). */
188
- current?: number;
189
- /** Server mode: the unpaged count. The array then holds exactly one page and is not sliced. */
190
- total?: number;
191
- /** Hide the pager when everything fits on one page. Default true. */
192
- hideOnSinglePage?: boolean;
193
- /** Called on every page / size change, in both modes. */
194
- onChange?: (page: number, pageSize: number) => void;
195
- }
196
- interface UseArrayTableOptions<TRow = any> {
197
- /** Row id property. Selection and expansion keys are this id (or a stable identity when rows have none). */
198
- rowKey?: string;
199
- /**
200
- * New id for a row that needs one (requires `rowKey`): `copy` always calls it for the copied row, `add` calls it
201
- * when the added row's `rowKey` is `undefined` / `null`. It receives the new row without its id.
202
- * Without it, `copy` drops the id field (the copy is keyed by object identity until you give it one) and
203
- * `add` inserts the row as given.
204
- *
205
- * ```ts
206
- * let next = 1000
207
- * useArrayTable<Row>('rows', { rowKey: 'id', createRowKey: () => ++next })
208
- * ```
209
- */
210
- createRowKey?: (row: TRow) => unknown;
211
- /** `false` shows every row. Default: client pages of 10. */
212
- pagination?: false | ArrayTablePagination;
213
- /** Keep selected keys across page changes. Default false (Pro.formily: a page change clears the selection). */
214
- preserveSelection?: boolean;
215
- /** Controlled selection (e.g. `useQueryTable().selectedKeys`). Pair with `onSelectionChange`. */
216
- selectedKeys?: string[];
217
- onSelectionChange?: (keys: string[]) => void;
218
- /** Expand every expandable row of the current page, again after each page change. */
219
- defaultExpandAll?: boolean;
220
- /** Which rows can expand. Default: every row. */
221
- rowExpandable?: (record: TRow, index: number) => boolean;
222
- /** Runs before a row is removed. A rejected promise keeps the row. The row reports `removing` meanwhile. */
223
- onRemove?: (index: number, record: TRow) => void | Promise<void>;
224
- }
225
- /** One rendered row of the current page. `index` is the index in the whole array. */
226
- interface ArrayTableRow extends ArrayKey {
227
- /** 1-based position across pages (what an index column shows). */
228
- position: number;
229
- }
230
- /**
231
- * Headless state for an array table (`ArrayTable`): page slice, row selection,
232
- * expansion, and row actions over {@link useArrayField}. No UI. `ArrayTable` in `@shikiform/antd` renders it.
233
- */
234
- interface ArrayTableApi<TRow = any> {
235
- path: string;
236
- /** Every row (structure keys), in array order. */
237
- rows: ArrayKey[];
238
- /** Rows of the current page. In server mode, every row in the array. */
239
- pageRows: ArrayTableRow[];
240
- /** The array value (read on render; the hook itself subscribes to structure only). */
241
- record: (index: number) => TRow;
242
- /** 1-based position across pages of the row at array `index` (server paging adds the page offset). */
243
- positionOf: (index: number) => number;
244
- total: number;
245
- page: number;
246
- pageSize: number;
247
- pageCount: number;
248
- /** False when pagination is off, or `hideOnSinglePage` and one page is enough. */
249
- showPager: boolean;
250
- setPage: (page: number, pageSize?: number) => void;
251
- selectedKeys: string[];
252
- setSelectedKeys: (keys: string[]) => void;
253
- toggleSelected: (key: string) => void;
254
- /** Select every row on the current page. */
255
- selectPage: () => void;
256
- /** Invert the selection on the current page (Pro.formily 反选). */
257
- invertPage: () => void;
258
- clearSelection: () => void;
259
- /** Records of the selected rows that are still in the array. */
260
- selectedRecords: () => TRow[];
261
- expandedKeys: string[];
262
- setExpandedKeys: (keys: string[]) => void;
263
- toggleExpanded: (key: string) => void;
264
- isExpandable: (index: number) => boolean;
265
- /** Keys whose `onRemove` is in flight. */
266
- removing: string[];
267
- /** Run `onRemove`, then remove the row. Resolves false when `onRemove` rejected. */
268
- remove: (index: number) => Promise<boolean>;
269
- /** Append a row. By default jumps to the page that shows it. */
270
- add: (row: TRow, options?: {
271
- jump?: boolean;
272
- }) => void;
273
- /**
274
- * Insert a structured copy of the row right after it. With `rowKey`, the copy gets `createRowKey(copy)` as its id,
275
- * or has the id field dropped when there is no `createRowKey`. `transform` runs last and returns the row to insert,
276
- * e.g. `copy(i, (row) => ({ ...row, id: nextId(), name: row.name + ' (副本)' }))`.
277
- */
278
- copy: (index: number, transform?: (copy: TRow, source: TRow) => TRow) => void;
279
- moveUp: (index: number) => void;
280
- moveDown: (index: number) => void;
281
- move: (from: number, to: number) => void;
282
- }
283
- /**
284
- * Array table state: what `ArrayTable` (Pro.formily `ProArrayTable`) does, without the table.
285
- *
286
- * ```tsx
287
- * const table = useArrayTable<Row>('list', { rowKey: 'id', pagination: { pageSize: 5 } })
288
- * table.pageRows.map((row) => <RowScope key={row.key} path={`${table.path}.${row.index}`} index={row.index}>…</RowScope>)
289
- * ```
290
- */
291
- declare function useArrayTable<TRow = any>(name: string, options?: UseArrayTableOptions<TRow>): ArrayTableApi<TRow>;
292
- /** Internal: {@link useArrayTableAt} over an array subscription the caller already holds (`ArrayTable` also needs its `dragProps`). */
293
- declare function useArrayTableOver<TRow = any>(path: string, array: Pick<ReturnType<typeof useArrayAt>, 'keys'>, options?: UseArrayTableOptions<TRow>): ArrayTableApi<TRow>;
294
-
295
- /** What {@link useColumnSettings} needs to know about a column. */
296
- interface ColumnSettingInput {
297
- key: string;
298
- title?: unknown;
299
- width?: number;
300
- /** Start hidden. */
301
- hidden?: boolean;
302
- }
303
- /** One column's user setting. */
304
- interface ColumnSetting {
305
- key: string;
306
- title?: unknown;
307
- show: boolean;
308
- width?: number;
309
- }
310
- /** Table density, cycled by the settings toolbar. */
311
- type TableDensity = 'large' | 'middle' | 'small';
312
- interface ColumnSettingsApi {
313
- /** Every column with its setting, in the user's order. */
314
- items: ColumnSetting[];
315
- /** Keys to render, in order. */
316
- visibleKeys: string[];
317
- toggle: (key: string) => void;
318
- /** Move a column to its final index among all columns. */
319
- move: (from: number, to: number) => void;
320
- setWidth: (key: string, width: number) => void;
321
- density: TableDensity;
322
- setDensity: (density: TableDensity) => void;
323
- /** Restore order, visibility, widths, and density. */
324
- reset: () => void;
325
- /** Move the column `from` to where the column `to` is (drag-and-drop by key). */
326
- moveKey: (from: string, to: string) => void;
327
- /**
328
- * HTML5 drag-and-drop props for one settings row: spread them on the row element. Dropping a row on another moves
329
- * it there. Keep `move` buttons beside them for keyboard users.
330
- */
331
- dragProps: (key: string) => ColumnDragProps;
332
- /** Key being dragged and key under it, for styling. */
333
- drag: {
334
- from: string | null;
335
- over: string | null;
336
- };
337
- }
338
- /** Minimal drag event shape, so the hook does not depend on DOM or React event types. */
339
- interface ColumnDragEvent {
340
- preventDefault: () => void;
341
- dataTransfer?: {
342
- setData?: (format: string, data: string) => void;
343
- effectAllowed?: string;
344
- dropEffect?: string;
345
- } | null;
346
- }
347
- /** What {@link ColumnSettingsApi.dragProps} returns. */
348
- interface ColumnDragProps {
349
- draggable: true;
350
- 'data-dragging'?: 'true';
351
- 'data-drag-over'?: 'true';
352
- onDragStart: (event: ColumnDragEvent) => void;
353
- onDragOver: (event: ColumnDragEvent) => void;
354
- onDragLeave: () => void;
355
- onDrop: (event: ColumnDragEvent) => void;
356
- onDragEnd: () => void;
357
- }
358
- /**
359
- * Headless column settings (Pro.formily `ProSettings`): show / hide, reorder (`move` by index, or drag-and-drop through
360
- * `dragProps`), resize, density.
361
- * Columns added later are appended; removed columns drop out.
362
- */
363
- declare function useColumnSettings(columns: readonly ColumnSettingInput[]): ColumnSettingsApi;
364
-
365
- /** Where a shadow form's values come from when it opens: a value, or a (possibly async) loader. */
366
- type ShadowInit<TValues> = TValues | Partial<TValues> | (() => TValues | Partial<TValues> | Promise<TValues | Partial<TValues>>);
367
- /** Result of {@link ShadowFormApi.confirm}. `ok: false` keeps the shadow open with its errors. */
368
- type ShadowConfirmResult<TValues> = {
369
- ok: true;
370
- values: TValues;
371
- } | {
372
- ok: false;
373
- errors: FieldError[];
374
- };
375
- interface UseShadowFormOptions<TValues, TContext = unknown> {
376
- /** Values the shadow opens with when `open()` gets none. */
377
- initialValues?: TValues;
378
- /** Field declarations for the shadow form (rules, enum, display…), as in `useForm({ fields })`. */
379
- fields?: FormOptions<TValues>['fields'];
380
- /** Effects for the shadow form. They run again on every open (a fresh engine). */
381
- effects?: FormOptions<TValues>['effects'];
382
- /** Other engine options (validateTrigger, schema…). */
383
- formOptions?: Omit<FormOptions<TValues>, 'initialValues' | 'fields' | 'effects'>;
384
- /** Called with the submitted shadow values after validation passes. Throw / reject to keep it open. */
385
- onOk?: (values: TValues, context: TContext | undefined) => void | Promise<void>;
386
- /** Called when the shadow closes without confirming. */
387
- onCancel?: (context: TContext | undefined) => void;
388
- }
389
- /**
390
- * A detached draft form. It never writes the host form by itself; `onOk` decides what to do with the values.
391
- * Every `open()` builds a fresh engine whose `initialValues` are the opened values, so `reset`, `dirty`,
392
- * errors and effects start clean each time. Render its fields with `<Form form={shadow.form}>` (or the
393
- * `ShadowModal` / `ShadowDrawer` / `ShadowPopconfirm` / `ShadowForm` components in `@shikiform/antd`).
394
- */
395
- interface ShadowFormApi<TValues, TContext = unknown> {
396
- /** The current draft engine. Replaced on every `open()`. */
397
- form: FormInstance<TValues>;
398
- /** True between `open()` and `confirm()` success / `cancel()`. */
399
- visible: boolean;
400
- /** True while an async `open()` loader runs. */
401
- loading: boolean;
402
- /** True while `confirm()` validates and runs `onOk`. */
403
- submitting: boolean;
404
- /** Whatever `open()` was given as `context` (e.g. `{ index }` of the row being edited). */
405
- context: TContext | undefined;
406
- /** Open with values (or a loader) and an optional context. A newer `open()` supersedes a pending loader. */
407
- open: (init?: ShadowInit<TValues>, context?: TContext) => Promise<void>;
408
- /** Validate the draft, call `onOk` (and the optional per-call handler), then close. */
409
- confirm: (onOk?: (values: TValues, context: TContext | undefined) => void | Promise<void>) => Promise<ShadowConfirmResult<TValues>>;
410
- /** Close without writing anything. */
411
- cancel: () => void;
412
- }
413
- /**
414
- * Headless ShadowForm (Pro.formily `ShadowForm` / `useShadowForm`): edit a copy of some record in a separate
415
- * form, then hand the validated values back. Components only decide where the draft is rendered
416
- * (modal, drawer, popconfirm, inline).
417
- *
418
- * ```tsx
419
- * const shadow = useShadowForm<Info>({ onOk: (values) => form.setValue('info', values) })
420
- * <Button onClick={() => shadow.open(form.getValue('info'))}>编辑</Button>
421
- * <Modal open={shadow.visible} onOk={() => shadow.confirm()} onCancel={shadow.cancel}>
422
- * <Form form={shadow.form}>…</Form>
423
- * </Modal>
424
- * ```
425
- */
426
- declare function useShadowForm<TValues = Record<string, any>, TContext = unknown>(options?: UseShadowFormOptions<TValues, TContext>): ShadowFormApi<TValues, TContext>;
427
-
428
- /** Remote search for a suggestion box. `signal` aborts when a newer keyword supersedes this call. */
429
- type SuggestFetcher = (keyword: string, ctx: {
430
- signal: AbortSignal;
431
- }) => Promise<readonly EnumOption[]> | readonly EnumOption[];
432
- interface UseSuggestionOptions {
433
- /** Load options for a keyword. */
434
- fetch: SuggestFetcher;
435
- /** Wait this long after the last keystroke. Default 300 ms. */
436
- debounce?: number;
437
- /** Keywords shorter than this clear the options without fetching. Default 1. */
438
- minLength?: number;
439
- }
440
- interface SuggestionApi {
441
- keyword: string;
442
- /** Options for the latest finished keyword, plus remembered selections (so a picked value keeps its label). */
443
- options: EnumOption[];
444
- loading: boolean;
445
- /** Last fetch error, cleared by the next search. */
446
- error: unknown;
447
- /** Set the keyword; fetches after `debounce`. Older requests are aborted and their results dropped. */
448
- search: (keyword: string) => void;
449
- /** Remember options the user picked so their labels survive the next search. */
450
- remember: (options: readonly EnumOption[]) => void;
451
- /** Label for a value from the current or remembered options. */
452
- labelOf: (value: unknown) => string | undefined;
453
- }
454
- /**
455
- * Headless remote suggestion (Pro.formily `Suggestion`): debounced, abortable, last-request-wins search.
456
- * `Suggestion` in `@shikiform/antd` binds it to a field through a searchable Select.
457
- */
458
- declare function useSuggestion(options: UseSuggestionOptions): SuggestionApi;
459
-
460
- /** A cascader node. `isLeaf: false` without `children` means "load on expand". */
461
- interface CascaderOption {
462
- label: string;
463
- value: string | number;
464
- isLeaf?: boolean;
465
- disabled?: boolean;
466
- children?: CascaderOption[];
467
- /** Set while this node's children load. */
468
- loading?: boolean;
469
- }
470
- /** Load the children of `path` (the selected values so far; `[]` is the root). */
471
- type CascaderLoader = (path: Array<string | number>) => Promise<readonly CascaderOption[]> | readonly CascaderOption[];
472
- interface UseLazyCascaderOptions {
473
- load: CascaderLoader;
474
- /** Value paths to show on open (反显). Each path's ancestors are loaded so the labels resolve. */
475
- paths?: ReadonlyArray<ReadonlyArray<string | number>>;
476
- /** Default true. `false` loads nothing (a read view whose value already carries its labels). */
477
- enabled?: boolean;
478
- }
479
- interface LazyCascaderApi {
480
- options: CascaderOption[];
481
- /** True while the root or an echo path loads. */
482
- loading: boolean;
483
- /** Load the children of `path` unless they are loaded or the node is a leaf. */
484
- loadChildren: (path: Array<string | number>) => Promise<void>;
485
- /** Load what is missing for each path (反显). */
486
- ensure: (paths: ReadonlyArray<ReadonlyArray<string | number>>) => Promise<void>;
487
- /** Labels along a value path, as far as the tree is loaded. */
488
- labelsOf: (path: ReadonlyArray<string | number>) => string[];
489
- }
490
- /**
491
- * Headless lazy cascader (Pro.formily `CascaderPlus`): root on mount, children on demand, a loader shared by
492
- * every level, and echo of an existing value by loading each ancestor level. A tree known up front is not this
493
- * hook's job: give it to `<Field enum>` and use `Cascader`. `CascaderPlus` in
494
- * `@shikiform/antd` renders it with Ant Design's Cascader and adds `multiple` / `labelInValue`.
495
- */
496
- declare function useLazyCascader(options: UseLazyCascaderOptions): LazyCascaderApi;
497
- type Key = string | number;
498
- /**
499
- * The value paths a cascader field holds: one path, or (`multiple`) several. A `labelInValue` level
500
- * (`{ label, value }`) contributes its `value`.
501
- */
502
- declare function cascaderPaths(value: unknown, multiple?: boolean): Key[][];
503
- interface UseCascaderLabelsOptions {
504
- value: unknown;
505
- multiple?: boolean;
506
- /** The same loader the editable cascader uses. Without it, levels without a label show their value. */
507
- load?: CascaderLoader;
508
- }
509
- interface CascaderLabelsApi {
510
- /** One label list per path. A level shows its `labelInValue` label, else the loaded label, else its value. */
511
- labels: string[][];
512
- /** True while the tree loads the ancestors needed to resolve a bare value. */
513
- loading: boolean;
514
- }
515
- /**
516
- * Labels for a cascader value, for a read view (`readPretty`). A `labelInValue` value already carries its labels and
517
- * loads nothing. A bare value (`['zj', 'hz']`) is resolved by loading each ancestor level through `load`, the same way
518
- * {@link useLazyCascader} echoes a value into the editor.
519
- */
520
- declare function useCascaderLabels(options: UseCascaderLabelsOptions): CascaderLabelsApi;
521
-
522
- export { type ArrayTableApi as A, useBuiltinQuery as B, type CascaderLabelsApi as C, useCascaderLabels as D, useColumnSettings as E, useLazyCascader as F, useQueryTable as G, useShadowForm as H, useSuggestion as I, cascaderPaths as J, useArrayTableOver as K, type LazyCascaderApi as L, type QueryFilters as Q, type ShadowFormApi as S, type TableDensity as T, type UseShadowFormOptions as U, type ArrayTablePagination as a, type ArrayTableRow as b, type CascaderLoader as c, type CascaderOption as d, type ColumnDragEvent as e, type ColumnDragProps as f, type ColumnSetting as g, type ColumnSettingInput as h, type ColumnSettingsApi as i, type QueryHookArgs as j, type QueryHookResult as k, type QueryRequestArgs as l, type QueryRequestResult as m, type QuerySort as n, type QueryTableApi as o, type ShadowConfirmResult as p, type ShadowInit as q, type SuggestFetcher as r, type SuggestionApi as s, type TableSorterLike as t, type UseArrayTableOptions as u, type UseCascaderLabelsOptions as v, type UseLazyCascaderOptions as w, type UseQueryTableOptions as x, type UseSuggestionOptions as y, useArrayTable as z };