apps/ui-kit/docs/api/super-formatter.md
For examples and usage details, visit the Super Formatter page.
| Name | Type | Description | Default | Status |
|---|---|---|---|---|
value | string | The SQL text to format and preview. | '' | ✅ |
canAddPresets | boolean | Enable preset management features (add, save, delete). When false, only formatting controls are shown. | false | ✅ |
clipboard | Clipboard | Custom clipboard handler for the editor used in vim. If provided, it must implement a write method to copy text to the clipboard. See MDN Clipboard API for more details. | undefined | ✅ |
startingPreset | FormatOptions | Initial formatting configuration to load. Can include an optional id property to select a specific preset. | See below | ✅ |
presets | Preset[] | Array of available formatting presets. See Preset Object below. | `[] | ✅ |
formatterDialect | string | SQL dialect for formatting. See sql-formatter's language docs. | 'sql' | ✅ |
{
id: null,
tabWidth: 2,
useTabs: false,
keywordCase: 'preserve',
dataTypeCase: 'preserve',
functionCase: 'preserve',
logicalOperatorNewline: 'before',
expressionWidth: 50,
linesBetweenQueries: 1,
denseOperators: false,
newlineBeforeSemicolon: false
}
| Property | Type | Description | Required |
|---|---|---|---|
id | number | Unique identifier for the preset. | ✅ |
name | string | Display name for the preset. | ✅ |
systemDefault | boolean | Whether this is a system preset (cannot be deleted). | ✅ |
config | FormatOptions | Formatting configuration. See Format Options below. | ✅ |
Configuration object for SQL formatting behavior.
| Property | Type | Description | Default |
|---|---|---|---|
id | number | null | Optional preset ID reference. | null |
tabWidth | number | Number of spaces per indentation level (1-20). | 2 |
useTabs | boolean | Use tab characters instead of spaces for indentation. | false |
keywordCase | 'preserve' | 'upper' | 'lower' | Text case transformation for SQL keywords (SELECT, FROM, WHERE, etc.). | 'preserve' |
dataTypeCase | 'preserve' | 'upper' | 'lower' | Text case transformation for data type names (VARCHAR, INTEGER, etc.). | 'preserve' |
functionCase | 'preserve' | 'upper' | 'lower' | Text case transformation for function names (COUNT, SUM, NOW, etc.). | 'preserve' |
logicalOperatorNewline | 'before' | 'after' | Placement of logical operators (AND, OR) relative to new lines. | 'before' |
expressionWidth | number | Maximum character width for expressions before wrapping (1-100). | 50 |
linesBetweenQueries | number | Number of blank lines to insert between separate SQL queries (1-20). | 1 |
denseOperators | boolean | Remove spaces around operators (e.g., a=b instead of a = b). | false |
newlineBeforeSemicolon | boolean | Place statement-ending semicolons on their own line. | false |
| Name | Description | Event Detail |
|---|---|---|
bks-create-preset | Emitted when a new preset is created. | { name: string, config: FormatOptions } |
bks-save-preset | Emitted when an existing preset is saved. | { id: number, config: FormatOptions } |
bks-delete-preset | Emitted when a preset is deleted. | { id: number } |
bks-apply-preset | Emitted when the user applies formatting. | { config: FormatOptions, id: number } |
formatter.addEventListener('bks-create-preset', (event) => {
const { name, config } = event.detail;
console.log(`Creating preset "${name}" with config:`, config);
// Save to database and update presets list
const newPreset = {
id: generateId(),
name: name,
systemDefault: false,
config: config
};
formatter.presets = [...formatter.presets, newPreset];
});
formatter.addEventListener('bks-save-preset', (event) => {
const { id, config } = event.detail;
console.log(`Saving preset ${id} with config:`, config);
// Update in database
const presetIndex = formatter.presets.findIndex(p => p.id === id);
if (presetIndex !== -1) {
formatter.presets[presetIndex].config = config;
formatter.presets = [...formatter.presets]; // Trigger reactivity
}
});
formatter.addEventListener('bks-delete-preset', (event) => {
const { id } = event.detail;
console.log(`Deleting preset ${id}`);
// Remove from database
formatter.presets = formatter.presets.filter(p => p.id !== id);
});
formatter.addEventListener('bks-apply-preset', (event) => {
const { config, id } = event.detail;
console.log(`Applying preset ${id}:`, config);
// Apply the configuration to your SQL editor
sqlEditor.formatOptions = config;
sqlEditor.format();
});
The formatterDialect property accepts the following values:
sql - Generic SQL (default)bigquery - Google BigQuerydb2 - IBM DB2db2i - IBM DB2 for ihive - Apache Hivemariadb - MariaDBmysql - MySQLn1ql - Couchbase N1QLplsql - Oracle PL/SQLpostgresql - PostgreSQLredshift - Amazon Redshiftsinglestoredb - SingleStoresnowflake - Snowflakespark - Apache Sparksqlite - SQLitetidb - TiDBtransactsql / tsql - SQL Server T-SQLtrino - TrinosystemDefault: true to prevent deletion.presets array after create/save/delete operations to keep UI in sync.// Using native Clipboard API
formatter.clipboard = {
writeText: (text) => navigator.clipboard.writeText(text)
};
// Custom clipboard handler
formatter.clipboard = {
writeText: (text) => {
// Custom implementation (e.g., Electron clipboard)
myClipboard.write(text);
}
};
// Update dialect based on database connection
const dialectMap = {
'postgres': 'postgresql',
'mysql': 'mysql',
'mssql': 'tsql',
'oracle': 'plsql'
};
formatter.formatterDialect = dialectMap[currentConnection.type] || 'sql';