obsidian-dev-utils 24.1.1 → 24.2.1-beta.1
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.
- package/CHANGELOG.md +11 -0
- package/dist/lib/cjs/Library.cjs +1 -1
- package/dist/lib/cjs/Object.cjs +1 -1
- package/dist/lib/cjs/Object.d.cts +6 -2
- package/dist/lib/cjs/ScriptUtils/esbuild/preprocessPlugin.cjs +1 -1
- package/dist/lib/cjs/Transformers/Transformer.cjs +1 -1
- package/dist/lib/cjs/Transformers/Transformer.d.cts +2 -1
- package/dist/lib/cjs/Type.cjs +1 -1
- package/dist/lib/cjs/Type.d.cts +6 -0
- package/dist/lib/cjs/obsidian/App.cjs +1 -1
- package/dist/lib/cjs/obsidian/FileChange.cjs +1 -1
- package/dist/lib/cjs/obsidian/Frontmatter.cjs +1 -1
- package/dist/lib/cjs/obsidian/Frontmatter.d.cts +2 -1
- package/dist/lib/cjs/obsidian/Link.cjs +1 -1
- package/dist/lib/cjs/obsidian/MonkeyAround.cjs +1 -1
- package/dist/lib/cjs/obsidian/Plugin/PluginBase.cjs +4 -4
- package/dist/lib/cjs/obsidian/Plugin/PluginBase.d.cts +4 -4
- package/dist/lib/cjs/obsidian/Plugin/PluginSettingsManagerBase.cjs +157 -258
- package/dist/lib/cjs/obsidian/Plugin/PluginSettingsManagerBase.d.cts +56 -93
- package/dist/lib/cjs/obsidian/Plugin/PluginSettingsTabBase.cjs +27 -19
- package/dist/lib/cjs/obsidian/Plugin/PluginSettingsWrapper.cjs +24 -0
- package/dist/lib/cjs/obsidian/Plugin/PluginSettingsWrapper.d.cts +25 -0
- package/dist/lib/cjs/obsidian/Plugin/PluginTypesBase.cjs +1 -1
- package/dist/lib/cjs/obsidian/Plugin/PluginTypesBase.d.cts +27 -0
- package/dist/lib/cjs/obsidian/Plugin/index.cjs +4 -1
- package/dist/lib/cjs/obsidian/Plugin/index.d.cts +1 -0
- package/dist/lib/esm/Library.mjs +1 -1
- package/dist/lib/esm/Object.d.mts +6 -2
- package/dist/lib/esm/Object.mjs +1 -1
- package/dist/lib/esm/ScriptUtils/esbuild/preprocessPlugin.mjs +1 -1
- package/dist/lib/esm/Transformers/Transformer.d.mts +2 -1
- package/dist/lib/esm/Transformers/Transformer.mjs +1 -1
- package/dist/lib/esm/Type.d.mts +6 -0
- package/dist/lib/esm/obsidian/App.mjs +1 -1
- package/dist/lib/esm/obsidian/FileChange.mjs +1 -1
- package/dist/lib/esm/obsidian/Frontmatter.d.mts +2 -1
- package/dist/lib/esm/obsidian/Frontmatter.mjs +1 -1
- package/dist/lib/esm/obsidian/Link.mjs +1 -1
- package/dist/lib/esm/obsidian/MonkeyAround.mjs +1 -1
- package/dist/lib/esm/obsidian/Plugin/PluginBase.d.mts +4 -4
- package/dist/lib/esm/obsidian/Plugin/PluginBase.mjs +4 -4
- package/dist/lib/esm/obsidian/Plugin/PluginSettingsManagerBase.d.mts +56 -93
- package/dist/lib/esm/obsidian/Plugin/PluginSettingsManagerBase.mjs +158 -255
- package/dist/lib/esm/obsidian/Plugin/PluginSettingsTabBase.mjs +27 -19
- package/dist/lib/esm/obsidian/Plugin/PluginSettingsWrapper.d.mts +25 -0
- package/dist/lib/esm/obsidian/Plugin/PluginSettingsWrapper.mjs +8 -0
- package/dist/lib/esm/obsidian/Plugin/PluginTypesBase.d.mts +27 -0
- package/dist/lib/esm/obsidian/Plugin/index.d.mts +1 -0
- package/dist/lib/esm/obsidian/Plugin/index.mjs +3 -1
- package/obsidian/Plugin/PluginSettingsWrapper/package.json +6 -0
- package/package.json +5 -5
@@ -5,11 +5,12 @@
|
|
5
5
|
*/
|
6
6
|
import type { App } from 'obsidian';
|
7
7
|
import type { Promisable, ReadonlyDeep } from 'type-fest';
|
8
|
+
import type { GenericObject } from '../../Object.mjs';
|
8
9
|
import type { Transformer } from '../../Transformers/Transformer.mjs';
|
9
10
|
import type { MaybeReturn, StringKeys } from '../../Type.mjs';
|
10
|
-
import type { ExtractPlugin, ExtractPluginSettings, PluginTypesBase } from './PluginTypesBase.mjs';
|
11
|
-
type
|
12
|
-
type Validator<
|
11
|
+
import type { ExtractPlugin, ExtractPluginSettings, ExtractPluginSettingsPropertyNames, ExtractReadonlyPluginSettingsWrapper, PluginTypesBase } from './PluginTypesBase.mjs';
|
12
|
+
type ValidationResult<PluginSettings extends object> = Partial<Record<StringKeys<PluginSettings>, string>>;
|
13
|
+
type Validator<PluginSettings extends object, PropertyName extends StringKeys<PluginSettings> = StringKeys<PluginSettings>> = (value: PluginSettings[PropertyName], settings: PluginSettings) => Promisable<MaybeReturn<string>>;
|
13
14
|
/**
|
14
15
|
* Base class for managing plugin settings.
|
15
16
|
*
|
@@ -18,9 +19,16 @@ type Validator<T> = (value: T) => Promisable<MaybeReturn<string>>;
|
|
18
19
|
export declare abstract class PluginSettingsManagerBase<PluginTypes extends PluginTypesBase> {
|
19
20
|
readonly plugin: ExtractPlugin<PluginTypes>;
|
20
21
|
readonly app: App;
|
21
|
-
readonly
|
22
|
-
|
23
|
-
|
22
|
+
readonly defaultSettings: ReadonlyDeep<ExtractPluginSettings<PluginTypes>>;
|
23
|
+
/**
|
24
|
+
* Gets the current settings wrapper.
|
25
|
+
*
|
26
|
+
* @returns The current settings wrapper.
|
27
|
+
*/
|
28
|
+
get settingsWrapper(): ExtractReadonlyPluginSettingsWrapper<PluginTypes>;
|
29
|
+
private currentSettingsWrapper;
|
30
|
+
private lastSavedSettingsWrapper;
|
31
|
+
private readonly propertyNames;
|
24
32
|
private readonly validators;
|
25
33
|
/**
|
26
34
|
* Creates a new plugin settings manager.
|
@@ -31,18 +39,27 @@ export declare abstract class PluginSettingsManagerBase<PluginTypes extends Plug
|
|
31
39
|
/**
|
32
40
|
* Edits the plugin settings and saves them.
|
33
41
|
*
|
34
|
-
* @param
|
42
|
+
* @param settingsEditor - The editor.
|
35
43
|
* @param context - The context.
|
36
44
|
* @returns A {@link Promise} that resolves when the settings are saved.
|
37
45
|
*/
|
38
|
-
editAndSave(
|
46
|
+
editAndSave(settingsEditor: (settings: ExtractPluginSettings<PluginTypes>) => Promisable<void>, context?: unknown): Promise<void>;
|
39
47
|
/**
|
40
|
-
*
|
48
|
+
* Ensures the settings are safe.
|
41
49
|
*
|
42
|
-
*
|
43
|
-
*
|
50
|
+
* It runs validation for each property and sets the default value if the validation fails.
|
51
|
+
*
|
52
|
+
* @param settings - The settings.
|
53
|
+
* @returns A {@link Promise} that resolves when the settings are safe.
|
44
54
|
*/
|
45
|
-
|
55
|
+
ensureSafe(settings: ExtractPluginSettings<PluginTypes>): Promise<void>;
|
56
|
+
/**
|
57
|
+
* Gets a safe copy of the settings.
|
58
|
+
*
|
59
|
+
* @param settings - The settings.
|
60
|
+
* @returns A {@link Promise} that resolves to the safe copy of the settings.
|
61
|
+
*/
|
62
|
+
getSafeCopy(settings: ExtractPluginSettings<PluginTypes>): Promise<ExtractPluginSettings<PluginTypes>>;
|
46
63
|
/**
|
47
64
|
* Loads the plugin settings from the file.
|
48
65
|
*
|
@@ -57,6 +74,22 @@ export declare abstract class PluginSettingsManagerBase<PluginTypes extends Plug
|
|
57
74
|
* @returns A {@link Promise} that resolves when the settings are saved.
|
58
75
|
*/
|
59
76
|
saveToFile(context?: unknown): Promise<void>;
|
77
|
+
/**
|
78
|
+
* Sets the value of a property.
|
79
|
+
*
|
80
|
+
* @typeParam PropertyName - The name of the property.
|
81
|
+
* @param propertyName - The name of the property.
|
82
|
+
* @param value - The value to set.
|
83
|
+
* @returns A {@link Promise} that resolves to the validation message.
|
84
|
+
*/
|
85
|
+
setProperty<PropertyName extends ExtractPluginSettingsPropertyNames<PluginTypes>>(propertyName: PropertyName, value: ExtractPluginSettings<PluginTypes>[PropertyName]): Promise<string>;
|
86
|
+
/**
|
87
|
+
* Validates the settings.
|
88
|
+
*
|
89
|
+
* @param settings - The settings.
|
90
|
+
* @returns A {@link Promise} that resolves to the validation result.
|
91
|
+
*/
|
92
|
+
validate(settings: ExtractPluginSettings<PluginTypes>): Promise<ValidationResult<ExtractPluginSettings<PluginTypes>>>;
|
60
93
|
protected abstract createDefaultSettings(): ExtractPluginSettings<PluginTypes>;
|
61
94
|
/**
|
62
95
|
* Gets the transformer.
|
@@ -69,104 +102,34 @@ export declare abstract class PluginSettingsManagerBase<PluginTypes extends Plug
|
|
69
102
|
*
|
70
103
|
* @param _record - The record.
|
71
104
|
*/
|
72
|
-
protected onLoadRecord(_record:
|
105
|
+
protected onLoadRecord(_record: GenericObject): Promise<void>;
|
73
106
|
/**
|
74
107
|
* Called when the plugin settings are saving.
|
75
108
|
*
|
76
109
|
* @param _record - The record.
|
77
110
|
*/
|
78
|
-
protected onSavingRecord(_record:
|
111
|
+
protected onSavingRecord(_record: GenericObject): Promise<void>;
|
79
112
|
/**
|
80
113
|
* Registers a validator for a property.
|
81
114
|
*
|
82
115
|
* @param propertyName - The name of the property.
|
83
116
|
* @param validator - The validator.
|
84
117
|
*/
|
85
|
-
protected registerValidator<PropertyName extends
|
118
|
+
protected registerValidator<PropertyName extends ExtractPluginSettingsPropertyNames<PluginTypes>>(propertyName: PropertyName, validator: Validator<ExtractPluginSettings<PluginTypes>, PropertyName>): void;
|
86
119
|
/**
|
87
120
|
* Registers the validators.
|
88
121
|
*
|
89
122
|
* This method can be overridden by subclasses to register validators for properties.
|
90
123
|
*/
|
91
124
|
protected registerValidators(): void;
|
92
|
-
private
|
93
|
-
private
|
125
|
+
private cloneSettings;
|
126
|
+
private cloneSettingsWrapper;
|
127
|
+
private createDefaultSettingsWrapper;
|
128
|
+
private edit;
|
129
|
+
private isValidPropertyName;
|
130
|
+
private rawRecordToSettings;
|
94
131
|
private saveToFileImpl;
|
95
|
-
|
96
|
-
|
97
|
-
* A property of a plugin settings.
|
98
|
-
*
|
99
|
-
* @typeParam T - The type of the property.
|
100
|
-
*/
|
101
|
-
export declare class PluginSettingsProperty<T> {
|
102
|
-
private readonly propertyName;
|
103
|
-
readonly defaultValue: T;
|
104
|
-
private readonly validator;
|
105
|
-
private readonly propertySetter;
|
106
|
-
/**
|
107
|
-
* The current value of the property.
|
108
|
-
*
|
109
|
-
* @returns The current value.
|
110
|
-
*/
|
111
|
-
get currentValue(): T;
|
112
|
-
/**
|
113
|
-
* The last saved value of the property.
|
114
|
-
*
|
115
|
-
* @returns The last saved value.
|
116
|
-
*/
|
117
|
-
get lastSavedValue(): T;
|
118
|
-
/**
|
119
|
-
* The safe value of the property.
|
120
|
-
*
|
121
|
-
* @returns The safe value.
|
122
|
-
*/
|
123
|
-
get safeValue(): T;
|
124
|
-
/**
|
125
|
-
* The validation message of the property.
|
126
|
-
*
|
127
|
-
* @returns The validation message.
|
128
|
-
*/
|
129
|
-
get validationMessage(): string;
|
130
|
-
private _currentValue;
|
131
|
-
private _lastSavedValue;
|
132
|
-
private _validationMessage;
|
133
|
-
/**
|
134
|
-
* Creates a new plugin settings property.
|
135
|
-
*
|
136
|
-
* @param propertyName - The name of the property.
|
137
|
-
* @param defaultValue - The default value of the property.
|
138
|
-
* @param validator - The validator of the property.
|
139
|
-
* @param propertySetter - The property setter of the property.
|
140
|
-
*/
|
141
|
-
constructor(propertyName: string, defaultValue: T, validator: Validator<T>, propertySetter: PropertySetter);
|
142
|
-
/**
|
143
|
-
* Resets the current value of the property to the default value.
|
144
|
-
*/
|
145
|
-
reset(): void;
|
146
|
-
/**
|
147
|
-
* Saves the current value of the property.
|
148
|
-
*
|
149
|
-
* @returns `true` if the value was changed, `false` otherwise.
|
150
|
-
*/
|
151
|
-
save(): boolean;
|
152
|
-
/**
|
153
|
-
* Sets the validation message of the property.
|
154
|
-
*
|
155
|
-
* @param validationMessage - The validation message.
|
156
|
-
*/
|
157
|
-
setValidationMessage(validationMessage: string): void;
|
158
|
-
/**
|
159
|
-
* Sets the current value of the property.
|
160
|
-
*
|
161
|
-
* @param value - The value to set.
|
162
|
-
*/
|
163
|
-
setValue(value: T): void;
|
164
|
-
/**
|
165
|
-
* Validates the current value of the property.
|
166
|
-
*
|
167
|
-
* @returns A {@link Promise} that resolves when the validation is complete.
|
168
|
-
*/
|
169
|
-
validate(): Promise<void>;
|
170
|
-
private showWarning;
|
132
|
+
private setPropertyImpl;
|
133
|
+
private settingsToRawRecord;
|
171
134
|
}
|
172
135
|
export {};
|