import type { EditorNodeTypeProvider, EditorSchemaContribution, Element, PropertyValueDescriptor, PropertyValueOf, SchemaContentRootContribution, SchemaElement, SchemaElementShapeFor, SchemaElementPropertyDefinition, SchemaPropertyHandle, SchemaPropertyKey, SchemaProperty, SchemaPropertyDefinition, SchemaTarget, SchemaTextProperty, SchemaTextPropertyDefinition, SchemaText, Text, EditorSchemaSourceProvider, } from '../../facade'; import type { AnyBasePluginDefinition, PluginSchema, PluginSchemaDeclaration, } from './PluginDefinition'; type IsAny = 0 extends 1 & T ? true : false; type ResolvePluginSchemaDeclaration = TSchema extends ( ...args: never[] ) => infer TDeclaration ? Extract : Extract; type InferPluginSchemaDeclaration = C extends Readonly<{ schema: infer TSchema extends PluginSchemaDeclaration; }> ? ResolvePluginSchemaDeclaration : never; type PluginElementPropertyHandles = TDeclaration extends Readonly<{ element: Readonly<{ properties?: infer TProperties extends Readonly< Record >; }>; }> ? Readonly<{ [TKey in Extract]: SchemaPropertyHandle< TKey, PropertyValueOf, 'element' >; }> : Readonly>; type PluginDeclaredPropertyKey = TProperty extends Readonly<{ key: infer TKey extends SchemaPropertyKey }> ? TKey : TLocalId; type PluginDeclaredPropertyHandles = TDeclaration extends Readonly<{ properties: infer TProperties; }> ? TProperties extends Readonly< Record< string, | SchemaElementPropertyDefinition | SchemaProperty | SchemaTextPropertyDefinition > > ? Readonly<{ [ TLocalId in Extract ]: SchemaPropertyHandle< PluginDeclaredPropertyKey, TProperties[TLocalId] extends Readonly<{ value: infer TDescriptor extends PropertyValueDescriptor; }> ? PropertyValueOf : never, TProperties[TLocalId] extends Readonly<{ placement: infer TPlacement extends 'element' | 'text'; }> ? TPlacement : never >; }> : Readonly> : Readonly>; /** Additional compiled properties visible only while authoring one plugin. */ export type InferPluginAdditionalSchemaPropertyHandles< C extends AnyBasePluginDefinition, > = IsAny extends true ? Readonly> : Readonly< PluginElementPropertyHandles> & PluginDeclaredPropertyHandles> >; type PluginWritablePropertyEntry< TOwnerName extends string, TLocalId extends string, TKey extends SchemaPropertyKey, TDescriptor extends PropertyValueDescriptor, TPlacement extends 'element' | 'text', > = Readonly<{ descriptor: TDescriptor; key: TKey; localId: TLocalId; ownerName: TOwnerName; placement: TPlacement; unaliased: TKey extends string ? TKey extends TLocalId ? TLocalId extends TKey ? true : false : false : false; value: PropertyValueDescriptor extends TDescriptor ? unknown : PropertyValueOf; }>; type PluginElementWritablePropertyEntries< C extends AnyBasePluginDefinition, TDeclaration, > = TDeclaration extends Readonly<{ element: Readonly<{ properties?: infer TProperties extends Readonly< Record >; }>; }> ? { [ TLocalId in Extract ]: PluginWritablePropertyEntry< C['name'], TLocalId, TLocalId, TProperties[TLocalId], 'element' >; }[Extract] : never; type PluginDeclaredWritablePropertyEntries< C extends AnyBasePluginDefinition, TDeclaration, > = TDeclaration extends Readonly<{ properties: infer TProperties }> ? TProperties extends Readonly< Record< string, | SchemaElementPropertyDefinition | SchemaProperty | SchemaTextPropertyDefinition > > ? { [ TLocalId in Extract ]: PluginWritablePropertyEntry< C['name'], TLocalId, PluginDeclaredPropertyKey, TProperties[TLocalId] extends Readonly<{ value: infer TDescriptor extends PropertyValueDescriptor; }> ? TDescriptor : PropertyValueDescriptor, TProperties[TLocalId] extends Readonly<{ placement: infer TPlacement extends 'element' | 'text'; }> ? TPlacement : never >; }[Extract] : never : never; type PluginMarkWritablePropertyEntry< C extends AnyBasePluginDefinition, TDeclaration, > = TDeclaration extends Readonly<{ mark: infer TMark }> ? PluginWritablePropertyEntry< C['name'], C['name'], TMark extends Readonly<{ key: infer TKey extends string }> ? TKey : C['name'], PluginMarkDescriptor, 'text' > : never; /** Shallow writable property identities owned by one plugin definition. */ export type InferPluginWritablePropertyEntries< C extends AnyBasePluginDefinition, > = IsAny extends true ? PluginWritablePropertyEntry< string, string, SchemaPropertyKey, PropertyValueDescriptor, 'element' | 'text' > : | PluginElementWritablePropertyEntries< C, InferPluginSchemaDeclaration > | PluginDeclaredWritablePropertyEntries< C, InferPluginSchemaDeclaration > | PluginMarkWritablePropertyEntry>; /** Persisted element identity owned by an element plugin. */ export type InferPluginElementType = IsAny extends true ? string : [InferPluginSchemaDeclaration] extends [never] ? never : InferPluginSchemaDeclaration extends Readonly<{ element: infer TElement extends SchemaElement; }> ? TElement extends Readonly<{ type: infer TType extends string }> ? TType : C['name'] : never; /** Persisted primary property identity owned by a mark plugin. */ export type InferPluginMarkKey = IsAny extends true ? string : [InferPluginSchemaDeclaration] extends [never] ? never : InferPluginSchemaDeclaration extends Readonly<{ mark: infer TMark; }> ? TMark extends Readonly<{ key: infer TKey extends string }> ? TKey : C['name'] : never; /** Value stored by a plugin's primary mark. */ export type InferPluginMarkValue = IsAny extends true ? unknown : C extends Readonly<{ markValue: infer TValue }> ? TValue : [InferPluginSchemaDeclaration] extends [never] ? never : InferPluginSchemaDeclaration extends Readonly<{ mark: infer TMark; }> ? PluginMarkDescriptor extends PropertyValueDescriptor< infer TValue > ? TValue : never : never; /** Primary persisted schema identity, never plugin capability identity. */ export type InferPluginDocumentType = [ InferPluginElementType, ] extends [never] ? InferPluginMarkKey : InferPluginElementType; export type InferPluginSchema = IsAny extends true ? PluginSchema | null : C extends Readonly<{ schema: infer TSchema extends PluginSchemaDeclaration; }> ? TSchema : null; type PluginDeclarationProperties = TDeclaration extends Readonly<{ properties: infer TProperties; }> ? TProperties extends Readonly< Record > ? ReadonlyArray< { [ TLocalId in Extract ]: TProperties[TLocalId] extends infer TProperty extends | SchemaProperty | SchemaPropertyDefinition ? TProperty extends SchemaProperty ? TProperty : Readonly<{ key: TLocalId }> & TProperty : never; }[Extract] > : readonly [] : readonly []; type PluginDeclarationContentRoots = TDeclaration extends Readonly<{ contentRoots: infer TContentRoots extends readonly SchemaContentRootContribution[]; }> ? TContentRoots : readonly []; type PluginMarkDescriptor = TMark extends PropertyValueDescriptor ? TMark : TMark extends Readonly<{ property: infer TDescriptor extends PropertyValueDescriptor; }> ? TDescriptor : never; type PluginMarkTarget = TMark extends Readonly<{ target: infer TTarget extends SchemaTarget; }> ? TTarget : undefined; type PluginMarkProperties = TDeclaration extends Readonly<{ mark: infer TMark }> ? readonly [ SchemaTextProperty< TType, PluginMarkDescriptor, PluginMarkTarget >, ] : readonly []; type LowerPluginSchemaDeclaration< TDeclaration, TElementType extends string, TPropertyKey extends string, > = Readonly<{ contentRoots: PluginDeclarationContentRoots; elements: TDeclaration extends Readonly<{ element: infer TElement extends SchemaElement; }> ? Readonly<{ [TKey in TElementType]: TElement }> : Readonly>; properties: readonly [ ...PluginDeclarationProperties, ...PluginMarkProperties, ]; }>; type InferExactPluginSchemaContributionForDefinition< C extends AnyBasePluginDefinition, > = C extends Readonly<{ schema: infer TSchema extends PluginSchemaDeclaration; }> ? LowerPluginSchemaDeclaration< ResolvePluginSchemaDeclaration, InferPluginElementType, InferPluginMarkKey > : never; export type InferExactPluginSchemaContribution< C extends AnyBasePluginDefinition, > = C extends unknown ? InferExactPluginSchemaContributionForDefinition : never; export type InferPluginSchemaContribution = [ InferExactPluginSchemaContribution, ] extends [never] ? EditorSchemaContribution : InferExactPluginSchemaContribution; type InferPluginOwnSchemaContribution = IsAny extends true ? EditorSchemaContribution : string extends C['name'] ? EditorSchemaContribution : InferExactPluginSchemaContribution; type PluginOwnSchemaSource = EditorSchemaSourceProvider<() => InferPluginOwnSchemaContribution>; type InferPluginOwnElement = [ InferPluginOwnSchemaContribution, ] extends [never] ? never : Extract>, Element>; type InferPluginOwnText = [ InferPluginOwnSchemaContribution, ] extends [never] ? never : Extract>, Text>; /** Exact descriptor-local node shapes, excluding installed dependencies. */ export type InferPluginNodeTypeProvider = EditorNodeTypeProvider< () => InferPluginOwnElement, () => InferPluginOwnText >;