ConfigManager

A configuration manager for persisting and retrieving client-side settings across sessions.

Import
the javascript logo
import { ConfigManager } from "@schukai/monster/source/components/host/config-manager.mjs";
Source
the git logo
Package
Since
1.0.0
No value yet.

Introduction

The Monster ConfigManager stores and retrieves client-side configuration values. Use it when user preferences, layout decisions or other lightweight settings should persist across sessions.

When to use ConfigManager

  • Use it for persistent UI settings: Theme, layout or filter preferences are typical examples.
  • Use it when configuration belongs on the client: The component is useful for browser-local state, not server truth.
  • Do not use it for sensitive application data: Security-relevant values need a stronger persistence model.

Config Manager

Persist a simple configuration value to IndexedDB and read it back.

No value yet.

Javascript

import '@schukai/monster/source/components/host/config-manager.mjs';

const manager = document.getElementById('config-manager');
const output = document.getElementById('config-manager-output');

document.getElementById('config-manager-save').addEventListener('click', () => {
    manager.setConfig('theme', { mode: 'light' }).then(() => {
        output.textContent = 'Saved theme setting.';
    });
});

document.getElementById('config-manager-load').addEventListener('click', () => {
    manager.getConfig('theme').then((value) => {
        output.textContent = value ? JSON.stringify(value) : 'No value stored.';
    });
});<script type="module">import '@schukai/monster/source/components/host/config-manager.mjs';

const manager = document.getElementById('config-manager');
const output = document.getElementById('config-manager-output');

document.getElementById('config-manager-save').addEventListener('click', () => {
    manager.setConfig('theme', { mode: 'light' }).then(() => {
        output.textContent = 'Saved theme setting.';
    });
});

document.getElementById('config-manager-load').addEventListener('click', () => {
    manager.getConfig('theme').then((value) => {
        output.textContent = value ? JSON.stringify(value) : 'No value stored.';
    });
});</script>

HTML

<div id="config-manager-output">No value yet.</div>
<button id="config-manager-save">Save setting</button>
<button id="config-manager-load">Load setting</button>

<monster-config-manager id="config-manager"></monster-config-manager>

Stylesheet

/** no additional stylesheet is defined **/
Open in playground

Scoped Configuration

Stores and reads a namespaced table preference through the asynchronous configuration API.

Javascript

import "@schukai/monster/source/components/host/config-manager.mjs";

const manager = document.getElementById("scoped-config");
const status = document.getElementById("scoped-config-status");
document.getElementById("scoped-config-save").addEventListener("click", async () => {
  await manager.setConfig("orders.table", {columns: ["number", "status"], density: "compact"});
  const stored = await manager.getConfig("orders.table");
  status.textContent = JSON.stringify(stored);
});

HTML

<section style="display:grid;gap:var(--monster-space-3)">
  <monster-config-manager id="scoped-config"></monster-config-manager>
  <button id="scoped-config-save" type="button">Save table preferences</button>
  <output id="scoped-config-status"></output>
</section>

Stylesheet

/** no additional stylesheet is defined **/
Open in playground

Component Design

The config manager is a headless component with no visual UI. It exposes a simple API for storing data and can be styled only if you add custom markup around it.

Customizing With Parts

You can adapt the visual appearance through exported parts instead of modifying the internal template. This reference is generated from the current component source.

The component exposes these part names:

  • control: Outer wrapper of the component.

HTML Structure

<monster-config-manager></monster-config-manager>

JavaScript Initialization

const element = document.createElement('monster-config-manager');
document.body.appendChild(element);

Exported

ConfigManager

Derived from

CustomElement

Options

The Options listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class. Therefore, it inherits Options from these parent classes. If you cannot find a specific Options in this list, we recommend consulting the documentation of the CustomElement.

Option
Type
Default
Description
templates
object
Template definitions
templates.main
string
undefined
Main template

  • since
  • deprecated

Properties and Attributes

The Properties and Attributes listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits Properties and Attributes from these parent classes. If you cannot find a specific Properties and Attributes in this list, we recommend consulting the documentation of the CustomElement.

  • data-monster-options: Sets the configuration options for the collapse component when used as an HTML attribute.
  • data-monster-option-[name]: Sets the value of the configuration option [name] for the collapse component when used as an HTML attribute.

Methods

The methods listed in this section are defined directly within the class. This class is derived from several parent classes, including the CustomElement class and ultimately from HTMLElement. Therefore, it inherits methods from these parent classes. If you cannot find a specific method in this list, we recommend consulting the documentation of the CustomElement.

Constructor

constructor()
No description available.

Behavioral methods

ready()
Returns
  • {Promise}
No description available.

State query methods

hasConfig(key)
Parameters
  • key {string}: key
Returns
  • {Promise<boolean>}
No description available.

Structural methods

getConfig(key)
Parameters
  • key {string}: key
Returns
  • {Promise<unknown>}
No description available.
getStorageAdapter()
Returns
  • {Object|null}
No description available.
setConfig(key,value)
Parameters
  • key {string}: key
  • value {*}: value
Returns
  • {Promise<unknown>}
No description available.
setStorageAdapter(adapter)
Parameters
  • adapter {object|null}: adapter
Returns
  • {ConfigManager}
Register an external host configuration storage adapter. Supported adapter methods are getConfig/hasConfig/setConfig/deleteConfig or their short aliases get/has/set/delete. If managesConfigKey, managesKey or manages is present, it is used to decide whether a key is handled by the adapter. Without such a method, an adapter handles all keys.

Static methods

[instanceSymbol]()
Returns
  • {symbol}
This method is called by the instanceof operator.
getCSSStyleSheet()
Returns
  • {CSSStyleSheet[]}
No description available.
getTag()
Returns
  • {string}
No description available.

Lifecycle methods

Lifecycle methods are called by the environment and are usually not intended to be called directly.

[assembleMethodSymbol]()
No description available.

Other methods

deleteConfig(key)
Parameters
  • key
No description available.

Events

This component does not fire any public events. It may fire events that are inherited from its parent classes.

The current width of the area is too small to display the content correctly.