feat: add docs and dev plugins

This commit is contained in:
SethBurkart123
2025-03-18 22:15:40 +11:00
parent 7a76d3f4eb
commit 1c63c06b72
18 changed files with 3855 additions and 54 deletions
+108
View File
@@ -0,0 +1,108 @@
import type { PluginSettings } from './types';
// Base interfaces for our settings
interface BaseSettingOptions {
title: string;
description?: string;
}
interface BooleanSettingOptions extends BaseSettingOptions {
default: boolean;
}
interface StringSettingOptions extends BaseSettingOptions {
default: string;
maxLength?: number;
pattern?: string;
}
interface NumberSettingOptions extends BaseSettingOptions {
default: number;
min?: number;
max?: number;
step?: number;
}
interface SelectSettingOptions<T extends string> extends BaseSettingOptions {
default: T;
options: readonly T[];
}
// The actual decorators
export function BooleanSetting(options: BooleanSettingOptions): PropertyDecorator {
return (target: Object, propertyKey: string | symbol) => {
// Ensure the settings property exists on the constructor's prototype
const proto = target.constructor.prototype;
if (!proto.hasOwnProperty('settings')) {
proto.settings = {};
}
// Add the setting to the prototype's settings object
proto.settings[propertyKey] = {
type: 'boolean',
...options
};
};
}
export function StringSetting(options: StringSettingOptions): PropertyDecorator {
return (target: Object, propertyKey: string | symbol) => {
// Ensure the settings property exists on the constructor's prototype
const proto = target.constructor.prototype;
if (!proto.hasOwnProperty('settings')) {
proto.settings = {};
}
// Add the setting to the prototype's settings object
proto.settings[propertyKey] = {
type: 'string',
...options
};
};
}
export function NumberSetting(options: NumberSettingOptions): PropertyDecorator {
return (target: Object, propertyKey: string | symbol) => {
// Ensure the settings property exists on the constructor's prototype
const proto = target.constructor.prototype;
if (!proto.hasOwnProperty('settings')) {
proto.settings = {};
}
// Add the setting to the prototype's settings object
proto.settings[propertyKey] = {
type: 'number',
...options
};
};
}
export function SelectSetting<T extends string>(options: SelectSettingOptions<T>): PropertyDecorator {
return (target: Object, propertyKey: string | symbol) => {
// Ensure the settings property exists on the constructor's prototype
const proto = target.constructor.prototype;
if (!proto.hasOwnProperty('settings')) {
proto.settings = {};
}
// Add the setting to the prototype's settings object
proto.settings[propertyKey] = {
type: 'select',
...options
};
};
}
// Base plugin class that handles settings
export abstract class BasePlugin<T extends PluginSettings = PluginSettings> {
// The settings property will be populated by decorators
settings: T = {} as T;
constructor() {
// Copy settings from the prototype to the instance
// This ensures that each instance has its own settings object
if (this.constructor.prototype.settings) {
this.settings = { ...this.constructor.prototype.settings };
}
}
}
+10 -5
View File
@@ -1,27 +1,32 @@
import ReactFiber from '@/seqta/utils/ReactFiber';
interface BooleanSetting {
export interface BooleanSetting {
type: 'boolean';
default: boolean;
title: string;
description?: string;
}
interface StringSetting {
export interface StringSetting {
type: 'string';
default: string;
title: string;
description?: string;
maxLength?: number;
pattern?: string;
}
interface NumberSetting {
export interface NumberSetting {
type: 'number';
default: number;
title: string;
description?: string;
min?: number;
max?: number;
step?: number;
}
interface SelectSetting<T extends string> {
export interface SelectSetting<T extends string> {
type: 'select';
options: readonly T[];
default: T;
@@ -29,7 +34,7 @@ interface SelectSetting<T extends string> {
description?: string;
}
type PluginSetting = BooleanSetting | StringSetting | NumberSetting | SelectSetting<string>;
export type PluginSetting = BooleanSetting | StringSetting | NumberSetting | SelectSetting<string>;
export type PluginSettings = {
[key: string]: PluginSetting;