[Refactor] Export config hooks from index.js
This commit is contained in:
@@ -595,48 +595,11 @@ const buildCategoryApiFromSettings = (settings, settingsArray, Category, extraFu
|
||||
return { ...api, ...extraFunctions };
|
||||
};
|
||||
|
||||
const createCategoryHook = (Category) => {
|
||||
export const createCategoryHook = (Category) => {
|
||||
return () => {
|
||||
const { settings } = useSettingsLogics(SETTINGS_ARRAY, Category);
|
||||
const extraFunctions = useConfigFunctions(Category);
|
||||
const autoApi = buildCategoryApiFromSettings(settings, SETTINGS_ARRAY, Category, extraFunctions);
|
||||
return { ...autoApi };
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
// --- 自動エクスポート: SETTINGS_ARRAY に含まれるユニークな Category ごとに use<Category> を作って export ---
|
||||
// 例: Category === "Appearance" -> export const useAppearance = createCategoryHook("Appearance");
|
||||
|
||||
// const uniqueCategories = Array.from(new Set(SETTINGS_ARRAY.map((s) => s.Category)));
|
||||
|
||||
// 動的に named export を作る(静的解析を壊さないために明示的に定義)
|
||||
/* eslint-disable import/prefer-default-export */
|
||||
export const useAppearance = createCategoryHook("Appearance");
|
||||
export const useDevice = createCategoryHook("Device");
|
||||
export const useTranslation = createCategoryHook("Translation");
|
||||
export const useTranscription = createCategoryHook("Transcription");
|
||||
export const useVr = createCategoryHook("Vr");
|
||||
export const useOthers = createCategoryHook("Others");
|
||||
export const useAdvancedSettings = createCategoryHook("AdvancedSettings");
|
||||
|
||||
// Exceptional exports that are not part of SETTINGS_ARRAY or have custom logic.
|
||||
export { useHotkeys } from "./hotkeys/useHotkeys.js";
|
||||
export { useSupporters } from "./supporters/useSupporters.js";
|
||||
export { usePlugins } from "./plugins/usePlugins.js";
|
||||
|
||||
export { useSettingBoxScrollPosition } from "./_aux/useSettingBoxScrollPosition.js";
|
||||
|
||||
|
||||
// If you later add other categories, you can either manually add:
|
||||
// export const useDevice = createCategoryHook("Device");
|
||||
// or uncomment the code below to auto-attach to module.exports (less ideal for tree-shaking).
|
||||
//
|
||||
// Auto-attach (not recommended for tree-shaking in bundlers):
|
||||
// uniqueCategories.forEach((Category) => {
|
||||
// const hookName = `use${Category}`;
|
||||
// module.exports[hookName] = createCategoryHook(Category);
|
||||
// });
|
||||
|
||||
/* eslint-enable import/prefer-default-export */
|
||||
};
|
||||
Reference in New Issue
Block a user