+
{tab.description}
+
+ {list.map((item, idx) => {
+ const others = list.filter((_, i) => i !== idx).map((n) => n.name);
+ const duplicate = !!item.name && others.includes(item.name);
return (
-
+ onToggleEnabled(idx, v)}
+ onEdit={() => onEdit(idx)}
+ onDelete={() => onDelete(idx)}
+ />
);
})}
@@ -543,211 +388,39 @@ function SegmentedField
({
);
}
-function SelectField({
- label,
- value,
- options,
- onChange,
- className,
-}: {
- label: string;
- value: T;
- options: ReadonlyArray>;
- onChange: (v: T) => void;
- className?: string;
-}) {
+// ─────────────── empty + loading ───────────────
+
+function EmptyState() {
return (
-
-
-
+
);
}
-const ADAPTER_FORMAT_OPTIONS: ReadonlyArray
> = [
- { value: 'array', label: '数组' },
- { value: 'string', label: 'CQ 码' },
-];
-
-const ADAPTER_REPORT_OPTIONS: ReadonlyArray> = [
- { value: 'on', label: '开启' },
- { value: 'off', label: '关闭' },
-];
-
-const WS_ROLE_OPTIONS: ReadonlyArray> = [
- { value: 'Universal', label: 'Universal' },
- { value: 'Event', label: 'Event' },
- { value: 'Api', label: 'Api' },
-];
-
-interface BaseAdapter {
- name: string;
- enabled?: boolean;
- accessToken?: string;
- messageFormat: MessageFormat;
- reportSelfMessage: boolean;
-}
-
-interface NetworkSectionProps {
- title: string;
- description?: string;
- kind: NetworkKind;
- networks: T[];
- onChange: (next: T[]) => void;
- renderFields: (item: T, patch: (changes: Partial) => void) => React.ReactNode;
- defaultEntry: (suffix: number) => T;
-}
-
-function NetworkSection({
- title,
- description,
- networks,
- onChange,
- renderFields,
- defaultEntry,
-}: NetworkSectionProps) {
- const handleAdd = () => {
- const used = new Set(networks.map((n) => n.name));
- let suffix = networks.length + 1;
- let entry = defaultEntry(suffix);
- while (used.has(entry.name)) {
- suffix += 1;
- entry = defaultEntry(suffix);
- }
- onChange([...networks, entry]);
- };
-
- const patchAt = (idx: number, changes: Partial) => {
- onChange(networks.map((it, i) => (i === idx ? { ...it, ...changes } : it)));
- };
-
- const removeAt = (idx: number) => {
- onChange(networks.filter((_, i) => i !== idx));
- };
-
+function LoadingSkeleton() {
return (
-
- {networks.length === 0 ? (
-
- ) : (
- networks.map((item, idx) => (
- i !== idx).map((n) => n.name)}
- onPatch={(changes) => patchAt(idx, changes)}
- onRemove={() => removeAt(idx)}
- renderFields={renderFields}
- />
- ))
- )}
-
+
+
+
+
+
+
);
}
-interface AdapterRowProps {
- item: T;
- otherNames: string[];
- onPatch: (changes: Partial) => void;
- onRemove: () => void;
- renderFields: (item: T, patch: (changes: Partial) => void) => React.ReactNode;
-}
+// ─────────────── helpers ───────────────
-function AdapterRow({
- item,
- otherNames,
- onPatch,
- onRemove,
- renderFields,
-}: AdapterRowProps) {
- const enabled = item.enabled !== false;
- const duplicateName = !!item.name && otherNames.includes(item.name);
- const blankName = !item.name?.trim();
-
- const formatValue: MessageFormat = item.messageFormat ?? 'array';
- const reportValue: 'on' | 'off' = item.reportSelfMessage ? 'on' : 'off';
-
- return (
-
-
- onPatch({ name: v } as Partial)}
- className="sm:w-44"
- />
- onPatch({ enabled: v ? undefined : false } as Partial)}
- />
-
-
- {(blankName || duplicateName) && (
-
- {blankName ? '请填写名称' : '名称与其它适配器重复'}
-
- )}
-
- {renderFields(item, onPatch)}
-
-
- onPatch({ messageFormat: v } as Partial)}
- />
-
- onPatch({
- reportSelfMessage: v === 'on',
- } as Partial)
- }
- />
-
-
- );
-}
-
-function updateNetworks(
- config: OneBotConfig,
- update: (next: OneBotConfig) => void,
+/** Names of every adapter except the one currently being edited. */
+function otherNames(
+ networks: OneBotNetworks,
kind: K,
- next: OneBotNetworks[K],
-): void {
- update({
- ...config,
- networks: { ...config.networks, [kind]: next },
- });
+ excludeIndex: number | null,
+): string[] {
+ const list = networks[kind];
+ return list
+ .filter((_, i) => i !== excludeIndex)
+ .map((n) => n.name)
+ .filter((s): s is string => typeof s === 'string' && s.length > 0);
}