@real1ty-obsidian-plugins/utils 2.26.0 → 2.27.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/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/dist/components/registered-events-component.d.ts +30 -0
- package/dist/components/registered-events-component.d.ts.map +1 -0
- package/dist/components/registered-events-component.js +43 -0
- package/dist/components/registered-events-component.js.map +1 -0
- package/package.json +1 -1
- package/src/components/index.ts +1 -0
- package/src/components/registered-events-component.ts +56 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC"}
|
package/dist/components/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"./frontmatter-propagation-modal\";\nexport * from \"./input-managers\";\nexport * from \"./whats-new-modal\";\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,kBAAkB,CAAC;AACjC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"./frontmatter-propagation-modal\";\nexport * from \"./input-managers\";\nexport * from \"./registered-events-component\";\nexport * from \"./whats-new-modal\";\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { EventRef } from "obsidian";
|
|
2
|
+
/**
|
|
3
|
+
* Base class that provides event registration and automatic cleanup.
|
|
4
|
+
* Similar to ItemView's registerEvent/registerDomEvent pattern.
|
|
5
|
+
*
|
|
6
|
+
* Subclasses should call cleanupEvents() in their destroy/cleanup method.
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class RegisteredEventsComponent {
|
|
9
|
+
protected eventRefs: EventRef[];
|
|
10
|
+
protected eventCleanupFunctions: Array<() => void>;
|
|
11
|
+
/**
|
|
12
|
+
* Register an Obsidian event (workspace, vault, metadataCache, etc.)
|
|
13
|
+
* Event will be automatically cleaned up when destroy() is called
|
|
14
|
+
*/
|
|
15
|
+
protected registerEvent<T extends keyof any>(emitter: {
|
|
16
|
+
on(event: T, callback: (...args: any[]) => void): void;
|
|
17
|
+
off(event: T, callback: (...args: any[]) => void): void;
|
|
18
|
+
}, event: T, callback: (...args: any[]) => void): void;
|
|
19
|
+
/**
|
|
20
|
+
* Register a DOM event (window, document, or element)
|
|
21
|
+
* Event will be automatically cleaned up when destroy() is called
|
|
22
|
+
*/
|
|
23
|
+
protected registerDomEvent<K extends keyof WindowEventMap>(target: Window | Document | HTMLElement, event: K, callback: (evt: WindowEventMap[K]) => void): void;
|
|
24
|
+
/**
|
|
25
|
+
* Clean up all registered events.
|
|
26
|
+
* Should be called by subclass destroy() method.
|
|
27
|
+
*/
|
|
28
|
+
protected cleanupEvents(): void;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=registered-events-component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registered-events-component.d.ts","sourceRoot":"","sources":["../../src/components/registered-events-component.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;;GAKG;AACH,8BAAsB,yBAAyB;IAC9C,SAAS,CAAC,SAAS,EAAE,QAAQ,EAAE,CAAM;IACrC,SAAS,CAAC,qBAAqB,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,CAAM;IAExD;;;OAGG;IACH,SAAS,CAAC,aAAa,CAAC,CAAC,SAAS,MAAM,GAAG,EAC1C,OAAO,EAAE;QACR,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;QACvD,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI,CAAC;KACxD,EACD,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAChC,IAAI;IAOP;;;OAGG;IACH,SAAS,CAAC,gBAAgB,CAAC,CAAC,SAAS,MAAM,cAAc,EACxD,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,WAAW,EACvC,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,IAAI,GACxC,IAAI;IAOP;;;OAGG;IACH,SAAS,CAAC,aAAa,IAAI,IAAI;CAM/B"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class that provides event registration and automatic cleanup.
|
|
3
|
+
* Similar to ItemView's registerEvent/registerDomEvent pattern.
|
|
4
|
+
*
|
|
5
|
+
* Subclasses should call cleanupEvents() in their destroy/cleanup method.
|
|
6
|
+
*/
|
|
7
|
+
export class RegisteredEventsComponent {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.eventRefs = [];
|
|
10
|
+
this.eventCleanupFunctions = [];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Register an Obsidian event (workspace, vault, metadataCache, etc.)
|
|
14
|
+
* Event will be automatically cleaned up when destroy() is called
|
|
15
|
+
*/
|
|
16
|
+
registerEvent(emitter, event, callback) {
|
|
17
|
+
emitter.on(event, callback);
|
|
18
|
+
this.eventCleanupFunctions.push(() => {
|
|
19
|
+
emitter.off(event, callback);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Register a DOM event (window, document, or element)
|
|
24
|
+
* Event will be automatically cleaned up when destroy() is called
|
|
25
|
+
*/
|
|
26
|
+
registerDomEvent(target, event, callback) {
|
|
27
|
+
target.addEventListener(event, callback);
|
|
28
|
+
this.eventCleanupFunctions.push(() => {
|
|
29
|
+
target.removeEventListener(event, callback);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Clean up all registered events.
|
|
34
|
+
* Should be called by subclass destroy() method.
|
|
35
|
+
*/
|
|
36
|
+
cleanupEvents() {
|
|
37
|
+
for (const cleanup of this.eventCleanupFunctions) {
|
|
38
|
+
cleanup();
|
|
39
|
+
}
|
|
40
|
+
this.eventCleanupFunctions = [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=registered-events-component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registered-events-component.js","sourceRoot":"","sources":["../../src/components/registered-events-component.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,OAAgB,yBAAyB;IAA/C;QACW,cAAS,GAAe,EAAE,CAAC;QAC3B,0BAAqB,GAAsB,EAAE,CAAC;IA6CzD,CAAC;IA3CA;;;OAGG;IACO,aAAa,CACtB,OAGC,EACD,KAAQ,EACR,QAAkC;QAElC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC5B,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,GAAG,EAAE;YACpC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACO,gBAAgB,CACzB,MAAuC,EACvC,KAAQ,EACR,QAA0C;QAE1C,MAAM,CAAC,gBAAgB,CAAC,KAAK,EAAE,QAAyB,CAAC,CAAC;QAC1D,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,GAAG,EAAE;YACpC,MAAM,CAAC,mBAAmB,CAAC,KAAK,EAAE,QAAyB,CAAC,CAAC;QAC9D,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;;OAGG;IACO,aAAa;QACtB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAClD,OAAO,EAAE,CAAC;QACX,CAAC;QACD,IAAI,CAAC,qBAAqB,GAAG,EAAE,CAAC;IACjC,CAAC;CACD","sourcesContent":["import type { EventRef } from \"obsidian\";\n\n/**\n * Base class that provides event registration and automatic cleanup.\n * Similar to ItemView's registerEvent/registerDomEvent pattern.\n *\n * Subclasses should call cleanupEvents() in their destroy/cleanup method.\n */\nexport abstract class RegisteredEventsComponent {\n\tprotected eventRefs: EventRef[] = [];\n\tprotected eventCleanupFunctions: Array<() => void> = [];\n\n\t/**\n\t * Register an Obsidian event (workspace, vault, metadataCache, etc.)\n\t * Event will be automatically cleaned up when destroy() is called\n\t */\n\tprotected registerEvent<T extends keyof any>(\n\t\temitter: {\n\t\t\ton(event: T, callback: (...args: any[]) => void): void;\n\t\t\toff(event: T, callback: (...args: any[]) => void): void;\n\t\t},\n\t\tevent: T,\n\t\tcallback: (...args: any[]) => void\n\t): void {\n\t\temitter.on(event, callback);\n\t\tthis.eventCleanupFunctions.push(() => {\n\t\t\temitter.off(event, callback);\n\t\t});\n\t}\n\n\t/**\n\t * Register a DOM event (window, document, or element)\n\t * Event will be automatically cleaned up when destroy() is called\n\t */\n\tprotected registerDomEvent<K extends keyof WindowEventMap>(\n\t\ttarget: Window | Document | HTMLElement,\n\t\tevent: K,\n\t\tcallback: (evt: WindowEventMap[K]) => void\n\t): void {\n\t\ttarget.addEventListener(event, callback as EventListener);\n\t\tthis.eventCleanupFunctions.push(() => {\n\t\t\ttarget.removeEventListener(event, callback as EventListener);\n\t\t});\n\t}\n\n\t/**\n\t * Clean up all registered events.\n\t * Should be called by subclass destroy() method.\n\t */\n\tprotected cleanupEvents(): void {\n\t\tfor (const cleanup of this.eventCleanupFunctions) {\n\t\t\tcleanup();\n\t\t}\n\t\tthis.eventCleanupFunctions = [];\n\t}\n}\n"]}
|
package/package.json
CHANGED
package/src/components/index.ts
CHANGED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { EventRef } from "obsidian";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base class that provides event registration and automatic cleanup.
|
|
5
|
+
* Similar to ItemView's registerEvent/registerDomEvent pattern.
|
|
6
|
+
*
|
|
7
|
+
* Subclasses should call cleanupEvents() in their destroy/cleanup method.
|
|
8
|
+
*/
|
|
9
|
+
export abstract class RegisteredEventsComponent {
|
|
10
|
+
protected eventRefs: EventRef[] = [];
|
|
11
|
+
protected eventCleanupFunctions: Array<() => void> = [];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Register an Obsidian event (workspace, vault, metadataCache, etc.)
|
|
15
|
+
* Event will be automatically cleaned up when destroy() is called
|
|
16
|
+
*/
|
|
17
|
+
protected registerEvent<T extends keyof any>(
|
|
18
|
+
emitter: {
|
|
19
|
+
on(event: T, callback: (...args: any[]) => void): void;
|
|
20
|
+
off(event: T, callback: (...args: any[]) => void): void;
|
|
21
|
+
},
|
|
22
|
+
event: T,
|
|
23
|
+
callback: (...args: any[]) => void
|
|
24
|
+
): void {
|
|
25
|
+
emitter.on(event, callback);
|
|
26
|
+
this.eventCleanupFunctions.push(() => {
|
|
27
|
+
emitter.off(event, callback);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Register a DOM event (window, document, or element)
|
|
33
|
+
* Event will be automatically cleaned up when destroy() is called
|
|
34
|
+
*/
|
|
35
|
+
protected registerDomEvent<K extends keyof WindowEventMap>(
|
|
36
|
+
target: Window | Document | HTMLElement,
|
|
37
|
+
event: K,
|
|
38
|
+
callback: (evt: WindowEventMap[K]) => void
|
|
39
|
+
): void {
|
|
40
|
+
target.addEventListener(event, callback as EventListener);
|
|
41
|
+
this.eventCleanupFunctions.push(() => {
|
|
42
|
+
target.removeEventListener(event, callback as EventListener);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Clean up all registered events.
|
|
48
|
+
* Should be called by subclass destroy() method.
|
|
49
|
+
*/
|
|
50
|
+
protected cleanupEvents(): void {
|
|
51
|
+
for (const cleanup of this.eventCleanupFunctions) {
|
|
52
|
+
cleanup();
|
|
53
|
+
}
|
|
54
|
+
this.eventCleanupFunctions = [];
|
|
55
|
+
}
|
|
56
|
+
}
|