obsidian-typings 1.0.2 → 1.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.0.4
4
+ - Added missing EventRef types
5
+ - **View Registry:** `view-registered`, `view-unregistered`, `extensions-updated`
6
+ - **Metadata Cache:** `initialized`, `finished`
7
+ - **Workspace:** `hover-link`, `tab-group-menu`, `swipe`, `layout-ready`, `url-menu`, `search:results-menu`, `receive-text-menu`,
8
+ `receive-files-menu`, `canvas:selection-menu`, `canvas:node-menu`, `canvas:node-connection-drop-menu`, `canvas:edge-menu`
9
+ - **Workspace Leaf:** `history-change`, `leaf-menu`
10
+ - Added missing typings for `Menu` and `MenuItem` classes
11
+ - Added missing typings for `Tree` and `TreeItem` classes (used in `Outline` and `FileExplorer` plugin views)
12
+ - Set vertical height for a split leaf item via `setDimension`
13
+ - Bumped `electron-types` version
14
+
15
+ ## v1.0.3
16
+ - Change `electron-types` types inclusion
17
+ - Added note in `README.md` on automatically including new types
18
+ - Fix lambda definitions and tsc compilatiion
19
+
3
20
  ## v1.0.2
4
21
  - Changed `any` type to `unknown` to enforcing explicit type casting
5
22
  - Fixed `CONTRIBUTING.md` link in `README.md`
package/README.md CHANGED
@@ -55,6 +55,19 @@ There are three options for installing this package:
55
55
  3. **Add extended typings as submodule** <br> Your IDE will likely pick up the typings automatically when the project is added as a submodule for your plugin, this also makes it simpler to test and submit features to the repository. <br> _Install via:_ `git submodule add https://github.com/Fevol/obsidian-typings.git typings` (or any other folder)
56
56
 
57
57
 
58
+ > [!NOTE]
59
+ > If you prefer to use the original NPM package name `obsidian-typings`, but don't want to explicitly import its types into your source code, you could adapt your `tsconfig.json` as follows:
60
+ > ```json
61
+ > {
62
+ > "compilerOptions": {
63
+ > ...
64
+ > "types": [
65
+ > "obsidian-typings"
66
+ > ]
67
+ > }
68
+ > }
69
+ > ```
70
+
58
71
  ## Disclaimer
59
72
 
60
73
  > [!WARNING]
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: {
@@ -498,7 +524,7 @@ interface CustomCSS extends Component {
498
524
  /**
499
525
  * @internal
500
526
  */
501
- queue: WeakMap<unknown, unknown>;
527
+ queue: WeakMap<object, unknown>;
502
528
  /**
503
529
  * @internal
504
530
  */
@@ -546,7 +572,7 @@ interface CustomCSS extends Component {
546
572
  * Fetch legacy theme CSS using the pre-v1.0.0 theme download pipeline
547
573
  * @returns string obsidian.css contents
548
574
  */
549
- downloadLegacyTheme({ repo: string }): Promise<string>;
575
+ downloadLegacyTheme(arg: { repo: string }): Promise<string>;
550
576
  /**
551
577
  * Enable translucency of application background
552
578
  */
@@ -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
@@ -960,7 +1059,7 @@ interface MetadataTypeManager extends Events {
960
1059
  /**
961
1060
  * @internal Get expected widget type for property and the one inferred from the property value
962
1061
  */
963
- getTypeInfo: (arg: { key: string, type: string, value: unknown }) => { inferred: PropertyWidget, expected: PropertyWidget }
1062
+ getTypeInfo(arg: { key: string, type: string, value: unknown }): { inferred: PropertyWidget, expected: PropertyWidget };
964
1063
  /**
965
1064
  * Get all properties with an assigned widget type
966
1065
  */
@@ -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
@@ -1462,7 +1796,7 @@ interface ViewRegistry extends Events {
1462
1796
  unregisterView(type: string): void;
1463
1797
  }
1464
1798
 
1465
- interface WeakMapWrapper<K extends WeakKey, V> extends WeakMap<K, V> {
1799
+ interface WeakMapWrapper<K extends object, V> extends WeakMap<K, V> {
1466
1800
  map: WeakMap<K, V>;
1467
1801
  }
1468
1802
 
@@ -2051,7 +2385,7 @@ declare module 'obsidian' {
2051
2385
  /**
2052
2386
  * Adds a search cursor to the editor
2053
2387
  */
2054
- searchCursor: (searchString: string) => {
2388
+ searchCursor(searchString: string): {
2055
2389
  current(): { from: EditorPosition, to: EditorPosition };
2056
2390
  findAll(): { from: EditorPosition, to: EditorPosition }[];
2057
2391
  findNext(): { from: EditorPosition, to: EditorPosition };
@@ -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[]): Menu;
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): Menu;
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}): Menu;
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): void;
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): void;
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
  */
@@ -2391,7 +2952,7 @@ declare module 'obsidian' {
2391
2952
  /**
2392
2953
  * Get all backlink information for a file
2393
2954
  */
2394
- getBacklinksForFile: (file?: TFile) => CustomArrayDict<LinkCache>
2955
+ getBacklinksForFile(file?: TFile): CustomArrayDict<LinkCache>
2395
2956
  /**
2396
2957
  * Get paths of all files cached in the vault
2397
2958
  */
@@ -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.2",
3
+ "version": "1.0.4",
4
4
  "description": "Extended type definitions for the Obsidian API (https://obsidian.md)",
5
5
  "main": "",
6
6
  "types": "obsidian-ex.d.ts",
@@ -9,7 +9,7 @@
9
9
  "url": "git+https://github.com/Fevol/obsidian-typings.git"
10
10
  },
11
11
  "keywords": [
12
- "obsmd",
12
+ "obsdmd",
13
13
  "obsidian",
14
14
  "typings",
15
15
  "API"
@@ -24,8 +24,8 @@
24
24
  "obsidian": "^1.4.11"
25
25
  },
26
26
  "devDependencies": {
27
- "@types/electron": "npm:@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"