import type { EntityContext } from '#blokkli/types'; import type { DefinitionProvider } from './definition.js'; import type { DirectiveProvider } from './directive.js'; import type { StateProvider } from './state.js'; import type { BlockDefinitionProvider } from './types.js'; import type { BlocksProvider } from './blocks.js'; /** * Simplified field type for editable fields. */ export type FieldValueType = 'plain' | 'markup'; /** * A text field value as provided by the adapter or directive system. */ export type TextFieldValue = { uuid: string; fieldName: string; value: string; fieldType: FieldValueType; entityType: string; entityBundle: string; }; /** * A droppable field value (ordered list of referenced entity IDs currently in * the field) as provided by the adapter's mapped state. */ export type DroppableFieldValue = { uuid: string; fieldName: string; ids: string[]; entityType: string; entityBundle: string; }; /** * The result of reading a field value. */ export type ReadFieldValueResult = { value: string; fieldType: FieldValueType; }; export type FieldValueProvider = { /** * Resolve an editable field config to its simplified type. * Returns 'plain' for text fields, 'markup' for rich text/frame fields, null for unsupported. */ resolveFieldType: (entityType: string, bundle: string, fieldName: string) => FieldValueType | null; /** * Read the current value of an editable field on a block or entity. * Tries the registered getValue() callback first, falls back to DOM element reading. */ readValue: (entityType: string, uuid: string, bundle: string, fieldName: string, fieldType: FieldValueType) => string; /** * Read the current value and field type of an editable field. * * Uses the correct strategy based on the field's configuration: * 1. Component editables — use getValue() callback * 2. Mutated props — read from mutatedItemProps or mutatedEntity * 3. Direct DOM — read innerHTML (markup) or textContent (plain) */ readFieldValue: (fieldName: string, host: EntityContext) => ReadFieldValueResult | null; /** * Get all text field values from the page. * Reads from mapped state if available, falls back to reading from directive system. */ getTextFieldValues: () => TextFieldValue[]; /** * Get all droppable field values (item counts) from the mapped state. * Returns an empty array when the adapter hasn't populated this. */ getDroppableFieldValues: () => DroppableFieldValue[]; /** * Get the current number of items in a droppable field. * Reads from mapped state; returns 0 when the adapter hasn't populated it. */ getDroppableFieldCount: (fieldName: string, host: EntityContext) => number; /** * Get the ordered list of referenced entity IDs currently in a droppable * field. Reads from mapped state; returns an empty array when the adapter * hasn't populated it. */ getDroppableFieldIds: (fieldName: string, host: EntityContext) => string[]; }; export default function fieldValueProvider(directive: DirectiveProvider, state: StateProvider, types: BlockDefinitionProvider, definitions: DefinitionProvider, blocks: BlocksProvider): FieldValueProvider;