Svelte setup ok

This commit is contained in:
Simon Cambier
2022-04-14 22:50:56 +02:00
parent 5602b1d8c8
commit e1d24fc562
7 changed files with 223 additions and 49 deletions

11
src/Component.svelte Normal file
View File

@@ -0,0 +1,11 @@
<script lang="ts">
export let variable: number;
</script>
<div class="number"><span>My number is {variable}!</span></div>
<style>
.number {
color: red;
}
</style>

View File

@@ -1,11 +1,7 @@
import { Notice, Plugin, TAbstractFile, TFile } from 'obsidian'
import MiniSearch from 'minisearch'
import {
clearContent,
extractHeadingsFromCache,
wait,
} from './utils'
import { IndexedNote } from './globals'
import { clearContent, extractHeadingsFromCache, wait } from './utils'
import type { IndexedNote } from './globals'
import { OmnisearchModal } from './modal'
export default class OmnisearchPlugin extends Plugin {
@@ -108,9 +104,15 @@ export default class OmnisearchPlugin extends Plugin {
basename: file.basename,
content: tmp.innerText,
path: file.path,
headings1: fileCache ? extractHeadingsFromCache(fileCache, 1).join(' ') : '',
headings2: fileCache ? extractHeadingsFromCache(fileCache, 2).join(' ') : '',
headings3: fileCache ? extractHeadingsFromCache(fileCache, 3).join(' ') : '',
headings1: fileCache
? extractHeadingsFromCache(fileCache, 1).join(' ')
: '',
headings2: fileCache
? extractHeadingsFromCache(fileCache, 2).join(' ')
: '',
headings3: fileCache
? extractHeadingsFromCache(fileCache, 3).join(' ')
: '',
}
this.minisearch.add(note)
this.indexedNotes[file.path] = note

View File

@@ -1,7 +1,8 @@
import { MarkdownView, SuggestModal, TFile } from 'obsidian'
import { ResultNote } from './globals'
import OmnisearchPlugin from './main'
import type { ResultNote } from './globals'
import type OmnisearchPlugin from './main'
import { escapeRegex, getAllIndexes, highlighter } from './utils'
import Component from './Component.svelte'
export class OmnisearchModal extends SuggestModal<ResultNote> {
private plugin: OmnisearchPlugin
@@ -64,7 +65,8 @@ export class OmnisearchModal extends SuggestModal<ResultNote> {
const record = events.find(event =>
(event.target as HTMLDivElement).classList.contains('is-selected'),
)
const id = (record?.target as HTMLElement)?.getAttribute('data-note-id') ?? null
const id =
(record?.target as HTMLElement)?.getAttribute('data-note-id') ?? null
if (id) {
this.selectedNoteId = id
}
@@ -160,6 +162,10 @@ export class OmnisearchModal extends SuggestModal<ResultNote> {
}
renderSuggestion(value: ResultNote, el: HTMLElement): void {
const component = new Component({
target: el,
props: { variable: 1 },
})
el.setAttribute('data-note-id', value.path)
el.addClass('omnisearch-result')