/** * This Source Code is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * Copyright (c) Infonomic Company Limited */ import type { MultiCollectionDefinition } from '@byline/core'; /** * Row rendering strategy, in priority order: * 1. `CollectionAdminConfig.itemView` — a ColumnDefinition[] from the target * admin config. Each row renders the declared columns side-by-side, * reusing any column formatters (thumbnail, date, etc). * 2. Explicit `displayField` prop on this component (forwarded from * `RelationField.displayField`). * 3. `CollectionDefinition.useAsTitle` on the target. * 4. First top-level `text` field on the target. * * Paths 2–4 render a single-line label (primary) + `path` (secondary). */ /** * One confirmed pick. `record` is the raw document the picker row rendered — * the caller can use it to show the selected value in its own tile without a * refetch. The fields available on `record` are whatever `resolveSelectFields` * asked the listing endpoint for (picker columns + `useAsTitle` + * `displayField`), so any display surface downstream of the picker that also * renders from those same columns will find the data it needs. */ export interface RelationPickerSelection { targetDocumentId: string; targetCollectionId: string; record?: Record; } interface RelationPickerBaseProps { /** The target collection path (e.g. `'media'`). */ targetCollectionPath: string; /** The target collection definition (used for labels + displayField fallback). */ targetDefinition?: MultiCollectionDefinition | null; /** Explicit display field to render as row label. */ displayField?: string; /** * Extra field names to load into each row's `record.fields` beyond the * display columns. Not rendered — available to the `onSelect` consumer * (e.g. the inline-image modal seeding alt-text from the picked media). * * Pass a stable (module-level) array — this feeds the fetch effect's * dependency list, so a fresh array each render would refetch on every * render. */ extraSelectFields?: string[]; /** Modal open/close state. */ isOpen: boolean; /** Called when the user dismisses the modal. */ onDismiss: () => void; } interface RelationPickerSingleProps extends RelationPickerBaseProps { /** Single-select (default): clicking a row selects it; confirm returns one pick. */ multiple?: false; /** Called with the picked selection when the user confirms. */ onSelect: (selection: RelationPickerSelection) => void; onSelectMany?: never; excludeIds?: never; } interface RelationPickerMultiProps extends RelationPickerBaseProps { /** * Multi-select mode (`hasMany` widgets): rows toggle a check state and the * confirm action returns every selection in pick order — several picks in * one trip instead of reopening the modal per item. */ multiple: true; /** Called with the full selection set (pick order) when the user confirms. */ onSelectMany: (selections: RelationPickerSelection[]) => void; onSelect?: never; /** * Target ids already present on the caller's value. Rendered as disabled * "already added" rows so the same target can't be picked twice. */ excludeIds?: string[]; } type RelationPickerProps = RelationPickerSingleProps | RelationPickerMultiProps; export declare const RelationPicker: ({ targetCollectionPath, targetDefinition, displayField, extraSelectFields, isOpen, multiple, excludeIds, onSelect, onSelectMany, onDismiss, }: RelationPickerProps) => import("react").JSX.Element; export {};