import { AssetFieldValue, BlockContentBase, BlockContentInputBase, Field, MultilinkFieldValue, PluginFieldValue, RichTextFieldValue, TableFieldValue } from "../overlay/_internal.gen.cjs"; import { Prettify } from "./_utils.cjs"; import { Block, BlockFields } from "./block.cjs"; //#region src/generated/types/field.d.ts /** * @deprecated Use {@link RichTextFieldValue} instead. Will be removed in a future major version. */ type RichtextFieldValue = RichTextFieldValue; /** * Registry of all blocks in the space, used to resolve nested `bloks` fields. * A `Block` union resolves nested content against the registry; `NoBlocks` * (the default) leaves it loose (`BlockContentBase`). */ type NoBlocks = false; /** True when `T` is the un-narrowed base `Block` (i.e. no specific block was supplied). */ type IsBaseBlock = [Block] extends [T] ? true : false; /** * Maps a block's ordered `fields` array to its read content object, splitting * required (`required: true`) from optional fields. Each `F` is a member of the * field union, so it provably satisfies `FieldValue`'s `Field` constraint. */ type ContentFields> = Prettify<{ [F in TFields[number] as F extends { required: true; } ? F["name"] : never]: FieldValue; } & { [F in TFields[number] as F extends { required: true; } ? never : F["name"]]?: FieldValue | null; }>; /** Input (write) variant of {@link ContentFields}, resolving each field via {@link FieldValueInput}. */ type ContentFieldsInput> = Prettify<{ [F in TFields[number] as F extends { required: true; } ? F["name"] : never]: FieldValueInput; } & { [F in TFields[number] as F extends { required: true; } ? never : F["name"]]?: FieldValueInput | null; }>; /** * Content object for a single block instance as returned by the Storyblok * Content Delivery API. Without a `TBlock` argument, this is the loose * runtime shape (any block, `_editable` optional). With a schema-typed * `TBlock`, fields are narrowed per the block's `fields`. */ type BlockContent> = IsBaseBlock extends true ? BlockContentBase : TBlock extends any ? Prettify<{ _uid: string; component: TBlock["name"]; _editable?: string; } & ContentFields> : never; /** Input variant of {@link BlockContent} for write operations (creating/updating stories via the MAPI). `_uid` is optional. */ type BlockContentInput> = IsBaseBlock extends true ? BlockContentInputBase : TBlock extends any ? Prettify<{ _uid?: string; component: TBlock["name"]; _editable?: string; } & ContentFieldsInput> : never; type BlocksFieldValue> = BlockContent[]; interface FieldTypeValueMap { text: string; textarea: string; richtext: RichTextFieldValue; markdown: string; /** * Stored and delivered as a string, not a JSON number. The Management API * rejects numeric values ("must be a string with numbers and allow '-' and * '.'"), the editor writes `String(value)`, and `default_value` is a string * for the same reason. An unset field is `''`. */ number: string; datetime: string; boolean: boolean; option: string; options: string[]; asset: AssetFieldValue; multiasset: AssetFieldValue[]; multilink: MultilinkFieldValue; bloks: BlockContentBase[]; table: TableFieldValue; section: never; tab: never; custom: PluginFieldValue; } type IsNestable = T extends { is_nestable: false; } ? false : T extends { is_nestable: true; } ? true : true; type AllowEntry = string | { folder: string; }; /** * Keeps `TBlock` when its `folder` is `TFolder` or any nested subfolder (mirrors * the editor's `isAnywhereInFolder`). This is a best-effort compile-time check, * compared case-insensitively via `Lowercase` so `folder: 'blog'` and a `Blog` * folder ref narrow the same. TypeScript cannot replicate the CLI's full slug at * the type level, so separator/symbol drift (`'My Layout'` vs `'my-layout'`) is * only reconciled at push/validate time — full folder identity is enforced * there, not here. To rely on narrowing, prefer a `defineFolder` ref over a * string path on both the block's `folder` and the field's `allow`: a shared ref * carries the exact path on both sides, so no drift is possible. */ type MatchesFolder = TBlock extends { folder: infer BF extends string; } ? Lowercase extends Lowercase | `${Lowercase}/${string}` ? TBlock : never : never; type ApplyAllow = TField extends { allow: ReadonlyArray; } ? TAllowed extends string ? Extract : TAllowed extends { folder: infer F extends string; } ? TBlocks extends any ? MatchesFolder : never : never : TBlocks extends any ? IsNestable extends true ? TBlocks : never : never; /** * Removes the registry blocks named in `deny`, the `Exclude` counterpart to * {@link ApplyAllow}. The wire `component_denylist` denies by block name only, * so folder refs are not accepted. A `deny` entry naming no known block is * inert: it removes nothing rather than collapsing the field. */ type ApplyDeny = TField extends { deny: ReadonlyArray; } ? Exclude : TBlocks; /** * Resolves the block union a `bloks` field accepts: `allow` narrows the registry * first, then `deny` removes from what is left, so the two compose. */ type ApplyRestrictions = ApplyDeny>; /** * Resolves a `custom` field to its registered plugin value. When the field's * `field_type` is a key of `TFieldPlugins`, the validator output is merged with * the plugin envelope (`plugin`, optional `_uid`); otherwise it falls back to * the untyped {@link PluginFieldValue}. Same shape for read and write. */ type ResolveCustom = TField extends { field_type: infer F extends string; } ? F extends keyof TFieldPlugins ? Prettify : PluginFieldValue : PluginFieldValue; /** Resolves a field definition to its runtime content value type (read). */ type FieldValue> = Prettify, TBlocks, TFieldPlugins>[] : BlockContentBase[] : TField extends { type: "custom"; } ? ResolveCustom : FieldTypeValueMap[TField["type"]]>; /** Resolves a field definition to its input value type (write). */ type FieldValueInput> = Prettify, TBlocks, TFieldPlugins>[] : BlockContentInputBase[] : TField extends { type: "custom"; } ? ResolveCustom : FieldTypeValueMap[TField["type"]]>; //#endregion export { type AssetFieldValue, BlockContent, BlockContentInput, BlocksFieldValue, type Field, FieldValue, FieldValueInput, type MultilinkFieldValue, type PluginFieldValue, type RichTextFieldValue, RichtextFieldValue, type TableFieldValue }; //# sourceMappingURL=field.d.cts.map