### Codeblock configuration examples Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/7-codeblock-api.md Various configurations for the smart-connections codeblock. ```markdown ```smart-connections { "results_limit": 5, "show_graph": false } ``` ``` ```markdown ```smart-connections { "results_limit": 20, "show_graph": true, "render_markdown": true, "show_full_path": true } ``` ``` ```markdown ```smart-connections { "results_limit": 10, "render_markdown": false, "show_graph": false } ``` ``` -------------------------------- ### Connections Settings Configuration Object Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/7-codeblock-api.md Example of the full configuration object structure passed to components. ```javascript { connections_settings: { results_limit: 10, show_graph: false, components: { connections_list_v4: { show_graph: false }, connections_list_item_v3: { render_markdown: true, show_full_path: false } } } } ``` -------------------------------- ### Initialize plugin components Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/1-plugin-entry-point.md The initialize method handles new user setup, environment loading, and view registration. ```javascript async initialize() { // New user flow this.is_new_user().then(async (is_new) => { if (!is_new) return; // Show getting started modal window.setTimeout(() => { StoryModal.open(this, {...}); }, 1000); // Setup connections view location this.apply_connections_view_location(); this.open_connections_view(); // Add .smart-env to gitignore this.add_to_gitignore("\n\n# Ignore Smart Environment folder\n.smart-env"); }); // General initialization for all users await this.SmartEnv.wait_for({ loaded: true }); this.wrap_connections_view_open(); this.apply_connections_view_location(); this.register_connections_view_location_listener(); register_smart_connections_codeblock(this); // Initialize footer connections if (!this.connections_footer_view) { this.registerEditorExtension(connections_footer_plugin); this.connections_footer_view = new ConnectionsFooterView(this); } this.toggled_footer_connections(); await this.check_for_updates(); } ``` -------------------------------- ### Configure Smart Connections Codeblock Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/7-codeblock-api.md Examples of JSON configuration for controlling result limits, graph visualization, and markdown rendering. ```json { "results_limit": 8, "show_graph": true } ``` ```json { "results_limit": 5, "render_markdown": false } ``` ```json { "results_limit": 10, "show_full_path": true } ``` -------------------------------- ### Get Smart Environment configuration Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/1-plugin-entry-point.md Getter for the Smart Environment configuration object. ```javascript get smart_env_config() { if (!this._smart_env_config) { this._smart_env_config = { ...smart_env_config }; } return this._smart_env_config; } ``` -------------------------------- ### Insert codeblock into editor Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/7-codeblock-api.md Examples for programmatically generating and inserting codeblocks into the Obsidian editor. ```javascript // Programmatically generate a codeblock string const block = build_connections_codeblock({ results_limit: 15, show_graph: true }); // Insert via editor const editor = view.editor; editor.replaceSelection(block); // Or with command command = { id: 'insert-connections-codeblock', name: 'Insert: Connections codeblock', editorCallback: (editor) => { editor.replaceSelection(build_connections_codeblock()); } } ``` -------------------------------- ### Get Environment Instance Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/4-ui-components.md Retrieves the SmartEnv instance associated with the current plugin. ```javascript get env() { return this.plugin.env; } ``` -------------------------------- ### Get Connection Item Options Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/3-connections-lists-collection.md Retrieves available component options for rendering connection items by filtering the environment configuration. ```javascript get_connections_list_item_options() { return Object.entries(this.env.config.components || {}) .filter(([key, fn]) => key.startsWith('connections_list_item_')) .map(([value, fn]) => ({ value, name: fn.display_name || value, description: fn.display_description })) ; } ``` ```javascript [ { value: 'connections_list_item_v3', name: 'Component Display Name', description: 'Component description' } ] ``` -------------------------------- ### Get connections_list_component_settings_config Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/3-connections-lists-collection.md Retrieves and formats component-specific settings configuration with prefixed keys for the settings tab. ```javascript get connections_list_component_settings_config() { if(!this.settings?.connections_list_component_key || (!this.env.is_pro && ['none', 'connections_list_v4_2', 'connections_list_v3'].includes(...))) { this.settings.connections_list_component_key = 'connections_list_v4'; } if(!this.settings?.components?.connections_list_v4) { if(!this.settings.components) this.settings.components = {}; this.settings.components.connections_list_v4 = { ...defaults }; } const component_key = this.settings.connections_list_component_key; if(!component_key || component_key === 'none') return null; const component_module = this.env.config.components?.[component_key]; const config = typeof component_module?.settings_config === 'function' ? component_module.settings_config(this) : component_module?.settings_config ; if (!config) return null; return Object.fromEntries( Object.entries(config) .map(([k, v]) => [`components.${component_key}.${k}`, v]) ); } ``` -------------------------------- ### Get Connections for Active File Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md Retrieves connection results for the currently active file using the plugin's environment instance. ```javascript const plugin = app.plugins.plugins['smart-connections']; const env = plugin.env; const activeFile = app.workspace.getActiveFile(); const source = env.smart_sources.get(activeFile.path); const results = await source.connections.get_results(); ``` -------------------------------- ### Plugin Initialization and Interaction Overview Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/1-plugin-entry-point.md This snippet outlines the entry point behavior and available user interaction methods for the plugin. ```javascript // This is called by Obsidian when the plugin loads // Plugin instance is automatically created and initialized // Users can interact via: // 1. Ribbon icons (connections, footer, random note) // 2. Commands: // - Open: Connections view // - Open: Random note from connections // - Show: Getting started slideshow // - Insert: Connections codeblock // - Toggle: Footer connections // 3. Settings tab in Obsidian settings // 4. Inline codeblocks: ```smart-connections ... ``` ``` -------------------------------- ### Get frontmatter_inclusions Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/3-connections-lists-collection.md Parses and returns the frontmatter include matchers from settings. ```javascript get frontmatter_inclusions() { return parse_frontmatter_filter_lines(this.settings.frontmatter_filter_include); } ``` -------------------------------- ### Action Registration and Usage Patterns Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/6-action-handlers.md Demonstrates how to invoke registered actions from the environment configuration, view contexts, or specific items. ```javascript // Usage pattern await connections_list.actions.connections_list_refresh({ view: this }); // Or from within a view context await this.env.connections_lists.actions.connections_list_copy_as_links({ results: customResults }); // Item-level actions const item = results[0].item; await item.actions.view_connections(); ``` -------------------------------- ### Execute Action Handlers Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/6-action-handlers.md Demonstrates how to access connection lists and trigger specific actions like refreshing, copying links, hiding items, pinning, and opening random connections. ```javascript // From a view or action handler const connections_list = env.connections_lists.get(item.key); // Refresh connections await connections_list.actions.connections_list_refresh({ view: connectionView }); // Copy results as links await connections_list.actions.connections_list_copy_as_links({ results: results }); // Hide a connection const result = results[0]; await connections_list.actions.hide(result.item, {}); // Toggle pin state await connections_list.actions.toggle_pinned(result.item, {}); // Open random connection const success = await connections_list.actions.connections_list_open_random_connection({ results: results, event: mouseEvent }); // View source connections const source = env.smart_sources.get('path/to/file.md'); await source.actions.view_connections(); ``` -------------------------------- ### Get Connections for Active File Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md Retrieves connection results for the currently active file in the workspace. ```APIDOC ## Get Connections for Active File ### Description Retrieves the connection results for the currently active file by accessing the plugin's smart_sources environment. ### Code Example ```javascript const plugin = app.plugins.plugins['smart-connections']; const env = plugin.env; const activeFile = app.workspace.getActiveFile(); const source = env.smart_sources.get(activeFile.path); const results = await source.connections.get_results(); ``` ``` -------------------------------- ### Get item views mapping Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/1-plugin-entry-point.md Getter that returns a mapping of view types to their respective classes. ```javascript get item_views() { return { ConnectionsItemView, ReleaseNotesView: this.ReleaseNotesView, }; } ``` -------------------------------- ### Programmatically Configure Plugin Settings Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/8-configuration.md Demonstrates how to access the plugin environment and modify settings like view location, filters, and component visibility at runtime. ```javascript const plugin = app.plugins.plugins['smart-connections']; const env = plugin.env; // Disable footer connections for this session env.connections_lists.settings.footer_connections = false; // Change view location env.connections_lists.settings.connections_view_location = 'left'; // Set a high result limit for a specific use case env.connections_lists.settings.results_limit = 50; // Configure filters env.connections_lists.settings.exclude_filter = 'Templates/,Archive/'; env.connections_lists.settings.include_filter = 'Projects/'; // Update component settings env.connections_lists.settings.components.connections_list_v4.show_graph = false; // Get all current settings console.log(env.connections_lists.settings); ``` -------------------------------- ### open_settings() Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/4-ui-components.md Opens the plugin settings tab. ```APIDOC ## open_settings() ### Description Opens the plugin settings tab. ### Returns - **Promise** ``` -------------------------------- ### Get frontmatter_exclusions Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/3-connections-lists-collection.md Parses and returns the frontmatter exclude matchers from settings, which take precedence over inclusions. ```javascript get frontmatter_exclusions() { return parse_frontmatter_filter_lines(this.settings.frontmatter_filter_exclude); } ``` -------------------------------- ### Connections Lists Usage Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/3-connections-lists-collection.md Demonstrates accessing the collection, retrieving settings, creating connections for a source, and parsing frontmatter filters. ```javascript // Access the connections lists collection const collections = env.connections_lists; // Get settings console.log(collections.settings.results_limit); // e.g., 20 console.log(collections.settings.results_collection_key); // 'smart_sources' // Create connections for a source const source = env.smart_sources.get('path/to/file.md'); const connections_list = collections.new_item(source); // Get connections list for a source (if already created) const connections = source.connections; // Get results const results = await connections.get_results(); // Check validated keys console.log(collections.score_algo_key); // Returns validated key or 'similarity' console.log(collections.results_collection_key); // Returns 'smart_sources' or 'smart_blocks' // Parse frontmatter filters const includes = collections.frontmatter_inclusions; const excludes = collections.frontmatter_exclusions; ``` -------------------------------- ### Get results_collection_key Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/3-connections-lists-collection.md Retrieves the results collection key, defaulting to 'smart_sources' if the stored key is not found in the environment. ```javascript get results_collection_key() { const stored_key = this.settings?.results_collection_key; if(this.env[stored_key]) return stored_key; return 'smart_sources'; } ``` -------------------------------- ### Copy Connections as Links Action Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/6-action-handlers.md Formats connection results as markdown links and copies them to the system clipboard. ```javascript export async function connections_list_copy_as_links(params = {}) { const results = params.results || this.results; if (!results || !Array.isArray(results) || !results.length) { return; } const markdown = format_connections_as_links(results); await navigator.clipboard.writeText(markdown); // Show success notification } ``` -------------------------------- ### Get score_algo_key Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/3-connections-lists-collection.md Retrieves the configured scoring algorithm key, defaulting to 'similarity' if the stored key is invalid. ```javascript get score_algo_key() { const stored_key = this.settings?.score_algo_key; if(this.env.config?.actions?.[stored_key]) return stored_key; return 'similarity'; } ``` -------------------------------- ### pre_process(params) Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/2-connections-list-api.md Prepares parameters by migrating legacy state and executing pre-processing hooks defined in the environment or scoring algorithm. ```javascript async pre_process(params) { migrate_hidden_connections(this.item); if(typeof this.actions.connections_list_pre_process === 'function') { await this.actions.connections_list_pre_process(params); } if(typeof this.env.config?.actions?.[params.score_algo_key]?.pre_process === 'function') { await this.env.config.actions[params.score_algo_key].pre_process.call(this.item, params); } } ``` -------------------------------- ### Define Basic Configuration Settings Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/8-configuration.md Configures core result collection behavior and result limits. ```javascript { "results_collection_key": { name: "Connection results type", type: "dropdown", description: "Choose whether results should be sources or blocks.", options_callback: () => [ { value: 'smart_sources', name: 'Sources' }, { value: 'smart_blocks', name: 'Blocks' } ] }, "results_limit": { name: "Results limit", type: "number", description: "Adjust the number of connections displayed (default 20)." } } ``` -------------------------------- ### Get Ranked Results Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/2-connections-list-api.md Fetches ranked connections with promise-based caching to prevent redundant concurrent requests. ```javascript async get_results(params = {}) { if (this._results_promise) return this._results_promise; const p = this._get_results(params); this._results_promise = p; this._results_promise.finally(() => { if (this._results_promise === p) { this._results_promise = null; } }); return this._results_promise; } ``` ```javascript { item: Source|Block, // The connected item score: number, // Similarity score (0-1) score_display: number, // Display score (may differ from score) connections_list: ConnectionsList, // Reference to this list collection_key: string, // Collection of the item item_key: string, // Key of the item // ... other item properties } ``` -------------------------------- ### Import smart-entities types Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/9-types-and-interfaces.md Core entity types for sources and blocks. ```javascript Source, // Source file entity Block // Code block entity ``` -------------------------------- ### build_connections_codeblock(settings) Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/7-codeblock-api.md Generates a formatted smart-connections codeblock string based on the provided settings object. ```APIDOC ## build_connections_codeblock(settings) ### Description Generates a string representing a smart-connections codeblock, which can be inserted into an editor. ### Parameters - **settings** (object) - Optional - An object containing configuration options such as results_limit, show_graph, render_markdown, and show_full_path. ### Returns - **string** - A formatted markdown codeblock string. ### Example ```javascript const block = build_connections_codeblock({ results_limit: 15, show_graph: true }); ``` ``` -------------------------------- ### Default Settings Structure Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/8-configuration.md Reference the default configuration object schema for Smart Connections. ```javascript { results_collection_key: 'smart_sources', score_algo_key: 'similarity', connections_post_process: 'none', results_limit: 20, connections_view_location: 'right', exclude_frontmatter_blocks: true, connections_list_component_key: 'connections_list_v4', connections_list_item_component_key: 'connections_list_item_v3', frontmatter_filter_include: '', frontmatter_filter_exclude: '', components: { connections_list_v4: { show_graph: true, }, connections_list_item_v3: { render_markdown: true, show_full_path: false, } }, } ``` -------------------------------- ### Open plugin settings Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/4-ui-components.md Navigates to the plugin settings tab within the application. ```javascript async open_settings() { await this.app.setting.open(); await this.app.setting.openTabById(this.plugin.manifest.id); } ``` -------------------------------- ### Get connection feedback items Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/5-utility-functions.md Parses connection state to identify hidden and pinned items, updating the params object in place. ```javascript function get_connections_feedback_items(connections_list, params) { params.hidden = []; params.hidden_keys = []; params.pinned = []; params.pinned_keys = []; const connections_state = connections_list.item.data?.connections || {}; Object.entries(connections_state).forEach(([key, state]) => { if (!state || (state.hidden == null && state.pinned == null)) return; const [collection_key, ...item_key_parts] = key.split(':'); if (!collection_key || !item_key_parts.length) return; const item_key = item_key_parts.join(':'); const collection = connections_list.env[collection_key]; if (!collection) return; const item = collection.get(item_key); if (!item) return; // Hidden-only: not in pinned list if (state.hidden && !state.pinned) { params.hidden.push(item); params.hidden_keys.push(item_key); } // Any pinned (pinned-only or hidden+pinned) if (state.pinned) { params.pinned.push(item); params.pinned_keys.push(item_key); } }); } ``` -------------------------------- ### Import obsidian-smart-env types Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/9-types-and-interfaces.md Environment and plugin base classes. ```javascript SmartEnv, // Smart Environment runtime SmartItemView, // Base view class SmartPlugin // Base plugin class ``` -------------------------------- ### Export Smart Connections Plugin Class Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md Main plugin class entry point exported from src/main.js. ```javascript export default class SmartConnectionsPlugin extends SmartPlugin ``` -------------------------------- ### Define ConnectionsFooterView Class Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/4-ui-components.md Initializes the view with plugin references and sets up internal state for visibility management. ```javascript export class ConnectionsFooterView { constructor(plugin) { this.plugin = plugin; this.app = plugin.app; this.register_env_listeners(); this.container_map = {}; this._detach_visibility_guard = null; } } ``` -------------------------------- ### Interact with Smart Connections View Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/4-ui-components.md Access the view instance, render items, and manage pause state controls. ```javascript // Access the connections view const view = workspace.getLeavesOfType('smart-connections-view')[0]?.view; // Render specific item await view.render_view({ connections_item: env.smart_sources.get('path/to/file.md') }); // Toggle pause state view.paused = true; view.pause_controls?.update(true); // Listen to pause control updates view.register_pause_controls({ update: (isPaused) => { console.log('Pause state:', isPaused); } }); // Footer view is managed automatically by the plugin // Enable via settings: env.connections_lists.settings.footer_connections = true ``` -------------------------------- ### Define Footer Settings Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/8-configuration.md Configures the visibility of connections at the bottom of notes. ```javascript { "footer_connections": { group: 'Footer connections', name: "Show footer connections", type: "toggle", description: "Show connections at the bottom of each note." } } ``` -------------------------------- ### Initialize plugin lifecycle Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/1-plugin-entry-point.md The onload method registers settings, icons, commands, and views when the plugin is loaded. ```javascript onload() { this.app.workspace.onLayoutReady(this.initialize.bind(this)); this.SmartEnv.create(this, this.smart_env_config); this.addSettingTab(new this.ConnectionsSettingsTab(this.app, this)); add_smart_dice_icon(); this.register_commands(); this.register_item_views(); this.register_ribbon_icons(); } ``` -------------------------------- ### Import smart-collections types Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/9-types-and-interfaces.md Base classes for collections and items. ```javascript Collection, // Base collection class CollectionItem // Base collection item class ``` -------------------------------- ### build_connections_codeblock(settings) Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/5-utility-functions.md Generates a markdown codeblock string configured for the smart-connections plugin. ```APIDOC ## build_connections_codeblock(settings) ### Description Builds a smart-connections markdown codeblock string containing the provided settings as a JSON object. ### Parameters - **settings** (object) - Optional - Codeblock configuration object to be JSON-serialized. ### Returns - **string** - Markdown codeblock string. ### Example ```javascript const block = build_connections_codeblock({ results_limit: 10, show_graph: true }); ``` ``` -------------------------------- ### Basic Smart Connections Codeblock Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/7-codeblock-api.md Displays connections for the current note using default settings. ```markdown ```smart-connections ``` ``` -------------------------------- ### Listen to connection events Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/README.md Subscribe to the 'sources:opened' event to trigger logic when a source is opened. ```javascript env.events.on('sources:opened', (event) => { console.log('Opened:', event.item_key); }); ``` -------------------------------- ### View Connections Action Implementation Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/6-action-handlers.md Emits the connections:show event to trigger navigation and state updates in the connections view. ```javascript export async function source_view_connections(params = {}) { // Emit connections:show event this.env.events.emit('connections:show', { collection_key: this.collection_key, item_key: this.key, }); } ``` -------------------------------- ### Show Connections for a Specific Note Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md Triggers the display of connections for a specific file path by emitting a custom event. ```javascript env.events.emit('connections:show', { collection_key: 'smart_sources', item_key: 'path/to/file.md' }); ``` -------------------------------- ### Define Display Settings Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/8-configuration.md Configures the sidebar location for the Connections view. ```javascript { "connections_view_location": { group: "Display", name: "Connections sidebar location", type: "dropdown", description: "Choose which sidebar opens when showing the Connections view.", options_callback: () => [ { value: 'right', name: 'Right sidebar' }, { value: 'left', name: 'Left sidebar' } ] } } ``` -------------------------------- ### Configure MenuDefinition Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/9-types-and-interfaces.md Structure for defining menu entries including title, icon, order, and callback. ```javascript { title: string, icon?: string, order?: number, callback?: () => void | Promise } ``` -------------------------------- ### Accessing Settings from Plugin Context Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/8-configuration.md Retrieving settings directly from the plugin environment instance. ```javascript // Access via environment const plugin = app.plugins.plugins['smart-connections']; const connections_settings = plugin.env.connections_lists.settings; console.log(connections_settings.results_limit); console.log(connections_settings.footer_connections); ``` -------------------------------- ### ConnectionsFooterView Lifecycle Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/10-events-and-lifecycle.md Outlines the sequence of events from creation to unloading for the ConnectionsFooterView. ```text 1. Created ├── Constructor runs ├── Register environment listeners └── Initialize container map 2. render_view() Called ├── Check if enabled ├── Attach visibility guard (last line check) ├── Get active entity ├── Render component ├── Update CodeMirror DOM effect └── (Mobile) Add status bar 3. Scroll/Resize Detected ├── Check if last line visible ├── Trigger render if visible └── Detach guard 4. Unload └── Clean up listeners and guards ``` -------------------------------- ### Render a Smart Component Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md Use this method to render registered components within the Smart Environment. ```javascript await env.smart_components.render_component(component_key, scope, params) ``` -------------------------------- ### Listen for sources:opened event Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/10-events-and-lifecycle.md Updates the connections view when a note is opened, using a 250ms debounce. ```javascript env.events.on('sources:opened', (event) => { // Debounced connections view update (250ms) if (!this.paused) { this.render_view({ connections_item: ... }); } }) ``` -------------------------------- ### Retrieve Connections List Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/7-codeblock-api.md Fetches or initializes the connections list associated with the entity. ```javascript const connections_list = entity.connections; ``` -------------------------------- ### open_note(target_path, event) Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/1-plugin-entry-point.md Opens a specific note given its path, with optional support for mouse events. ```APIDOC ## open_note(target_path, event) ### Description Opens a note at the specified path. Optionally accepts a MouseEvent to handle modifier keys like Cmd/Ctrl click. ### Parameters - **target_path** (string) - Required - Path to the note to open - **event** (MouseEvent) - Optional - Mouse event to use for opening ### Returns - **Promise** ``` -------------------------------- ### Register environment listeners Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/4-ui-components.md Sets up event listeners for environment changes that trigger view updates. Includes debouncing for performance and visibility checks. ```javascript register_env_listeners() { let handle_current_source_debounce; register_env_event_listener(this, 'sources:opened', (event = {}) => { if (this.paused) return; if (!is_visible(this.container)) return; const connections_item = this.env[event.collection_key || 'smart_sources']?.get(event.item_key || event.key); if (connections_item.key === this.current?.key) return; if (handle_current_source_debounce) window.clearTimeout(handle_current_source_debounce); handle_current_source_debounce = window.setTimeout(() => { this.render_view({connections_item}); }, 250); }); register_env_event_listener(this, 'settings:changed', (event) => { if(event.path?.includes('expanded_view')) return; if(event.path?.includes('connections_lists') && is_visible(this.container)){ this.render_view({connections_item: this.current}); } }); register_env_event_listener(this, 'connections:show', (event) => { if(event.collection_key && event.item_key){ const collection = this.env[event.collection_key]; const item = collection.get(event.item_key); if(item){ this.paused = true; this.pause_controls?.update?.(true); this.render_view({connections_item: item}); } } }); register_env_event_listener(this, 'items:embedded', (event = {}) => { if( event.collection_key === this.current?.collection_key && event.keys?.includes(this.current?.key) && is_visible(this.container) ){ this.render_view({connections_item: this.current}); } }); } ``` -------------------------------- ### Initialize ConnectionsItemView Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/4-ui-components.md Constructor for initializing the view with the workspace leaf and plugin instance, setting default state for pause controls and current items. ```javascript constructor(leaf, plugin) { super(leaf, plugin); this.paused = false; this.pause_controls = null; this.current = null; } ``` -------------------------------- ### Create New Connection Item Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/3-connections-lists-collection.md Instantiates a new ConnectionsList, adds it to the collection, and attaches a getter to the item. ```javascript new_item(item) { const connections_list = new this.item_type(this.env, { collection_key: item.collection_key, item_key: item.key }); this.set(connections_list); Object.defineProperty(item, 'connections', { get: () => connections_list, configurable: true }); return connections_list; } ``` -------------------------------- ### insert_settings_after(key, config, new_settings) Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/5-utility-functions.md Inserts new settings after a specific key in a settings config object. ```APIDOC ## insert_settings_after(key, config, new_settings) ### Description Updates a settings configuration object by inserting new settings after a specified key. ### Parameters - **key** (string) - Key to insert after. - **config** (object) - Current settings config. - **new_settings** (object) - Settings to insert. ### Returns - **object** - Updated config with new settings inserted. ``` -------------------------------- ### Define Default Settings Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/3-connections-lists-collection.md The static getter defining default configuration values for the connections list collection. ```javascript static get default_settings() { return { results_collection_key: 'smart_sources', score_algo_key: 'similarity', connections_post_process: 'none', results_limit: 20, connections_view_location: 'right', exclude_frontmatter_blocks: true, connections_list_component_key: 'connections_list_v4', connections_list_item_component_key: 'connections_list_item_v3', frontmatter_filter_include: '', frontmatter_filter_exclude: '', components: { connections_list_v4: { show_graph: true, }, connections_list_item_v3: { render_markdown: true, show_full_path: false, } }, }; } ``` -------------------------------- ### Wrap connections view open method Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/1-plugin-entry-point.md Wraps the base open_connections_view method to ensure proper leaf location handling. ```javascript wrap_connections_view_open() { if (this._open_connections_view_base || typeof this.open_connections_view !== 'function') { return; } this._open_connections_view_base = this.open_connections_view.bind(this); this.open_connections_view = (...args) => { this.ensure_connections_view_leaf_location(); return this._open_connections_view_base(...args); }; } ``` -------------------------------- ### Project Directory Structure Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/README.md Visual representation of the source code organization for the plugin. ```text src/ ├── main.js # Plugin entry point ├── collections/ # Collection classes ├── items/ # Collection item classes ├── views/ # View classes ├── components/ # UI components ├── actions/ # Action handlers └── utils/ # Utility functions ``` -------------------------------- ### Retrieve connections for the active note Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/README.md Access the plugin environment and fetch connection results for the currently active file in the workspace. ```javascript const plugin = app.plugins.plugins['smart-connections']; const env = plugin.env; const file = app.workspace.getActiveFile(); const source = env.smart_sources.get(file.path); const results = await source.connections.get_results(); ``` -------------------------------- ### Access Plugin Internals from Console Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md Retrieves plugin settings and computes connections for a specific file path. ```javascript const plugin = app.plugins.plugins['smart-connections']; const env = plugin.env; // Inspect connections lists console.log(env.connections_lists.settings); // Get connections for a source const source = env.smart_sources.get('path/to/file.md'); const connections_list = source.connections; const results = await connections_list.get_results(); ``` -------------------------------- ### Listen for settings:changed event Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/10-events-and-lifecycle.md Reacts to configuration changes, such as view location or connection list updates. ```javascript env.events.on('settings:changed', (event) => { if (event.path?.includes('connections_view_location')) { plugin.apply_connections_view_location(); } if (event.path?.includes('connections_lists')) { view.render_view({ connections_item: this.current }); } }) ``` -------------------------------- ### Configured Smart Connections Codeblock Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/7-codeblock-api.md Customizes the connections display using a JSON object within the codeblock. ```markdown ```smart-connections { "results_limit": 10, "show_graph": false } ``` ``` -------------------------------- ### Register connections view location listener Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/1-plugin-entry-point.md Sets up an event listener to trigger location updates when the relevant setting changes. ```javascript register_connections_view_location_listener() { if (this.connections_view_location_listener || !this.env?.events) return; this.connections_view_location_listener = this.env.events.on('settings:changed', (event) => { if (!event?.path?.includes?.('connections_view_location')) return; this.apply_connections_view_location(); }); } ``` -------------------------------- ### Display Environment Loading State Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/7-codeblock-api.md Shown when the environment is not ready; provides a retry mechanism. ```text Loading connections environment... [Retry button] ``` -------------------------------- ### Define plugin commands Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/1-plugin-entry-point.md Returns a mapping of command IDs to command configurations, extending the base class commands. ```javascript get commands() { return { ...super.commands, random_connection: { id: open_random_connection_command.id, name: open_random_connection_command.name, callback: async () => { await open_random_connection_command.callback(this); } }, getting_started: { id: "smart-connections-getting-started", name: "Show: Getting started slideshow", callback: () => { StoryModal.open(this, { title: 'Getting Started With Smart Connections', url: 'https://smartconnections.app/story/smart-connections-getting-started/?utm_source=sc-op-command', }); } }, insert_connections_codeblock: { id: 'insert-connections-codeblock', name: 'Insert: Connections codeblock', editorCallback: (editor) => { editor.replaceSelection(build_connections_codeblock()); } }, toggle_footer_connections: { id: 'toggle-footer-connections', name: 'Toggle: Footer connections', callback: () => { const settings = this.env.connections_lists.settings; settings.footer_connections = !settings.footer_connections; } }, }; } ``` -------------------------------- ### Validate Configuration Settings Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/8-configuration.md Implements getter logic to validate stored settings and provide fallback values if the configuration is invalid. ```javascript // score_algo_key validation get score_algo_key() { const stored_key = this.settings?.score_algo_key; if(this.env.config?.actions?.[stored_key]) return stored_key; return 'similarity'; // Fallback } // results_collection_key validation get results_collection_key() { const stored_key = this.settings?.results_collection_key; if(this.env[stored_key]) return stored_key; return 'smart_sources'; // Fallback } ``` -------------------------------- ### Export Connections Collections and Config Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md Collection management and configuration exports from src/collections/connections_lists.js. ```javascript export class ConnectionsLists extends Collection export const connections_filter_config export function settings_config(scope) export default { class: ConnectionsLists, ... } ``` -------------------------------- ### Build smart-connections markdown codeblock Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/5-utility-functions.md Generates a formatted markdown codeblock string containing JSON-serialized settings. Returns an empty codeblock if no settings are provided. ```javascript export function build_connections_codeblock(settings = null) { const json = settings ? JSON.stringify(settings, null, 2) : ''; return `\`\`\`smart-connections\n${json}\n\`\`\`\n`; } ``` ```javascript // Without settings const block = build_connections_codeblock(); // Returns: "```smart-connections\n\n```\n" // With settings const block = build_connections_codeblock({ results_limit: 10, show_graph: true }); ``` -------------------------------- ### Export Utility Functions Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md General utility functions for formatting and processing connections. ```javascript export function format_connections_as_links(results) export function build_connections_codeblock(settings) export function pre_process(params) // Called as action ``` -------------------------------- ### Listen to Plugin Events Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md Registers event listeners for source opening and setting changes. ```javascript env.events.on('sources:opened', (event) => { console.log('Opened:', event.item_key); }); env.events.on('settings:changed', (event) => { console.log('Setting changed:', event.path, '=', event.value); }); ``` -------------------------------- ### ConnectionsItemView Lifecycle Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/10-events-and-lifecycle.md Outlines the sequence of events from view creation to destruction for the ConnectionsItemView. ```text 1. View Created └── Constructor runs, initialize state 2. render_view() Called ├── Determine connections_item ├── Render component ├── Register environment listeners └── Emit connections:opened 3. Event Listeners Active ├── sources:opened (debounced 250ms) ├── settings:changed ├── connections:show (manual trigger) └── items:embedded 4. View Destroyed └── Event listeners cleaned up ``` -------------------------------- ### Insert settings into configuration object Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/5-utility-functions.md Inserts a new settings object after a specified key within an existing configuration object. ```javascript const original = { 'setting_a': { name: 'Setting A' }, 'setting_b': { name: 'Setting B' } }; const updated = insert_settings_after('setting_a', original, { 'new_setting': { name: 'New Setting' } }); // Result has new_setting between setting_a and setting_b ``` -------------------------------- ### Pre-process connection request parameters Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/5-utility-functions.md Populates default values, initializes filters, and handles exclusion sets for connection requests. This function mutates the provided params object directly. ```javascript export function pre_process(params) { // Fill defaults if (!params.limit) params.limit = this.settings?.results_limit ?? 20; if (!params.results_collection_key) { params.results_collection_key = this.collection.results_collection_key; } if (!params.filter) params.filter = {}; if (!params.score_algo_key) params.score_algo_key = this.collection.score_algo_key; // Set target item params.to_item = this.item; // Setup filter arrays if (!params.filter.exclude_keys) params.filter.exclude_keys = []; if (!params.filter.exclude_key_starts_with_any) { params.filter.exclude_key_starts_with_any = []; } // Setup frontmatter filters if (!params.filter.frontmatter) params.filter.frontmatter = {}; if (!params.filter.frontmatter.include) { params.filter.frontmatter.include = this.collection.frontmatter_inclusions; } if (!params.filter.frontmatter.exclude) { params.filter.frontmatter.exclude = this.collection.frontmatter_exclusions; } // Populate hidden/pinned feedback get_connections_feedback_items(this, params); // Build exclusion sets const exclude_keys_set = new Set(params.filter.exclude_keys); exclude_keys_set.add(this.item.key); // Always exclude self params.hidden_keys.forEach((key) => exclude_keys_set.add(key)); params.pinned_keys.forEach((key) => exclude_keys_set.add(key)); params.filter.exclude_keys = Array.from(exclude_keys_set); // Handle block-level exclusions if (params.results_collection_key === 'smart_blocks') { // Additional block-specific logic... } } ``` -------------------------------- ### Define ribbon icons Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/1-plugin-entry-point.md Returns a mapping of ribbon icon IDs to their respective configurations, including icons, descriptions, and callbacks. ```javascript get ribbon_icons() { return { connections: { icon_name: "smart-connections", description: "Smart Connections: Open connections view", callback: () => { this.open_connections_view(); } }, footer_connections: { description: 'Toggle Footer Connections', icon_name: 'smart-footer-connections', callback: () => { const settings = this.env.connections_lists.settings; settings.footer_connections = !settings.footer_connections; } }, random_note: { icon_name: "smart-dice", description: "Smart Connections: Open random connection", callback: () => { this.open_random_connection(); } }, }; } ``` -------------------------------- ### Listen to Settings Changes Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md Registers an event listener to react to changes in the plugin settings. ```APIDOC ## Listen to Settings Changes ### Description Subscribes to the 'settings:changed' event to perform actions when specific plugin settings are updated. ### Code Example ```javascript env.events.on('settings:changed', (event) => { if (event.path?.includes('connections_lists.results_limit')) { console.log('Limit changed to:', event.value); } }); ``` ``` -------------------------------- ### Display Entity Not Found Error Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/7-codeblock-api.md Indicates that the current file has not been embedded yet and will auto-initialize upon completion. ```markdown Entity not found: path/to/file.md ``` -------------------------------- ### Smart Connections View API Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/4-ui-components.md Methods and properties for interacting with the Smart Connections view instance. ```APIDOC ## view.render_view(options) ### Description Renders a specific item within the Smart Connections view. ### Parameters - **connections_item** (object) - Required - The source object retrieved from `env.smart_sources.get(path)`. ## view.paused ### Description A boolean property to toggle the pause state of the view. ## view.register_pause_controls(callbacks) ### Description Registers a callback to listen for updates to the pause state. ### Parameters - **update** (function) - Required - A callback function that receives the boolean `isPaused` state. ``` -------------------------------- ### Define ConnectionsShowEvent Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/9-types-and-interfaces.md Event structure for showing connections. ```javascript { collection_key: string, // Required item_key: string, // Required // ... parent event properties } ``` -------------------------------- ### Utility Functions Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md Helper functions for formatting and processing connection data. ```APIDOC ## Utility Functions ### format_connections_as_links(results) Formats connection results into clickable markdown links. ### build_connections_codeblock(settings) Constructs the configuration object for the connections codeblock. ### pre_process(params) Processes parameters as an action before connection rendering. ``` -------------------------------- ### Codeblock Render Flow Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/10-events-and-lifecycle.md Describes the process for registering and rendering a smart-connections markdown codeblock. ```text registerMarkdownCodeBlockProcessor('smart-connections', ...) ├── Parse JSON config from codeblock ├── Get entity for source file ├── Show loading UI ├── Call renderCodeblock() │ ├── Get connections_list │ ├── Wait for environment ready │ ├── Render connections_codeblock component │ ├── Append to container │ └── Register settings:changed listener └── Re-render on settings change ``` -------------------------------- ### Render Connections Component Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/7-codeblock-api.md Renders the connections component using the parsed configuration. ```javascript const connections_container = await plugin.env.smart_components.render_component( 'connections_codeblock', connections_list, { ...cb_config } ); ``` -------------------------------- ### Open a specific note Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/1-plugin-entry-point.md Opens a note at the provided path, optionally handling mouse events for navigation. ```javascript async open_note(target_path, event = null) { await open_note(this, target_path, event); } ``` -------------------------------- ### Accessing Settings from ConnectionsList Context Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/8-configuration.md Retrieving settings within a connections list or action scope. ```javascript // Within a connections list or action const limit = this.settings.results_limit; const collection = this.collection.results_collection_key; const algo = this.collection.score_algo_key; ``` -------------------------------- ### Generate codeblock string Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/7-codeblock-api.md Function to create a formatted smart-connections codeblock string for editor insertion. ```javascript export function build_connections_codeblock(settings = null) { const json = settings ? JSON.stringify(settings, null, 2) : ''; return `\`\`\`smart-connections\n${json}\n\`\`\`\n`; } ``` -------------------------------- ### Listen to Settings Changes Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md Registers an event listener to react to specific configuration changes within the plugin settings. ```javascript env.events.on('settings:changed', (event) => { if (event.path?.includes('connections_lists.results_limit')) { console.log('Limit changed to:', event.value); } }); ``` -------------------------------- ### connections_context_items(results) Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/5-utility-functions.md Builds context-ready items from connection results. ```APIDOC ## connections_context_items(results) ### Description Extracts item data from connection results for use in Smart Context or other context builders. ### Parameters - **results** (any) - The connection results to process. ``` -------------------------------- ### render_view(params, container) Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/4-ui-components.md Renders the connections view with a specific item or the current active file. ```APIDOC ## render_view(params, container) ### Description Renders the connections view with a specific item or the current active file. Defaults to the current active file if no item is specified. ### Parameters - **params** (object) - Optional - Rendering parameters - **params.connections_item** (Source) - Optional - Item to show connections for - **container** (HTMLElement) - Optional - Container to render into (defaults to this.container) ### Returns - **Promise** ``` -------------------------------- ### Format Results as Markdown Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md Converts connection results into a markdown link format and copies the output to the system clipboard. ```javascript const results = await connectionsList.get_results(); const markdown = format_connections_as_links(results); await navigator.clipboard.writeText(markdown); ``` -------------------------------- ### Define ComponentBuildFunction Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/9-types-and-interfaces.md Signature for component build functions returning an HTML string. ```javascript async function build_html( scope: any, params?: object ): Promise ``` -------------------------------- ### Open Random Connection Action Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/6-action-handlers.md Selects and opens a random connection from the current results list. Respects optional mouse events for window handling. ```javascript export async function connections_list_open_random_connection(params = {}) { const results = params.results || this.results; if (!results?.length) return false; const random = get_random_connection(results); if (!random?.item) return false; await this.env.open_source(random.item, params.event); return true; } ``` -------------------------------- ### ConnectionsListsSettings Schema Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/9-types-and-interfaces.md The complete configuration object for managing connection lists, filtering, and component settings. ```javascript { // Collection selection results_collection_key: 'smart_sources' | 'smart_blocks', // Limits and display results_limit: number, // Default 20 connections_view_location: 'left' | 'right', expanded_view?: boolean, // Show all expanded // Features footer_connections: boolean, inline_connections: boolean, // Filtering exclude_inlinks: boolean, exclude_outlinks: boolean, include_filter: string, // Comma-separated paths exclude_filter: string, // Comma-separated paths frontmatter_filter_include: string, // Newline-delimited frontmatter_filter_exclude: string, // Newline-delimited exclude_frontmatter_blocks: boolean, // Algorithm and processing score_algo_key: string, // 'similarity' default connections_post_process: string, // 'none' default // Component selection connections_list_component_key: string, // 'connections_list_v4' connections_list_item_component_key: string, // 'connections_list_item_v3' // Component-specific settings components: { connections_list_v4?: { show_graph: boolean }, connections_list_item_v3?: { render_markdown: boolean, show_full_path: boolean } } } ``` -------------------------------- ### Define ConnectionsList Class Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/2-connections-list-api.md Extends CollectionItem to manage ranked connections for a specific source item. ```javascript export class ConnectionsList extends CollectionItem { static key = 'connections_list'; static get defaults() { return { data: {} }; } } ``` -------------------------------- ### register_smart_connections_codeblock(plugin) Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/INDEX.md Registers the smart connections codeblock functionality within the Obsidian plugin environment. ```APIDOC ## register_smart_connections_codeblock ### Description Registers the smart connections codeblock to be used within Obsidian markdown files. ### Parameters - **plugin** (Object) - Required - The instance of the SmartConnectionsPlugin. ``` -------------------------------- ### connections_list_component_key (getter) Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/2-connections-list-api.md Determines the component key for rendering, defaulting to 'connections_list_v4' if the configured key is not found. ```javascript get connections_list_component_key() { const stored_key = this.data.connections_list_component_key || this.settings?.connections_list_component_key ; if(this.env.config.components[stored_key]) return stored_key; return 'connections_list_v4'; } ``` -------------------------------- ### SettingsConfigItem Definition Source: https://github.com/brianpetro/obsidian-smart-connections/blob/main/_autodocs/9-types-and-interfaces.md Defines the structure for individual setting definitions within the plugin. ```javascript { name: string, // Display name description?: string, // Help text type: 'toggle' | 'text' | 'number' | 'dropdown' | 'html', group?: string, // Settings group scope_class?: string, // CSS class (e.g., 'pro-setting') // For dropdowns options_callback?: () => Array, option_1?: string, // Deprecated: 'value|label' option_2?: string, // For HTML value?: string, // HTML content // Default default?: any } ```