svelte-settings
Version:
> [!WARNING] > This project is a work in progress. Do not use it in any of your projects yet.
52 lines (51 loc) • 1.96 kB
JavaScript
import { Button, buttonVariants } from './components/ui/button/index.js';
import Label from './components/ui/label/label.svelte';
import Input from './components/ui/input/input.svelte';
import Switch from './components/ui/switch/switch.svelte';
import LoaderPulsatingRing from './components/ui/LoaderPulsatingRing.svelte';
import { Checkbox } from './components/ui/checkbox/index.js';
import * as Popover from './components/ui/popover/index.js';
import * as Accordion from './components/ui/accordion/index.js';
import * as Select from './components/ui/select/index.js';
import * as Breadcrumb from './components/ui/breadcrumb/index.js';
import { mergeDeep } from './deep.js';
export const defaultOptions = {
components: {
Accordion,
Breadcrumb,
Button,
Checkbox,
Input,
Label,
Popover,
Select,
Switch,
LoaderPulsatingRing,
},
style: {
button: {
category: 'outline',
action: 'default',
},
category: {
classes: buttonVariants({ variant: 'outline', class: 'text-base whitespace-wrap' }),
},
},
};
// HACK: deep merge the options but not the components
// TODO: consider splitting components off of options
export function mergeOptions(userOptions) {
const userComponents = userOptions?.components;
if (userOptions?.components)
delete userOptions.components;
const options = mergeDeep(defaultOptions, userOptions);
// Error: type instantiation is excessively deep and possibly infinite. typescript (2589)
// options.components = { ...defaultOptions.components, ...userComponents } as Options['components']
options.components = { ...defaultOptions.components };
if (userComponents) {
for (const [componentKey, component] of Object.entries(userComponents)) {
options.components[componentKey] = component;
}
}
return options;
}