function
definePluginField
Connect a new Go field type to its default Svelte editor and the functions that check its values.
Example
import {
defineAdminPlugin,
definePluginField
} from '@riducms/plugin/authoring/v1';
import ColorField from './color-field.svelte';
import { decodeColor } from './value';
export const colorAdminPlugin = defineAdminPlugin({
key: 'color',
pairingVersion: 1,
fields: {
color: definePluginField({
component: ColorField,
decodeValue: decodeColor
})
}
});Arguments
| Argument | Description |
|---|---|
definition | Required object containing component and decodeValue. Add decodeInput for a different write shape, or decodeConfig for editor settings. |
Field editor options
| Property | Type | Description |
|---|---|---|
component | Component< | Required. The Svelte editor. It reads field.value, writes unsaved changes with field.set(...), and receives config only when decodeConfig is supplied. |
decodeValue | (value: unknown) => Value | Required. Check a saved value and return the value type the component can read. Throw an Error for invalid data. Runs synchronously; Ridu handles null and undefined separately. |
decodeInput | (value: unknown) => Input | Optional. Check values passed to field.set when the server accepts a different shape from saved data. Defaults to decodeValue when omitted. It must return synchronously. |
decodeConfig | (value: unknown) => Config | Optional. Check Go field settings and return the component’s config prop. Without this decoder, the plugin’s field settings must be empty and the component receives no config prop. |
Returns
A frozen PluginFieldRegistration with type: "plugin", retaining inferred saved-value and input types. Put it under the Go field-type key in defineAdminPlugin({ fields: ... }). The helper does not create a Go field or register server validation.
PluginFieldRegistration<Value, Input, "plugin"> & { readonly fieldType?: never; }How it works
Use this for a new type such as color.Field("accent"). The fields map key must match PluginFieldType.Key in the Go descriptor. Do not put app: on that key; app:name belongs to application field editors.
For a character counter or another input on an existing text, number, or checkbox field in one application, use defineFieldEditor. For a named alternative supplied by a plugin, use defineFieldComponent.
Value describes data returned by the server. Input describes data sent back and defaults to Value. Config is inferred from decodeConfig. TypeScript usually infers these from the decoder functions; explicit generic arguments are unnecessary.
When reading an unsaved form value, Ridu tries decodeValue first and then decodeInput if a separate input decoder is present. field.value may therefore contain either saved data or a pending edit.
Keep decoders synchronous and free of side effects. They may run on every read. Throw an Error with a useful message for unsupported data; field.rawValue remains available when a plugin needs to display or recover it.
Browser decoding does not replace the Go validator. field.set(...) changes the unsaved form; the document Save action sends it to the server for validation.
The example is the color plugin’s admin entry. Follow Build a field plugin for its complete Svelte editor, value decoder, and Go implementation.
Full signature (4 overloads)
function definePluginField<Value, Config, Input>(
definition: FieldDefinition<
Value,
Config,
"plugin",
Input,
> & {
decodeConfig: (value: unknown) => Config
decodeInput: (value: unknown) => Input
},
): PluginFieldRegistration<Value, Input, "plugin"> & { readonly fieldType?: never; }
function definePluginField<Value, Config>(
definition: FieldDefinition<
Value,
Config,
"plugin",
> & {
decodeConfig: (value: unknown) => Config
decodeInput?: never
},
): PluginFieldRegistration<Value, Value, "plugin"> & { readonly fieldType?: never; }
function definePluginField<Value, Input>(
definition: FieldDefinition<
Value,
undefined,
"plugin",
Input,
> & {
decodeInput: (value: unknown) => Input
decodeConfig?: never
},
): PluginFieldRegistration<Value, Input, "plugin"> & { readonly fieldType?: never; }
function definePluginField<Value>(
definition: FieldDefinition<
Value,
undefined,
"plugin",
> & {
decodeConfig?: never
decodeInput?: never
},
): PluginFieldRegistration<Value, Value, "plugin"> & { readonly fieldType?: never; }Related types
PluginFieldRegistrationHelper return type that preserves saved-value and write-value types for generated Go/admin compatibility checks. Let TypeScript infer it from your registration; annotating everything as
RegisteredPluginFieldwould lose this information.PluginFieldPropsValues and tools Ridu passes to a plugin’s Svelte field editor.