obsidian-dev-skills 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -130,119 +130,16 @@ class MySettingTab extends PluginSettingTab {
|
|
|
130
130
|
this.addSettingTab(new MySettingTab(this.app, this));
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
-
## Settings with Groups
|
|
133
|
+
## Settings with Groups
|
|
134
134
|
|
|
135
135
|
**Source**: Based on `.ref/obsidian-api/obsidian.d.ts` (API is authoritative) - `SettingGroup` requires API 1.11.0+
|
|
136
136
|
|
|
137
|
-
**Use this when**: You want to
|
|
137
|
+
**Use this when**: You want to visually group related settings together.
|
|
138
138
|
|
|
139
|
-
**
|
|
140
|
-
- Continue using the compatibility utility (supports all versions)
|
|
141
|
-
- Force `minAppVersion: "1.11.0"` in `manifest.json` and use `SettingGroup` directly (simpler, but excludes older versions)
|
|
142
|
-
|
|
143
|
-
### Step 1: Create the Compatibility Utility
|
|
144
|
-
|
|
145
|
-
Create `src/utils/settings-compat.ts` (or wherever you keep utilities):
|
|
146
|
-
|
|
147
|
-
```ts
|
|
148
|
-
/**
|
|
149
|
-
* Compatibility utilities for settings
|
|
150
|
-
* Provides backward compatibility for SettingGroup (requires API 1.11.0+)
|
|
151
|
-
*/
|
|
152
|
-
import { Setting, requireApiVersion } from 'obsidian';
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Type definition for SettingGroup constructor
|
|
156
|
-
* Note: SettingGroup may exist at runtime in 1.11.0+ but may not be in TypeScript definitions
|
|
157
|
-
*
|
|
158
|
-
* IMPORTANT: This type signature is inferred from usage patterns. When .ref/obsidian-api/obsidian.d.ts
|
|
159
|
-
* is available, verify the actual signature there. The signature shown here matches the expected
|
|
160
|
-
* behavior based on Obsidian's API design patterns.
|
|
161
|
-
*/
|
|
162
|
-
type SettingGroupConstructor = new (containerEl: HTMLElement) => {
|
|
163
|
-
setHeading(heading: string): {
|
|
164
|
-
addSetting(cb: (setting: Setting) => void): void;
|
|
165
|
-
};
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Interface that works with both SettingGroup and fallback container
|
|
170
|
-
*/
|
|
171
|
-
export interface SettingsContainer {
|
|
172
|
-
addSetting(cb: (setting: Setting) => void): void;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Creates a settings container that uses SettingGroup if available (API 1.11.0+),
|
|
177
|
-
* otherwise falls back to creating a heading and using the container directly.
|
|
178
|
-
*
|
|
179
|
-
* Uses requireApiVersion('1.11.0') to check if SettingGroup is available.
|
|
180
|
-
* This is the official Obsidian API method for version checking.
|
|
181
|
-
*
|
|
182
|
-
* IMPORTANT: We use dynamic require() instead of direct import because SettingGroup
|
|
183
|
-
* may not be in TypeScript type definitions even if it exists at runtime in 1.11.0+.
|
|
184
|
-
* This avoids compile-time TypeScript errors while still working at runtime.
|
|
185
|
-
*
|
|
186
|
-
* @param containerEl - The container element for settings
|
|
187
|
-
* @param heading - The heading text for the settings group (optional)
|
|
188
|
-
* @param manifestId - The plugin's manifest ID for CSS scoping (required for fallback mode)
|
|
189
|
-
* @returns A container that can be used to add settings
|
|
190
|
-
*/
|
|
191
|
-
export function createSettingsGroup(
|
|
192
|
-
containerEl: HTMLElement,
|
|
193
|
-
heading?: string,
|
|
194
|
-
manifestId?: string
|
|
195
|
-
): SettingsContainer {
|
|
196
|
-
// Check if SettingGroup is available (API 1.11.0+)
|
|
197
|
-
// requireApiVersion is the official Obsidian API method for version checking
|
|
198
|
-
if (requireApiVersion('1.11.0')) {
|
|
199
|
-
// Use dynamic require() to access SettingGroup at runtime
|
|
200
|
-
// This avoids TypeScript errors when SettingGroup isn't in type definitions
|
|
201
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
202
|
-
const obsidian = require('obsidian');
|
|
203
|
-
const SettingGroup = obsidian.SettingGroup as SettingGroupConstructor;
|
|
204
|
-
|
|
205
|
-
// Use SettingGroup - it's guaranteed to exist if requireApiVersion returns true
|
|
206
|
-
const group = heading
|
|
207
|
-
? new SettingGroup(containerEl).setHeading(heading)
|
|
208
|
-
: new SettingGroup(containerEl);
|
|
209
|
-
return {
|
|
210
|
-
addSetting(cb: (setting: Setting) => void) {
|
|
211
|
-
group.addSetting(cb);
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
} else {
|
|
215
|
-
// Fallback path (either API < 1.11.0 or SettingGroup not found)
|
|
216
|
-
// Add scoping class to containerEl to scope CSS to only this plugin's settings
|
|
217
|
-
if (manifestId) {
|
|
218
|
-
containerEl.addClass(`${manifestId}-settings-compat`);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Fallback: Create a heading manually and use container directly
|
|
222
|
-
if (heading) {
|
|
223
|
-
const headingEl = containerEl.createDiv('setting-group-heading');
|
|
224
|
-
headingEl.createEl('h3', { text: heading });
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
addSetting(cb: (setting: Setting) => void) {
|
|
229
|
-
const setting = new Setting(containerEl);
|
|
230
|
-
cb(setting);
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
**Note**: The dynamic `require()` approach is necessary because `SettingGroup` may not be in TypeScript type definitions even if it exists at runtime in Obsidian 1.11.0+. This avoids compile-time TypeScript errors while maintaining runtime compatibility.
|
|
238
|
-
|
|
239
|
-
### Step 2: Use in Settings Tab
|
|
240
|
-
|
|
241
|
-
Update your settings tab to use the compatibility utility:
|
|
139
|
+
**Important**: You must set `minAppVersion: "1.11.0"` in your `manifest.json` to use `SettingGroup`.
|
|
242
140
|
|
|
243
141
|
```ts
|
|
244
|
-
import { App, PluginSettingTab, Setting } from "obsidian";
|
|
245
|
-
import { createSettingsGroup } from "./utils/settings-compat";
|
|
142
|
+
import { App, PluginSettingTab, Setting, SettingGroup } from "obsidian";
|
|
246
143
|
|
|
247
144
|
interface MyPluginSettings {
|
|
248
145
|
generalEnabled: boolean;
|
|
@@ -271,7 +168,7 @@ class MySettingTab extends PluginSettingTab {
|
|
|
271
168
|
containerEl.empty();
|
|
272
169
|
|
|
273
170
|
// General Settings Group
|
|
274
|
-
const generalGroup =
|
|
171
|
+
const generalGroup = new SettingGroup(containerEl).setHeading("General Settings");
|
|
275
172
|
|
|
276
173
|
generalGroup.addSetting((setting) => {
|
|
277
174
|
setting
|
|
@@ -304,7 +201,7 @@ class MySettingTab extends PluginSettingTab {
|
|
|
304
201
|
});
|
|
305
202
|
|
|
306
203
|
// Advanced Settings Group
|
|
307
|
-
const advancedGroup =
|
|
204
|
+
const advancedGroup = new SettingGroup(containerEl).setHeading("Advanced Settings");
|
|
308
205
|
|
|
309
206
|
advancedGroup.addSetting((setting) => {
|
|
310
207
|
setting
|
|
@@ -343,69 +240,9 @@ class MySettingTab extends PluginSettingTab {
|
|
|
343
240
|
this.addSettingTab(new MySettingTab(this.app, this));
|
|
344
241
|
```
|
|
345
242
|
|
|
346
|
-
### Step 3: Add CSS Styling (Required for Older Obsidian Builds)
|
|
347
|
-
|
|
348
|
-
**Important**: When using the compatibility utility for older Obsidian builds (< 1.11.0), you must add CSS to prevent double divider lines. The fallback creates a heading with class `setting-group-heading`, and without proper CSS, you'll see a double divider (one from the heading's border-bottom and one from the first setting-item's border-top).
|
|
349
|
-
|
|
350
|
-
**CRITICAL**: The CSS **MUST** be scoped to your plugin's settings container using a manifest-ID-based class to avoid affecting other plugins' settings. Global CSS selectors will impact all settings in Obsidian, not just your plugin's settings.
|
|
351
|
-
|
|
352
|
-
Add this CSS to your `styles.css` file, replacing `{manifest-id}` with your plugin's manifest ID:
|
|
353
|
-
|
|
354
|
-
```css
|
|
355
|
-
/* Group settings compatibility styling for older Obsidian builds (< 1.11.0) */
|
|
356
|
-
/* Scoped to only this plugin's settings container to avoid affecting other plugins */
|
|
357
|
-
.{manifest-id}-settings-compat .setting-group-heading h3 {
|
|
358
|
-
margin: 0 0 0.75rem;
|
|
359
|
-
padding-bottom: 0.5rem;
|
|
360
|
-
padding-top: 0.5rem;
|
|
361
|
-
font-size: 1rem;
|
|
362
|
-
font-weight: 600;
|
|
363
|
-
border-bottom: none !important;
|
|
364
|
-
}
|
|
365
|
-
```
|
|
366
|
-
|
|
367
|
-
**Example**: If your manifest ID is `sample-plugin`, use `.sample-plugin-settings-compat` as the scoping class.
|
|
368
|
-
|
|
369
|
-
**How it works**:
|
|
370
|
-
- The CSS uses the `:has()` selector to detect if a `.setting-item` immediately follows the heading
|
|
371
|
-
- If settings exist below the heading, no border-bottom is applied (avoiding double divider)
|
|
372
|
-
- If no settings follow, border-bottom is applied for visual separation
|
|
373
|
-
- The scoping class (`{manifest-id}-settings-compat`) ensures CSS only affects headings within this plugin's settings container
|
|
374
|
-
- This only affects older builds (< 1.11.0) where the compatibility fallback is used
|
|
375
|
-
- On Obsidian 1.11.0+, `SettingGroup` handles styling automatically, so this CSS has no effect
|
|
376
|
-
|
|
377
|
-
**Note**: The `:has()` selector is well-supported in modern Obsidian (Chromium-based). If you need to support very old browsers, see the alternative TypeScript-based approach in the Common Pitfalls section below.
|
|
378
|
-
|
|
379
|
-
### How It Works
|
|
380
|
-
|
|
381
|
-
- **On Obsidian 1.11.0+**: Uses `SettingGroup` with proper styling and grouping
|
|
382
|
-
- **On older versions**: Creates a manual heading (`<h3>`) and uses regular `Setting` objects
|
|
383
|
-
- **Same API**: Your code using `addSetting()` works identically in both cases
|
|
384
|
-
|
|
385
243
|
### Common Pitfalls
|
|
386
244
|
|
|
387
|
-
#### Pitfall 1:
|
|
388
|
-
|
|
389
|
-
**Problem**: You may see this TypeScript error:
|
|
390
|
-
```ts
|
|
391
|
-
Module '"obsidian"' has no exported member 'SettingGroup'
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
**Cause**: `SettingGroup` may exist at runtime in Obsidian 1.11.0+ but may not be in the TypeScript type definitions, causing compile-time errors.
|
|
395
|
-
|
|
396
|
-
**Solution**: Use dynamic `require()` instead of direct import, as shown in the compatibility utility above. Do not import `SettingGroup` directly:
|
|
397
|
-
|
|
398
|
-
```ts
|
|
399
|
-
// ❌ WRONG - Causes TypeScript errors
|
|
400
|
-
import { SettingGroup } from 'obsidian';
|
|
401
|
-
|
|
402
|
-
// ✅ CORRECT - Use dynamic require()
|
|
403
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
404
|
-
const obsidian = require('obsidian');
|
|
405
|
-
const SettingGroup = obsidian.SettingGroup as SettingGroupConstructor;
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
#### Pitfall 2: Missing Closing Parentheses
|
|
245
|
+
#### Pitfall 1: Missing Closing Parentheses
|
|
409
246
|
|
|
410
247
|
**Problem**: Arrow functions with method chaining need proper closing parentheses and semicolons.
|
|
411
248
|
|
|
@@ -431,7 +268,7 @@ generalGroup.addSetting((setting) =>
|
|
|
431
268
|
); // Closing parenthesis and semicolon required
|
|
432
269
|
```
|
|
433
270
|
|
|
434
|
-
#### Pitfall
|
|
271
|
+
#### Pitfall 2: Storing Setting References
|
|
435
272
|
|
|
436
273
|
**Problem**: If you need to reference a `Setting` object later (e.g., for visibility toggling), you must use block syntax `{ }` instead of expression syntax.
|
|
437
274
|
|
|
@@ -460,27 +297,6 @@ generalGroup.addSetting((setting) => {
|
|
|
460
297
|
mySetting.settingEl.style.display = this.plugin.settings.enabled ? "" : "none";
|
|
461
298
|
```
|
|
462
299
|
|
|
463
|
-
### Alternative: Force Minimum Version
|
|
464
|
-
|
|
465
|
-
If you don't need to support versions before 1.11.0, you can skip the compatibility utility:
|
|
466
|
-
|
|
467
|
-
1. Set `minAppVersion: "1.11.0"` in your `manifest.json`
|
|
468
|
-
2. Use `SettingGroup` directly:
|
|
469
|
-
|
|
470
|
-
```ts
|
|
471
|
-
import { Setting, SettingGroup } from "obsidian";
|
|
472
|
-
|
|
473
|
-
// In settings tab:
|
|
474
|
-
const group = new SettingGroup(containerEl).setHeading("My Settings");
|
|
475
|
-
group.addSetting((setting) => {
|
|
476
|
-
// ... configure setting
|
|
477
|
-
});
|
|
478
|
-
```
|
|
479
|
-
|
|
480
|
-
**Note**: Even with `minAppVersion: "1.11.0"`, you may still encounter TypeScript errors if `SettingGroup` isn't in the type definitions. In that case, you can still use the compatibility utility approach (it will always use `SettingGroup` when `requireApiVersion('1.11.0')` returns true), or use dynamic `require()` as shown in the compatibility utility.
|
|
481
|
-
|
|
482
|
-
This approach is simpler but excludes users on older Obsidian versions. The compatibility utility still works and is recommended for maximum flexibility.
|
|
483
|
-
|
|
484
300
|
## Modal with Form Input
|
|
485
301
|
|
|
486
302
|
**Source**: Based on `.ref/obsidian-plugin-docs/docs/guides/modals.md`
|
|
@@ -16,9 +16,6 @@ Applicability: Plugin
|
|
|
16
16
|
|
|
17
17
|
## Version Considerations
|
|
18
18
|
|
|
19
|
-
When using newer API features (e.g., `SettingGroup` since API 1.11.0),
|
|
20
|
-
- **For new plugins**: You can set `minAppVersion: "1.11.0"` in `manifest.json` and use the feature directly
|
|
21
|
-
- **For existing plugins**: Use version checking with `requireApiVersion()` to support both newer and older Obsidian versions
|
|
22
|
-
- See [code-patterns.md](code-patterns.md) for backward compatibility patterns, including a complete example for `SettingGroup`
|
|
19
|
+
When using newer API features (e.g., `SettingGroup` since API 1.11.0), you must set `minAppVersion: "1.11.0"` in your `manifest.json`.
|
|
23
20
|
|
|
24
21
|
|
|
@@ -137,7 +137,7 @@ this.addSettingTab(new MySettingTab(this.app, this));
|
|
|
137
137
|
- `addSearch(cb: (component: SearchComponent) => any)` - Add a search input at the beginning of the group (useful for filtering)
|
|
138
138
|
- `addExtraButton(cb: (component: ExtraButtonComponent) => any)` - Add an extra button to the group
|
|
139
139
|
|
|
140
|
-
**
|
|
140
|
+
**Important**: You must set `minAppVersion: "1.11.0"` in your `manifest.json` to use these methods.
|
|
141
141
|
|
|
142
142
|
## Secret Storage
|
|
143
143
|
|