@tensorify.io/sdk
Version:
TypeScript SDK for developing Tensorify plugins with V2-Alpha definition/execution pattern and legacy compatibility
206 lines (189 loc) • 5.03 kB
text/typescript
/**
* Settings field types for the Tensorify SDK
* Defines how plugin settings are configured and validated
*/
// ========================================
// SETTINGS UI COMPONENT TYPES
// ========================================
/**
* UI component types available for settings fields
*/
export enum SettingsUIType {
// Text Input
INPUT_TEXT = "input-text",
TEXTAREA = "textarea",
// Numeric Input
INPUT_NUMBER = "input-number",
SLIDER = "slider",
// Boolean Input
TOGGLE = "toggle",
CHECKBOX = "checkbox",
// Selection Input
DROPDOWN = "dropdown",
RADIO = "radio",
MULTI_SELECT = "multi-select",
// Advanced Input
CODE_EDITOR = "code-editor",
FILE_UPLOAD = "file-upload",
COLOR_PICKER = "color-picker",
DATE_PICKER = "date-picker",
}
/**
* Data types for settings fields
*/
export enum SettingsDataType {
STRING = "string",
NUMBER = "number",
BOOLEAN = "boolean",
ARRAY = "array",
OBJECT = "object",
FILE = "file",
DATE = "date",
COLOR = "color",
}
// ========================================
// SETTINGS FIELD CONFIGURATION
// ========================================
/**
* Options for dropdown and radio fields
*/
export interface SelectOption {
/** Display text */
label: string;
/** Actual value */
value: any;
/** Optional description */
description?: string;
/** Whether option is selectable */
disabled?: boolean;
}
/**
* Validation rules for settings fields
*/
export interface FieldValidation {
minLength?: number;
maxLength?: number;
/** For numeric fields */
min?: number;
/** For numeric fields */
max?: number;
/** Regex pattern */
pattern?: string;
/** Custom validation function */
customValidator?: string;
/** Custom error message */
errorMessage?: string;
}
/**
* Conditional display rules for settings fields
*/
export interface ConditionalDisplay {
/** Field key this depends on */
dependsOn: string;
/** Condition type */
condition:
| "equals"
| "not-equals"
| "greater-than"
| "less-than"
| "contains"
| "not-contains";
/** Value to compare against */
value: any;
}
/**
* Complete settings field definition
*/
export interface SettingsField {
/** Maps to settings object key */
key: string;
/** UI display label */
label: string;
/** UI component type */
type: SettingsUIType;
/** Underlying data type */
dataType: SettingsDataType;
/** Default value */
defaultValue?: any;
/** Validation requirement */
required: boolean;
/** Help text/tooltip */
description?: string;
/** Validation rules */
validation?: FieldValidation;
/** Show/hide based on other fields */
conditionalDisplay?: ConditionalDisplay;
/** For dropdown/radio fields */
options?: SelectOption[];
/** Input placeholder text */
placeholder?: string;
/** Grouping for UI organization */
group?: string;
/** Field order within group */
order?: number;
}
/**
* Settings field grouping for UI organization
*/
export interface SettingsGroup {
/** Unique group identifier */
id: string;
/** Display label for the group */
label: string;
/** Optional description */
description?: string;
/** Whether the group can be collapsed */
collapsible: boolean;
/** Whether the group is expanded by default */
defaultExpanded: boolean;
/** Field keys in this group */
fields: string[];
/** Display order */
order?: number;
}
// ========================================
// SETTINGS VALIDATION HELPERS
// ========================================
/**
* Type mapping for UI components to data types
* Used for validation during plugin development
*/
export const UI_TYPE_TO_DATA_TYPE_MAP: Record<
SettingsUIType,
SettingsDataType[]
> = {
[]: [SettingsDataType.STRING],
[]: [SettingsDataType.STRING],
[]: [SettingsDataType.NUMBER],
[]: [SettingsDataType.NUMBER],
[]: [SettingsDataType.BOOLEAN],
[]: [SettingsDataType.BOOLEAN],
[]: [
SettingsDataType.STRING,
SettingsDataType.NUMBER,
SettingsDataType.BOOLEAN,
],
[]: [
SettingsDataType.STRING,
SettingsDataType.NUMBER,
SettingsDataType.BOOLEAN,
],
[]: [SettingsDataType.ARRAY],
[]: [SettingsDataType.STRING],
[]: [SettingsDataType.FILE],
[]: [SettingsDataType.COLOR],
[]: [SettingsDataType.DATE],
};
/**
* Default values for different data types
*/
export const DEFAULT_VALUES: Record<SettingsDataType, any> = {
[]: "",
[]: 0,
[]: false,
[]: [],
[]: {},
[]: null,
[]: new Date(),
[]: "#000000",
};