import type { ComputedRef } from 'vue'; import type { BlockOptionDefinition } from './blockOptions.js'; import type { AdapterContext } from '../editor/adapter/index.js'; import type { BlockBundleWithNested, FieldListItemTyped, GlobalOptionsKey, ValidChunkNames, ValidFieldListTypes, ValidGlobalConfigKeys, BundleProps, ValidProviderTypes } from '#blokkli-build/generated-types'; import type { BlockDefinitionInputBase, BlockDefinitionRenderForBase, BlockDefinitionRenderForFieldListBase, BlockDefinitionRenderForFieldListTypeBase, BlockDefinitionRenderForParentBase, BlockDefinitionRenderForProviderTypeBase, BlokkliDefinitionInputEditorBase, FragmentDefinitionInputBase, ProviderDefinitionInputBase } from './../../global/types/definitions.js'; import type { GlobalOptionsType } from '#blokkli-build/definitions'; import type { BlokkliIcon } from '#blokkli-build/icons'; import type { ComplexOptionTypeMap } from '#blokkli-build/complex-option-types'; import type { BlokkliProviderEntityContext } from './provider.js'; type GetType = T extends { options: infer O; } ? T extends { type: 'checkboxes'; } ? Array : keyof O : T extends { type: 'checkbox'; } ? boolean : T extends { type: 'range'; } ? number : T extends { type: 'number'; nullable: true; } ? number | undefined : T extends { type: 'number'; } ? number : T extends { type: 'json'; dataType: infer D; } ? D extends keyof ComplexOptionTypeMap ? ComplexOptionTypeMap[D] : any : T extends { type: 'json'; } ? any : string; export type BlockDefinitionOptionsInput = { [key: string]: BlockOptionDefinition; }; type WithOptions = { [K in keyof T]: GetType; }; type GlobalOptionsKeyTypes = { [K in T[number]]: GetType; }; export type BundleKey = keyof BundleProps; export type DefineBlokkliContext = { /** * The UUID of the item. */ uuid: string; /** * The index of the item in the field list. */ index: ComputedRef; /** * Whether the item is being displayed in an editing context. * * Use `import.meta.blokkliEditing` instead, which will only * include "editing related code" in the editor bundle and remove it from * the main ("public") bundle. * * @deprecated */ isEditing: boolean; /** * The item type name (e.g. "teaser_list") of the parent item if this item is nested. */ parentType: ComputedRef; /** * The type of the field list the item is part of. */ fieldListType: ComputedRef; /** * All sibling blocks (including this one) that are in the same field. */ siblings: ComputedRef; /** * All blocks that are in the root field (direct child of ). */ rootBlocks: ComputedRef; /** * The reactive runtime options. * * This includes both the locally defined options and the inherited global * options. */ options: ComputedRef<(T extends BlockDefinitionOptionsInput ? WithOptions : object) & (G extends ValidGlobalConfigKeys ? GlobalOptionsKeyTypes : object)>; /** * The provider context. */ provider: ComputedRef; /** * Whether the block is currently selected in the editor. Only available during editing. */ isSelected?: ComputedRef; }; export type DefineProviderContext = { /** * The reactive runtime options. * * This includes both the locally defined options and the inherited global * options. */ options: ComputedRef<(T extends BlockDefinitionOptionsInput ? WithOptions : object) & (G extends ValidGlobalConfigKeys ? GlobalOptionsKeyTypes : object)>; }; type DetermineVisibleOptionsContext = { options: (T extends BlockDefinitionOptionsInput ? WithOptions : object) & (G extends ValidGlobalConfigKeys ? GlobalOptionsKeyTypes : object); parentType: BlockBundleWithNested | undefined; fieldListType: ValidFieldListTypes; props: B extends BundleKey ? BundleProps[B] : Record; entity: AdapterContext; }; type ExtractGlobalOptions = G[number] extends GlobalOptionsKey ? G[number] : never; type CombineKeysAndGlobalOptions = keyof T | ExtractGlobalOptions>; export type BlokkliDefinitionInputEditor> = Omit, 'determineVisibleOptions'> & { /** * Determine which options should be visible in the editor based on the * given context. * * If a method is defined, it is called whenever any of the options change. */ determineVisibleOptions?: (ctx: DetermineVisibleOptionsContext) => Array>; }; export type BlockDefinitionRenderForParent = BlockDefinitionRenderForParentBase; export type BlockDefinitionRenderForFieldList = BlockDefinitionRenderForFieldListBase; export type BlockDefinitionRenderForFieldListType = BlockDefinitionRenderForFieldListTypeBase; export type BlockDefinitionRenderForProviderType = BlockDefinitionRenderForProviderTypeBase; export type BlockDefinitionRenderFor = BlockDefinitionRenderForBase; export type BlockDefinitionInput = Omit, 'editor'> & { /** * Settings for the behaviour in the editor. */ editor?: BlokkliDefinitionInputEditor; }; export type RuntimeBlockDefinitionInput = { bundle: string; }; export type FragmentDefinitionInput = Omit, 'editor'> & { /** * Settings for the behaviour in the editor. */ editor?: BlokkliDefinitionInputEditor; }; export type ProviderDefinitionInput = ProviderDefinitionInputBase; export {};