obsidian-dev-utils 83.3.0 → 84.1.0
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 +32 -0
- package/dist/dev/main.js +2471 -1860
- package/dist/lib/cjs/generated-during-build.cjs +2 -2
- package/dist/lib/cjs/obsidian/components/plugin-notice-component.cjs +6 -4
- package/dist/lib/cjs/obsidian/components/rename-delete-handler-component.cjs +10 -10
- package/dist/lib/cjs/obsidian/components/rename-delete-handler-component.d.cts +3 -3
- package/dist/lib/cjs/obsidian/editor.cjs +21 -1
- package/dist/lib/cjs/obsidian/editor.d.cts +23 -3
- package/dist/lib/cjs/obsidian/file-manager.cjs +9 -9
- package/dist/lib/cjs/obsidian/file-manager.d.cts +9 -9
- package/dist/lib/cjs/obsidian/i18n/locales/en.cjs +8 -8
- package/dist/lib/cjs/obsidian/i18n/locales/en.d.cts +7 -7
- package/dist/lib/cjs/obsidian/i18n/locales/translations-map.d.cts +7 -7
- package/dist/lib/cjs/obsidian/index.cjs +7 -4
- package/dist/lib/cjs/obsidian/index.d.cts +2 -1
- package/dist/lib/cjs/obsidian/markdown-code-block-processor.cjs +7 -7
- package/dist/lib/cjs/obsidian/markdown-code-block-processor.d.cts +9 -9
- package/dist/lib/cjs/obsidian/plugin/plugin.cjs +21 -21
- package/dist/lib/cjs/obsidian/plugin/plugin.d.cts +15 -15
- package/dist/lib/cjs/obsidian/resource-lock.cjs +899 -0
- package/dist/lib/cjs/obsidian/resource-lock.d.cts +227 -0
- package/dist/lib/cjs/obsidian/vault-transaction.cjs +373 -0
- package/dist/lib/cjs/obsidian/vault-transaction.d.cts +146 -0
- package/dist/lib/cjs/obsidian/vault.cjs +4 -4
- package/dist/lib/cjs/obsidian/vault.d.cts +3 -3
- package/dist/lib/esm/generated-during-build.mjs +2 -2
- package/dist/lib/esm/obsidian/components/plugin-notice-component.mjs +10 -5
- package/dist/lib/esm/obsidian/components/rename-delete-handler-component.d.mts +3 -3
- package/dist/lib/esm/obsidian/components/rename-delete-handler-component.mjs +10 -10
- package/dist/lib/esm/obsidian/editor.d.mts +23 -3
- package/dist/lib/esm/obsidian/editor.mjs +20 -1
- package/dist/lib/esm/obsidian/file-manager.d.mts +9 -9
- package/dist/lib/esm/obsidian/file-manager.mjs +9 -9
- package/dist/lib/esm/obsidian/i18n/locales/en.d.mts +7 -7
- package/dist/lib/esm/obsidian/i18n/locales/en.mjs +8 -8
- package/dist/lib/esm/obsidian/i18n/locales/translations-map.d.mts +7 -7
- package/dist/lib/esm/obsidian/index.d.mts +2 -1
- package/dist/lib/esm/obsidian/index.mjs +5 -3
- package/dist/lib/esm/obsidian/markdown-code-block-processor.d.mts +9 -9
- package/dist/lib/esm/obsidian/markdown-code-block-processor.mjs +7 -7
- package/dist/lib/esm/obsidian/plugin/plugin.d.mts +15 -15
- package/dist/lib/esm/obsidian/plugin/plugin.mjs +21 -21
- package/dist/lib/esm/obsidian/resource-lock.d.mts +227 -0
- package/dist/lib/esm/obsidian/resource-lock.mjs +799 -0
- package/dist/lib/esm/obsidian/vault-transaction.d.mts +146 -0
- package/dist/lib/esm/obsidian/vault-transaction.mjs +273 -0
- package/dist/lib/esm/obsidian/vault.d.mts +3 -3
- package/dist/lib/esm/obsidian/vault.mjs +4 -4
- package/dist/styles.css +8 -1
- package/obsidian/resource-lock/package.json +6 -0
- package/obsidian/vault-transaction/package.json +6 -0
- package/package.json +1 -1
- package/dist/lib/cjs/obsidian/editor-lock.cjs +0 -545
- package/dist/lib/cjs/obsidian/editor-lock.d.cts +0 -142
- package/dist/lib/esm/obsidian/editor-lock.d.mts +0 -142
- package/dist/lib/esm/obsidian/editor-lock.mjs +0 -442
- package/obsidian/editor-lock/package.json +0 -6
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/// <reference path="../library.d.cts" />
|
|
2
|
-
/**
|
|
3
|
-
* @file
|
|
4
|
-
*
|
|
5
|
-
* Note-scoped, reference-counted editor locking.
|
|
6
|
-
*
|
|
7
|
-
* Where {@link toggleEditorReadOnly} from `./editor.ts` toggles the read-only state of a single
|
|
8
|
-
* {@link Editor} instance, the helpers here lock a note by its **path**: while a path is
|
|
9
|
-
* locked, every current and future {@link MarkdownView} of that note (in any window, including
|
|
10
|
-
* popouts) is made read-only and shows a lock indicator in its tab header, its view action bar, and
|
|
11
|
-
* the status bar (while the note is active). Locks are reference-counted per locking plugin, so
|
|
12
|
-
* nested or concurrent operations on the same note are safe — the note is unlocked only when the
|
|
13
|
-
* last lock is released — and the indicators' tooltip lists which plugins currently hold a lock.
|
|
14
|
-
*
|
|
15
|
-
* The acquirers return a {@link Disposable}, so the preferred call style is a `using` declaration
|
|
16
|
-
* that releases automatically at scope exit (including on throw):
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* using _lock = lockEditorForPath(app, path, this.manifest.id);
|
|
20
|
-
* // ... long-running work (process, processFrontMatter, merge/split) ...
|
|
21
|
-
* // auto-unlocked at scope exit
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* The explicit {@link unlockEditorForPath} pair remains available for non-`using` call sites.
|
|
25
|
-
*/
|
|
26
|
-
import type { App } from 'obsidian' with { 'resolution-mode': 'import' };
|
|
27
|
-
import type { PathOrFile } from './file-system.cjs';
|
|
28
|
-
import { ComponentEx } from './components/component-ex.cjs';
|
|
29
|
-
/**
|
|
30
|
-
* Options for {@link EditorLockComponent.lockForPath}.
|
|
31
|
-
*/
|
|
32
|
-
export interface EditorLockComponentLockForPathOptions {
|
|
33
|
-
/**
|
|
34
|
-
* An optional {@link AbortController} associated with the lock. When the lock indicator is
|
|
35
|
-
* right-clicked and the user confirms an unlock (or {@link requestEditorUnlockForPath} is called for
|
|
36
|
-
* the path), this controller is aborted so the operation holding the lock can cancel itself and
|
|
37
|
-
* release the lock in its own cleanup.
|
|
38
|
-
*/
|
|
39
|
-
readonly abortController?: AbortController;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* A per-plugin handle for note-scoped editor locking. Add it as a child of your plugin
|
|
43
|
-
* (`this.addChild(new EditorLockComponent(this.app))`) so that any locks it still holds are released
|
|
44
|
-
* automatically when the plugin unloads — a note can never be left stuck read-only because the
|
|
45
|
-
* plugin that locked it was disabled or reloaded mid-operation.
|
|
46
|
-
*
|
|
47
|
-
* Locks are reference-counted and attributed to this plugin, so the lock indicators' tooltip names
|
|
48
|
-
* it among the plugins currently holding a lock.
|
|
49
|
-
*/
|
|
50
|
-
export declare class EditorLockComponent extends ComponentEx {
|
|
51
|
-
private readonly app;
|
|
52
|
-
private readonly pluginId;
|
|
53
|
-
/**
|
|
54
|
-
* Creates an editor-lock handle owned by a plugin.
|
|
55
|
-
*
|
|
56
|
-
* @param app - The Obsidian app instance.
|
|
57
|
-
* @param pluginId - The id of the owning plugin (e.g. its `manifest.id`). Locks are attributed to
|
|
58
|
-
* it for reference-counting and the indicators' "locked by" tooltip.
|
|
59
|
-
*/
|
|
60
|
-
constructor(app: App, pluginId: string);
|
|
61
|
-
/**
|
|
62
|
-
* Checks whether the note at the given path is currently locked by any plugin.
|
|
63
|
-
*
|
|
64
|
-
* @param pathOrFile - The path or file of the note to check.
|
|
65
|
-
* @returns `true` if the note has at least one active lock, `false` otherwise.
|
|
66
|
-
*/
|
|
67
|
-
isLockedForPath(pathOrFile: PathOrFile): boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Locks the note at the given path on behalf of this plugin, making it read-only in every current
|
|
70
|
-
* and future {@link MarkdownView} until the lock is released. Reference-counted: balance each call
|
|
71
|
-
* with a dispose of the returned {@link Disposable} (ideally via `using`) or {@link unlockForPath}.
|
|
72
|
-
*
|
|
73
|
-
* @param pathOrFile - The path or file of the note to lock.
|
|
74
|
-
* @param options - Optional locking options. Pass an
|
|
75
|
-
* {@link EditorLockComponentLockForPathOptions.abortController} to make the lock cancelable via the
|
|
76
|
-
* indicator's right-click "unlock" menu or {@link requestEditorUnlockForPath}.
|
|
77
|
-
* @returns A {@link Disposable} that releases this lock when disposed. Disposing more than once is a no-op.
|
|
78
|
-
*/
|
|
79
|
-
lockForPath(pathOrFile: PathOrFile, options?: EditorLockComponentLockForPathOptions): Disposable;
|
|
80
|
-
/**
|
|
81
|
-
* Releases every lock still held by this plugin when the component (and thus the plugin) unloads,
|
|
82
|
-
* so no note is left stuck read-only by an operation that never completed.
|
|
83
|
-
*/
|
|
84
|
-
onunload(): void;
|
|
85
|
-
/**
|
|
86
|
-
* Releases one lock previously acquired for the note at the given path via {@link lockForPath}.
|
|
87
|
-
*
|
|
88
|
-
* @param pathOrFile - The path or file of the note to unlock.
|
|
89
|
-
*/
|
|
90
|
-
unlockForPath(pathOrFile: PathOrFile): void;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Checks whether the note at the given path is currently locked.
|
|
94
|
-
*
|
|
95
|
-
* @param app - The Obsidian app instance.
|
|
96
|
-
* @param pathOrFile - The path or file of the note to check.
|
|
97
|
-
* @returns `true` if the note has at least one active lock, `false` otherwise.
|
|
98
|
-
*/
|
|
99
|
-
export declare function isEditorLockedForPath(app: App, pathOrFile: PathOrFile): boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Locks the note at the given path, making it read-only in every current and future
|
|
102
|
-
* {@link MarkdownView} until the lock is released, and showing a lock indicator in the tab header,
|
|
103
|
-
* view action bar, and (while active) the status bar. The indicators' tooltip lists the plugins
|
|
104
|
-
* that currently hold a lock on the note.
|
|
105
|
-
*
|
|
106
|
-
* The lock is reference-counted per calling plugin: each call must be balanced by exactly one
|
|
107
|
-
* release (either disposing the returned {@link Disposable} — ideally via a `using` declaration — or
|
|
108
|
-
* a matching {@link unlockEditorForPath} call).
|
|
109
|
-
*
|
|
110
|
-
* @param app - The Obsidian app instance.
|
|
111
|
-
* @param pathOrFile - The path or file of the note to lock.
|
|
112
|
-
* @param pluginId - The id of the locking plugin (e.g. its `manifest.id`). The lock is attributed to
|
|
113
|
-
* it for reference-counting and the indicators' "locked by" tooltip.
|
|
114
|
-
* @returns A {@link Disposable} that releases this lock when disposed. Disposing more than once is a no-op.
|
|
115
|
-
*/
|
|
116
|
-
export declare function lockEditorForPath(app: App, pathOrFile: PathOrFile, pluginId: string): Disposable;
|
|
117
|
-
/**
|
|
118
|
-
* Requests an unlock of the note at the given path by aborting every {@link AbortController} that was
|
|
119
|
-
* associated with a lock on it (via {@link EditorLockComponent.lockForPath}'s
|
|
120
|
-
* {@link EditorLockComponentLockForPathOptions.abortController}). The operations holding the lock
|
|
121
|
-
* observe the abort and release their own locks. A no-op when no abortable lock is registered for the
|
|
122
|
-
* path.
|
|
123
|
-
*
|
|
124
|
-
* This lets a consuming plugin wire its own "unlock active note" command without reaching into the
|
|
125
|
-
* lock manager directly.
|
|
126
|
-
*
|
|
127
|
-
* @param app - The Obsidian app instance.
|
|
128
|
-
* @param pathOrFile - The path or file of the note to request an unlock for.
|
|
129
|
-
*/
|
|
130
|
-
export declare function requestEditorUnlockForPath(app: App, pathOrFile: PathOrFile): void;
|
|
131
|
-
/**
|
|
132
|
-
* Releases one lock previously acquired for the note at the given path via {@link lockEditorForPath}.
|
|
133
|
-
*
|
|
134
|
-
* When the last lock is released the note becomes fully editable again and its lock indicators are
|
|
135
|
-
* removed. Calling this when the note is not locked is a no-op.
|
|
136
|
-
*
|
|
137
|
-
* @param app - The Obsidian app instance.
|
|
138
|
-
* @param pathOrFile - The path or file of the note to unlock.
|
|
139
|
-
* @param pluginId - The id of the plugin that holds the lock (e.g. its `manifest.id`); one of its
|
|
140
|
-
* locks on the note is released.
|
|
141
|
-
*/
|
|
142
|
-
export declare function unlockEditorForPath(app: App, pathOrFile: PathOrFile, pluginId: string): void;
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/// <reference path="../library.d.mts" />
|
|
2
|
-
/**
|
|
3
|
-
* @file
|
|
4
|
-
*
|
|
5
|
-
* Note-scoped, reference-counted editor locking.
|
|
6
|
-
*
|
|
7
|
-
* Where {@link toggleEditorReadOnly} from `./editor.ts` toggles the read-only state of a single
|
|
8
|
-
* {@link Editor} instance, the helpers here lock a note by its **path**: while a path is
|
|
9
|
-
* locked, every current and future {@link MarkdownView} of that note (in any window, including
|
|
10
|
-
* popouts) is made read-only and shows a lock indicator in its tab header, its view action bar, and
|
|
11
|
-
* the status bar (while the note is active). Locks are reference-counted per locking plugin, so
|
|
12
|
-
* nested or concurrent operations on the same note are safe — the note is unlocked only when the
|
|
13
|
-
* last lock is released — and the indicators' tooltip lists which plugins currently hold a lock.
|
|
14
|
-
*
|
|
15
|
-
* The acquirers return a {@link Disposable}, so the preferred call style is a `using` declaration
|
|
16
|
-
* that releases automatically at scope exit (including on throw):
|
|
17
|
-
*
|
|
18
|
-
* ```ts
|
|
19
|
-
* using _lock = lockEditorForPath(app, path, this.manifest.id);
|
|
20
|
-
* // ... long-running work (process, processFrontMatter, merge/split) ...
|
|
21
|
-
* // auto-unlocked at scope exit
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* The explicit {@link unlockEditorForPath} pair remains available for non-`using` call sites.
|
|
25
|
-
*/
|
|
26
|
-
import type { App } from 'obsidian';
|
|
27
|
-
import type { PathOrFile } from './file-system.mjs';
|
|
28
|
-
import { ComponentEx } from './components/component-ex.mjs';
|
|
29
|
-
/**
|
|
30
|
-
* Options for {@link EditorLockComponent.lockForPath}.
|
|
31
|
-
*/
|
|
32
|
-
export interface EditorLockComponentLockForPathOptions {
|
|
33
|
-
/**
|
|
34
|
-
* An optional {@link AbortController} associated with the lock. When the lock indicator is
|
|
35
|
-
* right-clicked and the user confirms an unlock (or {@link requestEditorUnlockForPath} is called for
|
|
36
|
-
* the path), this controller is aborted so the operation holding the lock can cancel itself and
|
|
37
|
-
* release the lock in its own cleanup.
|
|
38
|
-
*/
|
|
39
|
-
readonly abortController?: AbortController;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* A per-plugin handle for note-scoped editor locking. Add it as a child of your plugin
|
|
43
|
-
* (`this.addChild(new EditorLockComponent(this.app))`) so that any locks it still holds are released
|
|
44
|
-
* automatically when the plugin unloads — a note can never be left stuck read-only because the
|
|
45
|
-
* plugin that locked it was disabled or reloaded mid-operation.
|
|
46
|
-
*
|
|
47
|
-
* Locks are reference-counted and attributed to this plugin, so the lock indicators' tooltip names
|
|
48
|
-
* it among the plugins currently holding a lock.
|
|
49
|
-
*/
|
|
50
|
-
export declare class EditorLockComponent extends ComponentEx {
|
|
51
|
-
private readonly app;
|
|
52
|
-
private readonly pluginId;
|
|
53
|
-
/**
|
|
54
|
-
* Creates an editor-lock handle owned by a plugin.
|
|
55
|
-
*
|
|
56
|
-
* @param app - The Obsidian app instance.
|
|
57
|
-
* @param pluginId - The id of the owning plugin (e.g. its `manifest.id`). Locks are attributed to
|
|
58
|
-
* it for reference-counting and the indicators' "locked by" tooltip.
|
|
59
|
-
*/
|
|
60
|
-
constructor(app: App, pluginId: string);
|
|
61
|
-
/**
|
|
62
|
-
* Checks whether the note at the given path is currently locked by any plugin.
|
|
63
|
-
*
|
|
64
|
-
* @param pathOrFile - The path or file of the note to check.
|
|
65
|
-
* @returns `true` if the note has at least one active lock, `false` otherwise.
|
|
66
|
-
*/
|
|
67
|
-
isLockedForPath(pathOrFile: PathOrFile): boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Locks the note at the given path on behalf of this plugin, making it read-only in every current
|
|
70
|
-
* and future {@link MarkdownView} until the lock is released. Reference-counted: balance each call
|
|
71
|
-
* with a dispose of the returned {@link Disposable} (ideally via `using`) or {@link unlockForPath}.
|
|
72
|
-
*
|
|
73
|
-
* @param pathOrFile - The path or file of the note to lock.
|
|
74
|
-
* @param options - Optional locking options. Pass an
|
|
75
|
-
* {@link EditorLockComponentLockForPathOptions.abortController} to make the lock cancelable via the
|
|
76
|
-
* indicator's right-click "unlock" menu or {@link requestEditorUnlockForPath}.
|
|
77
|
-
* @returns A {@link Disposable} that releases this lock when disposed. Disposing more than once is a no-op.
|
|
78
|
-
*/
|
|
79
|
-
lockForPath(pathOrFile: PathOrFile, options?: EditorLockComponentLockForPathOptions): Disposable;
|
|
80
|
-
/**
|
|
81
|
-
* Releases every lock still held by this plugin when the component (and thus the plugin) unloads,
|
|
82
|
-
* so no note is left stuck read-only by an operation that never completed.
|
|
83
|
-
*/
|
|
84
|
-
onunload(): void;
|
|
85
|
-
/**
|
|
86
|
-
* Releases one lock previously acquired for the note at the given path via {@link lockForPath}.
|
|
87
|
-
*
|
|
88
|
-
* @param pathOrFile - The path or file of the note to unlock.
|
|
89
|
-
*/
|
|
90
|
-
unlockForPath(pathOrFile: PathOrFile): void;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Checks whether the note at the given path is currently locked.
|
|
94
|
-
*
|
|
95
|
-
* @param app - The Obsidian app instance.
|
|
96
|
-
* @param pathOrFile - The path or file of the note to check.
|
|
97
|
-
* @returns `true` if the note has at least one active lock, `false` otherwise.
|
|
98
|
-
*/
|
|
99
|
-
export declare function isEditorLockedForPath(app: App, pathOrFile: PathOrFile): boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Locks the note at the given path, making it read-only in every current and future
|
|
102
|
-
* {@link MarkdownView} until the lock is released, and showing a lock indicator in the tab header,
|
|
103
|
-
* view action bar, and (while active) the status bar. The indicators' tooltip lists the plugins
|
|
104
|
-
* that currently hold a lock on the note.
|
|
105
|
-
*
|
|
106
|
-
* The lock is reference-counted per calling plugin: each call must be balanced by exactly one
|
|
107
|
-
* release (either disposing the returned {@link Disposable} — ideally via a `using` declaration — or
|
|
108
|
-
* a matching {@link unlockEditorForPath} call).
|
|
109
|
-
*
|
|
110
|
-
* @param app - The Obsidian app instance.
|
|
111
|
-
* @param pathOrFile - The path or file of the note to lock.
|
|
112
|
-
* @param pluginId - The id of the locking plugin (e.g. its `manifest.id`). The lock is attributed to
|
|
113
|
-
* it for reference-counting and the indicators' "locked by" tooltip.
|
|
114
|
-
* @returns A {@link Disposable} that releases this lock when disposed. Disposing more than once is a no-op.
|
|
115
|
-
*/
|
|
116
|
-
export declare function lockEditorForPath(app: App, pathOrFile: PathOrFile, pluginId: string): Disposable;
|
|
117
|
-
/**
|
|
118
|
-
* Requests an unlock of the note at the given path by aborting every {@link AbortController} that was
|
|
119
|
-
* associated with a lock on it (via {@link EditorLockComponent.lockForPath}'s
|
|
120
|
-
* {@link EditorLockComponentLockForPathOptions.abortController}). The operations holding the lock
|
|
121
|
-
* observe the abort and release their own locks. A no-op when no abortable lock is registered for the
|
|
122
|
-
* path.
|
|
123
|
-
*
|
|
124
|
-
* This lets a consuming plugin wire its own "unlock active note" command without reaching into the
|
|
125
|
-
* lock manager directly.
|
|
126
|
-
*
|
|
127
|
-
* @param app - The Obsidian app instance.
|
|
128
|
-
* @param pathOrFile - The path or file of the note to request an unlock for.
|
|
129
|
-
*/
|
|
130
|
-
export declare function requestEditorUnlockForPath(app: App, pathOrFile: PathOrFile): void;
|
|
131
|
-
/**
|
|
132
|
-
* Releases one lock previously acquired for the note at the given path via {@link lockEditorForPath}.
|
|
133
|
-
*
|
|
134
|
-
* When the last lock is released the note becomes fully editable again and its lock indicators are
|
|
135
|
-
* removed. Calling this when the note is not locked is a no-op.
|
|
136
|
-
*
|
|
137
|
-
* @param app - The Obsidian app instance.
|
|
138
|
-
* @param pathOrFile - The path or file of the note to unlock.
|
|
139
|
-
* @param pluginId - The id of the plugin that holds the lock (e.g. its `manifest.id`); one of its
|
|
140
|
-
* locks on the note is released.
|
|
141
|
-
*/
|
|
142
|
-
export declare function unlockEditorForPath(app: App, pathOrFile: PathOrFile, pluginId: string): void;
|