obsidian-typings 1.0.3 → 1.0.5

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/obsidian-ex.d.ts CHANGED
@@ -3,7 +3,8 @@ import {
3
3
  Command,
4
4
  Component,
5
5
  Constructor,
6
- EditorRange,
6
+ EditorRange,
7
+ EventRef,
7
8
  Events,
8
9
  KeymapInfo,
9
10
  Loc,
@@ -31,6 +32,11 @@ export * from 'obsidian';
31
32
 
32
33
 
33
34
  // TODO: Interfaces that have not been fully typed yet are marked as @internal with 'unknown'
35
+ // TODO: Add Canvas typings (work off base from Dev-Mike, attribute)
36
+ // TODO: Missing event types on sync plugin (but not the internalplugin itself):
37
+ // - new-log
38
+ // - status-change
39
+
34
40
 
35
41
  interface Account {
36
42
  /**
@@ -321,6 +327,26 @@ interface BlockCache {
321
327
  cache: unknown;
322
328
  }
323
329
 
330
+ interface CanvasConnection {
331
+
332
+ }
333
+
334
+ interface CanvasLeaf extends WorkspaceLeaf {
335
+
336
+ }
337
+
338
+ interface CanvasNode {
339
+
340
+ }
341
+
342
+ interface CanvasPlugin extends InternalPlugin {
343
+
344
+ }
345
+
346
+ interface CanvasView {
347
+
348
+ }
349
+
324
350
  interface CMState extends EditorState {
325
351
  vim: {
326
352
  inputState: {
@@ -680,11 +706,35 @@ interface FileExplorerPlugin extends InternalPlugin {
680
706
  }
681
707
 
682
708
  interface FileExplorerView extends View {
709
+ /**
710
+ * Mapping of tree self element to abstract file
711
+ */
683
712
  files: WeakMapWrapper<HTMLElement, TAbstractFile>;
684
-
713
+ /**
714
+ * Mapping of file path to tree item
715
+ */
716
+ fileItems: Record<string, TreeItem<FileTreeItem>>;
717
+ /**
718
+ * Tree view of files
719
+ */
720
+ tree: Tree<FileTreeItem>;
721
+
685
722
  openFileContextMenu(event: Event, fileItemElement: HTMLElement): void;
686
723
  }
687
724
 
725
+ interface FileTreeItem {
726
+ file: TAbstractFile;
727
+ }
728
+
729
+
730
+ interface GlobalSearchLeaf extends WorkspaceLeaf {
731
+
732
+ }
733
+
734
+ interface GlobalSearchPlugin extends InternalPlugin {
735
+
736
+ }
737
+
688
738
  interface HotkeyManager {
689
739
  /**
690
740
  * Reference to App
@@ -773,6 +823,18 @@ interface HoverLinkSource {
773
823
  defaultMod: boolean;
774
824
  }
775
825
 
826
+ interface HoverLinkEvent {
827
+ event: MouseEvent,
828
+ source: "search" | "editor" | "preview" | "properties" | "graph" | "file-explorer" | "hover-link",
829
+ hoverParent: WorkspaceLeaf,
830
+ targetEl: HTMLElement | null,
831
+ linktext: string,
832
+ sourcePath?: string,
833
+ state?: {
834
+ scroll: unknown,
835
+ }
836
+ }
837
+
776
838
  interface ImportedAttachments {
777
839
  data: Promise<ArrayBuffer>;
778
840
  extension: string;
@@ -780,6 +842,37 @@ interface ImportedAttachments {
780
842
  name: string;
781
843
  }
782
844
 
845
+ /**
846
+ * @internal
847
+ */
848
+ interface InfinityScroll {
849
+ height: number;
850
+ lastScroll: number;
851
+ queued: unknown | null;
852
+ renderBlockSize: number;
853
+ rootEl: unknown;
854
+ scrollEl: HTMLElement;
855
+ setWidth: boolean;
856
+ width: number;
857
+
858
+ compute(x: unknown): unknown;
859
+ findElementTop(x: unknown, y: unknown, z: unknown): unknown;
860
+ getRootTop(): unknown;
861
+ invalidate(x: unknown, y: unknown): unknown;
862
+ invalidateAll(): unknown;
863
+ measure(x: unknown, y: unknown): unknown;
864
+ onResize(): unknown;
865
+ onScroll(): unknown;
866
+ queueCompute(): unknown;
867
+ scrollIntoView(x: unknown, y: unknown): unknown;
868
+ update(x: unknown, y: unknown, z: unknown, u: unknown, v: unknown, w: unknown): unknown;
869
+ updateVirtualDisplay(x: unknown): unknown;
870
+
871
+ _layout(x: unknown, y: unknown): unknown;
872
+ _measure(x: unknown): unknown;
873
+ _precompute(x: unknown): unknown;
874
+ }
875
+
783
876
  interface InternalPlugin extends Plugin {
784
877
  disable(): void;
785
878
  enable(): void;
@@ -830,8 +923,13 @@ interface InternalPlugins extends Events {
830
923
  migration: boolean;
831
924
  /**
832
925
  * Plugin configs for internal plugins
926
+ * @remark Prefer usage of getPluginById to access a plugin
833
927
  */
834
- plugins: Record<InternalPluginName, InternalPlugin>;
928
+ plugins: {
929
+ "file-explorer": FileExplorerPlugin,
930
+ "global-search": GlobalSearchPlugin,
931
+ [key: string]: InternalPlugin,
932
+ }
835
933
  /**
836
934
  * @internal Request save of plugin configs
837
935
  */
@@ -843,6 +941,7 @@ interface InternalPlugins extends Events {
843
941
  */
844
942
  getEnabledPluginById(id: InternalPluginName): InternalPlugin | null;
845
943
  getEnabledPluginById(id: 'file-explorer'): FileExplorerPlugin | null;
944
+ getEnabledPluginById(id: 'global-search'): GlobalSearchPlugin | null;
846
945
 
847
946
  /**
848
947
  * Get all enabled internal plugins
@@ -1026,7 +1125,7 @@ interface PluginManifest {
1026
1125
  /**
1027
1126
  * Storage location of the plugin relative to the vault root
1028
1127
  */
1029
- dir: string;
1128
+ dir?: string;
1030
1129
  /**
1031
1130
  * URL for funding the author
1032
1131
  */
@@ -1038,7 +1137,7 @@ interface PluginManifest {
1038
1137
  /**
1039
1138
  * Whether the plugin is designed for desktop use only
1040
1139
  */
1041
- isDesktopOnly: boolean;
1140
+ isDesktopOnly?: boolean;
1042
1141
  /**
1043
1142
  * Minimum Obsidian version compatible with the plugin
1044
1143
  */
@@ -1060,6 +1159,7 @@ interface Plugins {
1060
1159
  app: App;
1061
1160
  /**
1062
1161
  * Set of enabled plugin IDs
1162
+ * @remark The plugin ids aren't guaranteed to be either active (in `app.plugins.plugins`) or installed (in `app.plugins.manifests`)
1063
1163
  */
1064
1164
  enabledPlugins: Set<string>;
1065
1165
  /**
@@ -1067,11 +1167,12 @@ interface Plugins {
1067
1167
  */
1068
1168
  loadingPluginId: string | null;
1069
1169
  /**
1070
- * Manifests of all the plugins
1170
+ * Manifests of all the plugins that are installed
1071
1171
  */
1072
1172
  manifests: Record<string, PluginManifest>;
1073
1173
  /**
1074
- * Mapping of plugin ID to plugin instance
1174
+ * Mapping of plugin ID to active plugin instance
1175
+ * @remark Prefer usage of getPlugin to access a plugin
1075
1176
  */
1076
1177
  plugins: Record<string, Plugin>;
1077
1178
  /**
@@ -1410,6 +1511,224 @@ interface ThemeManifest {
1410
1511
  version: '0.0.0' | string;
1411
1512
  }
1412
1513
 
1514
+ export interface Token extends EditorRange {
1515
+ type: "tag" | "external-link" | "internal-link";
1516
+ }
1517
+
1518
+ interface Tree<T> {
1519
+ /**
1520
+ * Currently active item in tree view
1521
+ */
1522
+ activeDom: TreeNode<T> | null;
1523
+ /**
1524
+ * Reference to App
1525
+ */
1526
+ app: App;
1527
+ /**
1528
+ * Container element of the tree view
1529
+ */
1530
+ containerEl: HTMLElement;
1531
+ /**
1532
+ * Currently focused item in tree view
1533
+ */
1534
+ focusedItem: TreeNode<T> | null;
1535
+ /**
1536
+ * Gets the ID of a tree item given its Node
1537
+ */
1538
+ getNodeId: (node: TreeNode<T>) => string | undefined;
1539
+ /**
1540
+ * Handle collapsing of all nodes
1541
+ */
1542
+ handleCollapseAll: () => void;
1543
+ /**
1544
+ * Handle deletion of selected nodes
1545
+ */
1546
+ handleDeleteSelectedItems: () => void | undefined;
1547
+ /**
1548
+ * Handle renaming of focused item
1549
+ */
1550
+ handleRenameFocusedItem: () => void;
1551
+ /**
1552
+ * ID of the view the tree is associated with
1553
+ */
1554
+ id: string;
1555
+ /**
1556
+ * @internal Facilitates rendering of tree view
1557
+ */
1558
+ infinityScroll: InfinityScroll;
1559
+ /**
1560
+ * Whether all items in the tree are collapsed
1561
+ */
1562
+ isAllCollapsed: boolean;
1563
+ /**
1564
+ * Whether tree items should default to collapsed state
1565
+ */
1566
+ prefersCollapsed: boolean;
1567
+ /**
1568
+ * Request saving of the current fold states
1569
+ */
1570
+ requestSaveFolds: () => void;
1571
+ /**
1572
+ * Key scope for tree view
1573
+ */
1574
+ scope: Scope;
1575
+ /**
1576
+ * Currently selected items in tree view
1577
+ */
1578
+ selectedDoms: Set<TreeNode<T>>;
1579
+ /**
1580
+ * The view the tree is associated with
1581
+ */
1582
+ view: View;
1583
+
1584
+ /**
1585
+ * Root item of the tree view
1586
+ */
1587
+ get root(): TreeNode<T>;
1588
+
1589
+ /**
1590
+ * Change the focused item to the next item in specified direction
1591
+ */
1592
+ changeFocusedItem(direction: "forwards" | "backwards"): void;
1593
+ /**
1594
+ * Unselect all selected items in the tree view
1595
+ */
1596
+ clearSelectedDoms(): void;
1597
+ /**
1598
+ * Mark tree item as deselected
1599
+ */
1600
+ deselectItem(node: TreeNode<T>): void;
1601
+ /**
1602
+ * Get the local storage key for the saved tree view folds
1603
+ */
1604
+ getFoldKey(): string;
1605
+ /**
1606
+ * Handle selection of tree item via keyboard event
1607
+ */
1608
+ handleItemSelection(event: MouseEvent, node: TreeNode<T>): void;
1609
+ /**
1610
+ * @internal Registers all keyboard actions to the tree view keyscope
1611
+ */
1612
+ initializeKeyboardNav(): void;
1613
+ /**
1614
+ * Check whether item is a valid tree item
1615
+ */
1616
+ isItem(node: TreeNode<T> | undefined): boolean;
1617
+ /**
1618
+ * Load the saved fold states of the tree view from local storage
1619
+ */
1620
+ loadFolds(): void;
1621
+ /**
1622
+ * Handle keyboard event for moving/selecting tree item below
1623
+ */
1624
+ onKeyArrowDown(event: KeyboardEvent): void;
1625
+ /**
1626
+ * Handle keyboard event for moving through the hierarchy of tree items (and/or folding/unfolding)
1627
+ */
1628
+ onKeyArrowLeft(event: KeyboardEvent): void;
1629
+ /**
1630
+ * Handle keyboard event for moving through the hierarchy of tree items (and/or folding/unfolding)
1631
+ */
1632
+ onKeyArrowRight(event: KeyboardEvent): void;
1633
+ /**
1634
+ * Handle keyboard event for moving/selecting tree item above
1635
+ */
1636
+ onKeyArrowUp(event: KeyboardEvent): void;
1637
+ /**
1638
+ * Handle keyboard event for opening tree item
1639
+ */
1640
+ onKeyOpen(event: KeyboardEvent): void;
1641
+ /**
1642
+ * @internal Update scroll representation on resize
1643
+ */
1644
+ onResize(): void;
1645
+ /**
1646
+ * Save the current fold states of the tree view to local storage
1647
+ */
1648
+ saveFolds(): void;
1649
+ /**
1650
+ * Mark tree item as selected
1651
+ */
1652
+ selectItem(node: TreeNode<T>): void;
1653
+ /**
1654
+ * Set all items in the tree view to be collapsed or expanded
1655
+ */
1656
+ setCollapseAll(collapse: boolean): void;
1657
+ /**
1658
+ * Set the focused item in the tree view
1659
+ */
1660
+ setFocusedItem(node: TreeNode<T>, scrollIntoView?: boolean): void;
1661
+ /**
1662
+ * (Un)Collapse all items in the tree view
1663
+ */
1664
+ toggleCollapseAll(): void;
1665
+ }
1666
+
1667
+
1668
+
1669
+ type TreeNode<T = object> = T & {
1670
+ childrenEl: HTMLElement;
1671
+ el: HTMLElement;
1672
+ info: {
1673
+ childLeft: number;
1674
+ childLeftPadding: number;
1675
+ childTop: number;
1676
+ computed: boolean;
1677
+ height: number;
1678
+ hidden: boolean;
1679
+ next: boolean;
1680
+ queued: boolean;
1681
+ width: number;
1682
+ };
1683
+ pusherEl: HTMLElement;
1684
+ vChildren: {
1685
+ _children: TreeNode<T>[];
1686
+ owner: TreeNode<T>;
1687
+ };
1688
+ }
1689
+
1690
+ // NOTE: File-explorer root vs Outline root are different (former is a treeitem, latter just a treenode)
1691
+ type TreeItem<T> = TreeNode<T> & {
1692
+ collapseEl: HTMLElement;
1693
+ collapsed: boolean;
1694
+ collapsible: boolean;
1695
+ coverEl: HTMLElement;
1696
+ innerEl: HTMLElement;
1697
+ parent: TreeNode<T> | undefined;
1698
+ selfEl: HTMLElement;
1699
+ view: View;
1700
+
1701
+ /**
1702
+ * Execute collapse functionality on mouse click
1703
+ */
1704
+ onCollapseClick(event: MouseEvent): void;
1705
+ /**
1706
+ * Execute item functionality on clicking tree item
1707
+ */
1708
+ onSelfClick(event: MouseEvent): void;
1709
+ /**
1710
+ * Set clickable state of tree item
1711
+ */
1712
+ setClickable(clickable: boolean): void;
1713
+ /**
1714
+ * Set collapsed state of tree item
1715
+ */
1716
+ setCollapsed(collapsed: boolean, check: boolean): Promise<undefined>;
1717
+ /**
1718
+ * Set collapsible state of tree item
1719
+ */
1720
+ setCollapsible(collapsible: boolean): void;
1721
+ /**
1722
+ * Toggle collapsed state of tree item
1723
+ */
1724
+ toggleCollapsed(check: boolean): Promise<undefined>;
1725
+ /**
1726
+ * @internal Update the tree item's cover element
1727
+ */
1728
+ updateCollapsed(check: boolean): Promise<undefined>;
1729
+ }
1730
+
1731
+
1413
1732
  interface ViewRegistry extends Events {
1414
1733
  /**
1415
1734
  * Mapping of file extensions to view type
@@ -1420,6 +1739,21 @@ interface ViewRegistry extends Events {
1420
1739
  */
1421
1740
  viewByType: Record<string, (leaf: WorkspaceLeaf) => View>;
1422
1741
 
1742
+ /**
1743
+ * Called when a view of type has been registered into the registry
1744
+ */
1745
+ on(name: 'view-registered', callback: (type: string) => void): EventRef;
1746
+
1747
+ /**
1748
+ * Called when a view of type has been unregistered from the registry
1749
+ */
1750
+ on(name: 'view-unregistered', callback: (type: string) => void): EventRef;
1751
+
1752
+ /**
1753
+ * Called when the file extensions mapping has been updated
1754
+ */
1755
+ on(name: 'extensions-updated', callback: () => void): EventRef;
1756
+
1423
1757
  /**
1424
1758
  * Get the view type associated with a file extension
1425
1759
  * @param extension File extension
@@ -2297,21 +2631,236 @@ declare module 'obsidian' {
2297
2631
  interface FileSystemAdapter extends DataAdapter {
2298
2632
  }
2299
2633
 
2634
+
2635
+ interface MarkdownEditView {
2636
+ triggerClickableToken(token: Token, new_leaf: boolean): void;
2637
+ }
2638
+
2639
+ interface MarkdownView {
2640
+ editMode: MarkdownEditView;
2641
+ }
2642
+
2300
2643
  interface MarkdownPreviewView {
2301
2644
  renderer: ReadViewRenderer;
2302
2645
  }
2303
2646
 
2304
2647
  interface Menu {
2648
+ /**
2649
+ * Background for the suggestion menu
2650
+ */
2651
+ bgEl: HTMLElement;
2652
+ /**
2653
+ * The currently active submenu, if any
2654
+ */
2655
+ currentSubmenu?: Menu;
2656
+ /**
2657
+ * DOM element of the menu
2658
+ */
2305
2659
  dom: HTMLElement;
2660
+ /**
2661
+ * Callback to execute when the menu is hidden
2662
+ */
2663
+ hideCallback: () => void;
2664
+ /**
2665
+ * Items contained in the menu
2666
+ */
2306
2667
  items: MenuItem[];
2307
- onMouseOver(evt: MouseEvent): void;
2668
+ /**
2669
+ * @internal Callback that opens the submenu after a delay
2670
+ */
2671
+ openSubmenuSoon: () => void;
2672
+ /**
2673
+ * Parent menu of the current menu
2674
+ */
2675
+ parentMenu: Menu | null;
2676
+ /**
2677
+ * Scope in which the menu is active
2678
+ */
2679
+ scope: Scope;
2680
+ /**
2681
+ * Sections within the menu
2682
+ */
2683
+ sections: string[];
2684
+ /**
2685
+ * @internal Which menuitem is currently selected
2686
+ */
2687
+ selected: number;
2688
+ /**
2689
+ * @internal Configurations for the submenu configs
2690
+ */
2691
+ submenuConfig: Record<string, { title: string, icon: string }>;
2692
+ /**
2693
+ * @internal Whether the submenu is currently unloading
2694
+ */
2695
+ unloading: boolean;
2696
+ /**
2697
+ * Whether the menu is rendered in native mode
2698
+ */
2699
+ useNativeMenu: boolean;
2700
+
2701
+ /**
2702
+ * @internal Children of the menu
2703
+ */
2704
+ _children: unknown[];
2705
+ /**
2706
+ * @internal Events registered on the menu
2707
+ */
2708
+ _events: unknown[];
2709
+ /**
2710
+ * @internal Whether the menu is loaded
2711
+ */
2712
+ _loaded: boolean;
2713
+
2714
+ /**
2715
+ * @internal Add a section to the menu
2716
+ */
2717
+ addSections(items: string[]): this;
2718
+ /**
2719
+ * @internal Close the currently open submenu
2720
+ */
2721
+ closeSubmenu(): void;
2722
+ /**
2723
+ * @internal Check whether the clicked element is inside the menu
2724
+ */
2725
+ isInside(e: HTMLElement): boolean;
2726
+ /**
2727
+ * @internal Move selection to the next item in the menu
2728
+ * @param e - Keyboard event
2729
+ */
2730
+ onArrowDown(e: KeyboardEvent): boolean;
2731
+ /**
2732
+ * @internal Move selection to the previous item in the menu
2733
+ * @param e - Keyboard event
2734
+ */
2735
+ onArrowUp(e: KeyboardEvent): boolean;
2736
+ /**
2737
+ * @internal Move selection into the submenu
2738
+ */
2739
+ onArrowRight(e: KeyboardEvent): boolean;
2740
+ /**
2741
+ * @internal Move selection out of the submenu
2742
+ */
2743
+ onArrowLeft(e: KeyboardEvent): boolean;
2744
+ /**
2745
+ * @internal Execute selected menu item (does nothing if item is submenu)
2746
+ */
2747
+ onEnter(e: KeyboardEvent): boolean;
2748
+ /**
2749
+ * @internal Pre-emptively closes the menu if click is registered on menu item
2750
+ * @param e
2751
+ */
2752
+ onMenuClick(e: MouseEvent): void;
2753
+ /**
2754
+ * @internal Opens submenu if mouse is hovering over item with submenu
2755
+ * @param e - Mouse event
2756
+ */
2757
+ onMouseOver(e: MouseEvent): boolean;
2758
+ /**
2759
+ * @internal Registers dom events and scope for the menu
2760
+ */
2761
+ onload(): void;
2762
+ /**
2763
+ * @internal Unregisters scope for the menu
2764
+ */
2765
+ onunload(): void;
2766
+ /**
2767
+ * @internal Open the submenu of the selected item
2768
+ * @param item - Item to open submenu for
2769
+ */
2770
+ openSubmenu(item: MenuItem): void;
2771
+ /**
2772
+ * @internal Select the item at the specified index (after either hovering or arrowing over it)
2773
+ * @param index
2774
+ */
2775
+ select(index: number): void;
2776
+ /**
2777
+ * @internal Set the parent element of the menu (i.e. for workspace leaf context menu)
2778
+ * @param el - Element to set as parent
2779
+ */
2780
+ setParentElement(el: HTMLElement): this;
2781
+ /**
2782
+ * @internal Add a section to the submenu config
2783
+ * @param section
2784
+ * @param submenu
2785
+ */
2786
+ setSectionSubmenu(section: string, submenu: {title: string, icon: string}): this;
2787
+ /**
2788
+ * @internal Sort the items in the menu
2789
+ */
2790
+ sort(): void;
2791
+ /**
2792
+ * @internal Unselect the currently selected item and closes the submenu
2793
+ */
2794
+ unselect(): void;
2308
2795
  }
2309
2796
 
2310
2797
  interface MenuItem {
2311
- callback(): void;
2798
+ /**
2799
+ * The callback that is executed when the menu item is clicked
2800
+ */
2801
+ callback?: () => void;
2802
+ /**
2803
+ * Whether the menu item is checked
2804
+ */
2805
+ checked: boolean | null;
2806
+ /**
2807
+ * Check icon element of the menu item, only present if the item is checked
2808
+ */
2809
+ checkIconEl?: HTMLElement;
2810
+ /**
2811
+ * Whether the menu item is disabled
2812
+ */
2813
+ disabled: boolean;
2814
+ /**
2815
+ * Dom element of the menu item
2816
+ */
2312
2817
  dom: HTMLElement;
2818
+ /**
2819
+ * Icon element of the menu item
2820
+ */
2821
+ iconEl: HTMLElement;
2822
+ /**
2823
+ * Menu the item is in
2824
+ */
2825
+ menu: Menu;
2826
+ /**
2827
+ * The section the item belongs to
2828
+ */
2829
+ section: string;
2830
+ /**
2831
+ * The submenu that is attached to the item
2832
+ */
2833
+ submenu: Menu | null;
2834
+ /**
2835
+ * Title of the menu item
2836
+ */
2837
+ titleEl: string;
2838
+
2839
+ /**
2840
+ * @internal Executes the callback of the onClick event (if not disabled)
2841
+ * @param e - Mouse or keyboard event
2842
+ */
2843
+ handleEvent(e: MouseEvent | KeyboardEvent): void;
2844
+ /**
2845
+ * @internal Remove the icon element from the menu item
2846
+ */
2847
+ removeIcon(): void;
2848
+ /**
2849
+ * @deprecated
2850
+ * @internal Calls `setChecked`, prefer usage of that function instead
2851
+ * @param active - Whether the menu item should be checked
2852
+ */
2853
+ setActive(active: boolean): this;
2854
+ /**
2855
+ * Create a submenu on the menu item
2856
+ * @tutorial Creates the foldable menus with more options as seen when you right-click in the editor (e.g. "Insert", "Format", ...)
2857
+ */
2313
2858
  setSubmenu(): Menu;
2314
- disabled: boolean;
2859
+ /**
2860
+ * @internal Add warning styling to the menu item
2861
+ * @param warning - Whether the menu item should be styled as a warning
2862
+ */
2863
+ setWarning(warning: boolean): this;
2315
2864
  }
2316
2865
 
2317
2866
  interface MetadataCache {
@@ -2384,6 +2933,18 @@ declare module 'obsidian' {
2384
2933
  */
2385
2934
  workerResolve: unknown;
2386
2935
 
2936
+ /**
2937
+ * Called whenever the metadatacache is fully loaded in
2938
+ * @remark 'finished' is also emitted when the cache is initialized
2939
+ */
2940
+ on(name: 'initialized', callback: () => void): EventRef;
2941
+
2942
+ /**
2943
+ * Called whenever the metadatacache has finished updating
2944
+ */
2945
+ on(name: 'finished', callback: () => void): EventRef;
2946
+
2947
+
2387
2948
  /**
2388
2949
  * Get all property infos of the vault
2389
2950
  */
@@ -2729,6 +3290,27 @@ declare module 'obsidian' {
2729
3290
  deleted: boolean;
2730
3291
  }
2731
3292
 
3293
+ /**
3294
+ * @internal Used for Obsidian's touch event handling
3295
+ */
3296
+ interface ObsidianTouchEvent {
3297
+ direction: "x" | "y";
3298
+ evt: TouchEvent;
3299
+ points: number;
3300
+ registerCallback: ({
3301
+ move: (x: number) => void,
3302
+ cancel: () => void,
3303
+ finish: (x: number, y: number, z: number) => void
3304
+ }),
3305
+ startX: number;
3306
+ startY: number;
3307
+ targetEl: HTMLElement;
3308
+ touch: Touch;
3309
+
3310
+ x: number;
3311
+ y: number;
3312
+ }
3313
+
2732
3314
  interface Vault {
2733
3315
  /**
2734
3316
  * Low-level file system adapter for read and write operations
@@ -2753,8 +3335,56 @@ declare module 'obsidian' {
2753
3335
  */
2754
3336
  fileMap: Record<string, TAbstractFile>;
2755
3337
 
3338
+ /**
3339
+ * Called whenever any of Obsidian's settings are changed
3340
+ * @remark Does *not* trigger when a particular plugin's settings are changed, for that, you could monkey-patch the `saveSettings` method of a plugin instance
3341
+ */
2756
3342
  on(name: 'config-changed', callback: () => void, ctx?: unknown): EventRef;
2757
3343
 
3344
+ /**
3345
+ * @internal Triggered whenever a file gets loaded internally
3346
+ */
3347
+ on(name: 'raw', callback: (path: string) => void, ctx?: unknown): EventRef;
3348
+
3349
+ /**
3350
+ * @internal Not accessible
3351
+ * @remark Always prefer usage of on(name: 'rename', ...) instead
3352
+ */
3353
+ // on(name: 'renamed', callback: (oldPath: string, newPath: string) => void): EventRef;
3354
+
3355
+ /**
3356
+ * @internal Not accessible
3357
+ * @remark Always prefer usage of on(name: 'modify', ...) instead
3358
+ */
3359
+ // on(name: 'modified', callback: () => void): EventRef;
3360
+
3361
+ /**
3362
+ * @internal Not accessible
3363
+ */
3364
+ // on(name: 'file-created', callback: () => void): EventRef;
3365
+
3366
+ /**
3367
+ * @internal Not accessible
3368
+ */
3369
+ // on(name: 'folder-created', callback: () => void): EventRef;
3370
+
3371
+ /**
3372
+ * @internal Not accessible
3373
+ */
3374
+ // on(name: 'file-removed', callback: () => void): EventRef;
3375
+
3376
+ /**
3377
+ * @internal Not accessible
3378
+ */
3379
+ // on(name: 'folder-removed', callback: () => void): EventRef;
3380
+
3381
+ /**
3382
+ * @internal Not accessible
3383
+ */
3384
+ // on(name: 'closed', callback: () => void): EventRef;
3385
+
3386
+
3387
+
2758
3388
  /**
2759
3389
  * @internal Add file as child/parent to respective folders
2760
3390
  */
@@ -2993,6 +3623,68 @@ declare module 'obsidian' {
2993
3623
  */
2994
3624
  undoHistory: StateHistory[];
2995
3625
 
3626
+ /**
3627
+ * @internal Triggers when user hovers over any note link element (file explorer, editor, ...)
3628
+ * @remark Used for preparing (Ctrl) hover previews
3629
+ */
3630
+ on(name: 'hover-link', callback: (event: HoverLinkEvent) => void, ctx?: unknown): EventRef;
3631
+
3632
+ /**
3633
+ * @internal Called whenever user opens tab group menu (contains e.g. stacked tabs button)
3634
+ */
3635
+ on(name: 'tab-group-menu', callback: (tabMenu: Menu, tabsLeaf: WorkspaceTabs) => void, ctx?: unknown): EventRef;
3636
+
3637
+ /**
3638
+ * @internal Triggers when user swipes open left/right sidebar
3639
+ */
3640
+ on(name: 'swipe', callback: (touchEvents: ObsidianTouchEvent[]) => void, ctx?: unknown): EventRef;
3641
+
3642
+ /**
3643
+ * Triggers when workspace layout is loaded
3644
+ * @remark Prefer usage of onLayoutReady instead
3645
+ */
3646
+ on(name: 'layout-ready', callback: () => void, ctx?: unknown): EventRef;
3647
+
3648
+ /**
3649
+ * @internal Triggers when user right-clicks on external URL in editor
3650
+ */
3651
+ on(name: 'url-menu', callback: (menu: Menu, url: string) => void, ctx?: unknown): EventRef;
3652
+
3653
+ /**
3654
+ * Triggers when user clicks on 'N results' button in search view
3655
+ */
3656
+ on(name: 'search:results-menu', callback: (menu: Menu, search: GlobalSearchLeaf) => void, ctx?: unknown): EventRef;
3657
+
3658
+ /**
3659
+ * @internal Called when user shares text on mobile
3660
+ */
3661
+ on(name: 'receive-text-menu', callback: (menu: Menu, x: unknown) => void, ctx?: unknown): EventRef;
3662
+
3663
+ /**
3664
+ * @internal Called when user shares files on mobile
3665
+ */
3666
+ on(name: 'receive-files-menu', callback: (menu: Menu, x: unknown) => void, ctx?: unknown): EventRef;
3667
+
3668
+ /**
3669
+ * Triggers when the user opens a context menu on a selection of multiple nodes in the canvas
3670
+ */
3671
+ on(name: 'canvas:selection-menu', callback: (menu: Menu, canvasView: CanvasView) => void, ctx?: unknown): EventRef;
3672
+
3673
+ /**
3674
+ * Triggers when the user opens a context menu on a single node in the canvas
3675
+ */
3676
+ on(name: 'canvas:node-menu', callback: (menu: Menu, node: CanvasNode) => void, ctx?: unknown): EventRef;
3677
+
3678
+ /**
3679
+ * Triggers when the user drops edge connection to empty space in the canvas
3680
+ */
3681
+ on(name: 'canvas:node-connection-drop-menu', callback: (menu: Menu, originalNode: CanvasNode, connection: CanvasConnection) => void, ctx?: unknown): EventRef;
3682
+
3683
+ /**
3684
+ * Triggers when the user opens a context menu on a connection in the canvas
3685
+ */
3686
+ on(name: 'canvas:edge-menu', callback: (menu: Menu, connection: CanvasConnection) => void, ctx?: unknown): EventRef;
3687
+
2996
3688
  /**
2997
3689
  * @internal Change active leaf and trigger leaf change event
2998
3690
  */
@@ -3212,6 +3904,25 @@ declare module 'obsidian' {
3212
3904
  tabHeaderEl: HTMLElement;
3213
3905
  tabHeaderInnerIconEl: HTMLElement;
3214
3906
  tabHeaderInnerTitleEl: HTMLElement;
3907
+
3908
+ /**
3909
+ * Triggers when the leaf's history gets updated (e.g. when new file is opened, or moving through history)
3910
+ */
3911
+ on(name: 'history-change', callback: () => void, ctx?: unknown): EventRef;
3912
+
3913
+ /**
3914
+ * Triggers when context menu action is executed on the leaf
3915
+ */
3916
+ on(name: 'leaf-menu', callback: (menu: Menu, leaf: WorkspaceLeaf) => void, ctx?: unknown): EventRef;
3917
+
3918
+ /**
3919
+ * Set the vertical height a leaf may occupy if it is in a split. The height is not set directly, but
3920
+ * by setting the flex-grow (css) of the element. This means to predictably affect the height, you also
3921
+ * need to use setDimension on the other leafs of the column. (The flex-grow values of every leaf work
3922
+ basically like a ratio, e.g. 1:2 meaning the first leaf takes 33% of the height, and the second 67%.)
3923
+ * @param flexgrow - sets the flex-grow of the leaf. (0-100)
3924
+ */
3925
+ setDimension(flexgrow?: number | null): void;
3215
3926
  }
3216
3927
 
3217
3928
  interface WorkspaceSplit {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "obsidian-typings",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Extended type definitions for the Obsidian API (https://obsidian.md)",
5
5
  "main": "",
6
6
  "types": "obsidian-ex.d.ts",
@@ -24,8 +24,8 @@
24
24
  "obsidian": "^1.4.11"
25
25
  },
26
26
  "devDependencies": {
27
- "@ophidian/electron-types": "^24.3.1",
28
- "@types/node": "^20.10.7"
27
+ "@types/node": "^20.10.7",
28
+ "@types/electron": "npm:@ophidian/electron-types"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "tsc --build --force"
package/CHANGELOG.md DELETED
@@ -1,18 +0,0 @@
1
- # Changelog
2
-
3
- ## v1.0.3
4
- - Change `electron-types` types inclusion
5
- - Added note in `README.md` on automatically including new types
6
- - Fix lambda definitions and tsc compilatiion
7
-
8
- ## v1.0.2
9
- - Changed `any` type to `unknown` to enforcing explicit type casting
10
- - Fixed `CONTRIBUTING.md` link in `README.md`
11
- - Added badges to `README.md`
12
-
13
- ## v1.0.1
14
- - Automated npm publishing
15
-
16
- ## v1.0.0 (initial npm release)
17
- - Made package installable via npm
18
- - Clarified README, added contribution guidelines
package/CONTRIBUTING.md DELETED
@@ -1,235 +0,0 @@
1
- # Introduction
2
-
3
- ## General Notes
4
- Feel free to start typing any part of the Obsidian API that is not yet typed, or fixing/adding additional descriptions to existing typings.
5
- If you are unsure about anything, don't hesitate to open an issue.
6
-
7
- ### TSDoc
8
- Please use [TSDoc](https://tsdoc.org/) to document the typings. This will allow the documentation to be automatically generated
9
- within your IDE, and can help with the discoverability of the typings.
10
-
11
-
12
- Example:
13
- ```ts
14
- interface someObject {
15
- /**
16
- * Does something specific
17
- * @param val1 Enables some functionality
18
- * @tutorial Useful for implementing some features for your plugin
19
- * @remark Prefer using `someOtherMethod` instead
20
- */
21
- someMethod(val1: boolean): number;
22
-
23
- /**
24
- * Does something that you're not certain about, and should probably not be used
25
- * @internal
26
- */
27
- someInternalMethod(): void;
28
- }
29
- ```
30
-
31
- > [!NOTE]
32
- > `@internal` --- Method is *very likely* not fully/correctly typed, and/or is not intended to be used by plugins.
33
- >
34
- > `@remark` --- Alternatives that should be used instead, or warnings about the function.
35
- >
36
- > `@tutorial` --- Short description on how the function could be used in your plugin.
37
- >
38
- > `@deprecated` --- Method is deprecated in a particular version (can't be found in `app.js` anymore).
39
-
40
-
41
- # Tutorial
42
-
43
- ## Adding new typings
44
-
45
- ### Finding/Discovering new typings
46
-
47
- The first step to add new typings, is finding the object/interface/module you want to add typings for within the Obsidian app.
48
- One of the easiest way to do this, is to open the developer console (Ctrl+Shift+I), and start searching for the interface you wish to
49
- type from the `app.` object.
50
-
51
- If you want to, for example, add typings for the `InternalPlugins` object, you can type `app.internalPlugins` into the console,
52
- which will produce the following output:
53
-
54
- ![images/prototype-reference.png](images/prototype-reference.png)
55
-
56
- Note how the internalPlugins object contains multiple prototypes: the `InternalPlugins` interface itself, but also
57
- the `Events` class and then the `Object` literal (does not need to be typed). This can be determined this by looking at the other definitions in the (un)official API,
58
- and checking whether the two objects define the same properties.
59
-
60
- Thus, to define `InternalPlugin`, you can start by adding each of the methods and properties to a `InternalPlugins` interface:
61
-
62
- ```ts
63
- interface InternalPlugins extends Events {
64
- // Variables
65
- app: App;
66
- config: Record<unknown, unknown>;
67
- migration: unknown;
68
- plugins: Record<unknown, unknown>;
69
-
70
- // Methods
71
- requestSaveConfig(): unknown;
72
- enable(): unknown;
73
- getEnabledPluginById(var1: unknown): unknown;
74
- getEnabledPlugins(): unknown;
75
- // ...
76
- }
77
- ```
78
- To keep it simple, we first add `unknown` as type to every variable and method -- unless it is obvious what the type should be
79
- (i.e. `app` will always be an instance of `App`).
80
-
81
- Next up, is the most tedious part of adding typings: finding the correct types for each of the methods and variables.
82
-
83
- ### Typing variables
84
-
85
- The easiest way to start, is by tackling the variables first. For example, in the console output, you can see that `config`
86
- is mapping a string to `true`. In this case, it would be safe to assume that the type of `config` is `Record<string, boolean>`.
87
-
88
- ```ts
89
- interface InternalPlugins extends Events {
90
- // ...
91
- config: Record<string, boolean>;
92
- // ...
93
- }
94
- ```
95
-
96
- However, you can take this one step further still by considering the fact that each string is essentialy a different plugin ID.
97
- In this case, we might just define a new type that contains all the plugin IDs, and use this as the key for the `config` object:
98
-
99
- ```ts
100
- type InternalPluginName = 'audio-recorder' | 'backlink' | 'bookmarks' | 'canvas' /*| ... */;
101
- interface InternalPlugins extends Events {
102
- // ...
103
- config: Record<InternalPluginName, boolean>;
104
- // ...
105
- }
106
- ```
107
-
108
- Similarly, you can define the `plugins` variable as `Record<InternalPluginName, unknown>`.
109
-
110
- Further, it is safe to assume that each element in `Plugins` would be some instance of a `InternalPlugin` class, so we
111
- will also need to add a new interface for this:
112
-
113
- ```ts
114
- interface InternalPlugin {
115
- app: App;
116
- commands: unknown;
117
- // etc. (repeat the same procedure)
118
- }
119
-
120
- interface InternalPlugins extends Events {
121
- // ...
122
- plugins: Record<InternalPluginName, InternalPlugin>;
123
- // ...
124
- }
125
- ```
126
-
127
- Make sure to also add brief descriptions (using [TSDoc](https://tsdoc.org/)) to each of the variables. Mark variables that you are not entirely sure about with `@internal`.
128
- Feel free to copy descriptions from previous typings, or from the official API.
129
-
130
-
131
- ### Typing methods
132
-
133
- Typing methods is a bit more difficult, as aside you will need to know what the method does, and what the expected input and output is.
134
-
135
- You could start by typing the methods that do not take any arguments, and have a simple return type. For example, the `requestSaveConfig` method.
136
- From the name, we can already make the assumption that this method will probably _not_ return anything, as it is just telling
137
- the app that a config should be saved, the method will thus _likely_ be of type `void`.
138
-
139
- However, to make sure whether this assumption is correct, you _**should**_ check the source code (see next section).
140
- If possible, you can also run the method in the console, and see what happens (in this case, nothing happens, so it is likely just `void`).
141
-
142
- As before, if you are not certain about the return type or the workings of the function in general,
143
- add a `@internal` tag to the method description, and/or mark the return type as `unknown`.
144
-
145
-
146
- ```ts
147
- interface InternalPlugins extends Events {
148
- // ...
149
- /**
150
- * @internal Request save of plugin configs
151
- */
152
- requestSaveConfig(): unknown;
153
- // ...
154
- }
155
- ```
156
-
157
- Next up, are methods that take arguments. For example, the `getEnabledPluginById` method takes a single argument.
158
- It is very likely that this argument will just be of type `InternalPluginName`, but again, you could easily verify this by
159
- running the method in the console (i.e. `app.internalPlugins.getEnabledPluginById('audio-recorder')` and `app.internalPlugins.getEnabledPluginById('wrong-id')`).
160
-
161
- ```ts
162
- interface InternalPlugins extends Events {
163
- // ...
164
- /**
165
- * Get an internal plugin by ID
166
- * @param id - ID of the plugin to get
167
- * @returns Plugin instance
168
- */
169
- getEnabledPluginById(id: InternalPluginName): InternalPlugin;
170
- // ...
171
- }
172
- ```
173
-
174
-
175
- ## Traversing and analysing the source code
176
-
177
- Finally, this is both the most tedious but also the most important technique: finding the definition of the method in the minified source code.
178
-
179
- Start off by going back to the console, and going into the `Sources` tab. Here you will find the `app.js` file where
180
- all the internal methods are defined.
181
-
182
- 1. Go to the `Sources` tab
183
- 2. Select the `app.js` file
184
- 3. `Pretty format` the code (optional)
185
- 4. Copy the code to your IDE of choice (optional, but recommended)
186
-
187
-
188
- ![images/accessing-main.png](images/accessing-main.png)
189
-
190
- With access to the minified code, you can now start searching through it and find the definition of the method you are trying to type.
191
-
192
- For any method "XYZ", start by just searching for "XYZ". Generally, the method is defined as either:
193
- - `t.XYZ = ...` (for prototype methods)
194
- - `t.prototype.XYZ = ...` (for prototype methods)
195
- - `function XYZ(` (for internal/minified methods)
196
-
197
- At this stage, you might get lucky and get a single definition, or you may get multiple definitions of the method.
198
- In the latter case,
199
- you will need try to look at the context of the code to determine which interface/class the method belongs to.
200
- The main tip for finding the correct definition, is to look at the other methods being defined on the prototype,
201
- and check if these match with the other methods of your object.
202
-
203
- With the correct line found for the definition, you can now start analysing the code to determine the input/output types
204
- and its behaviour.
205
-
206
- For example, the `requestSaveConfig` method (seen earlier) is defined as follows:
207
-
208
- ```js
209
- n.requestSaveConfig = at(n.saveConfig.bind(n), 1e3, !0),
210
- ```
211
-
212
- Here, we find the following three things:
213
- - `at` is a minified function that takes three arguments, and its return value is the return value of the method
214
- - `1e3` is shorthand notation for `1000`
215
- - `!0` is shorthand notation for `true`
216
-
217
- (There are many shorthands and structural changes that you will need to get used to in the minified code)
218
-
219
- Since we don't know what `at` does, we need to start searching through the code again. Make sure to enable caps + whole word search, as `at` is a very common word.
220
- Start by searching for `function at`, or `.prototype.at`. With any luck, this will lead you to the following definition:
221
-
222
- ```js
223
- function at(e, t, n) {
224
- void 0 === t && (t = 0),
225
- void 0 === n && (n = !1);
226
- var i, r = null, o = null, a = null, s = 0, l = function() {
227
- var t = o
228
- , n = a;
229
- /* ... */
230
- }
231
- }
232
- ```
233
-
234
- You may want to pass the code through your favourite flavour of LLM or de-minifier to make the code at least somewhat understandable.
235
- Depending on whether you manage to decipher the code, you can now explicitly define the behaviour and/or types of the method.
Binary file
Binary file