diff --git a/src/views/TemplateBuilderModal.ts b/src/views/TemplateBuilderModal.ts index dbbaffbe..2e1df1c1 100644 --- a/src/views/TemplateBuilderModal.ts +++ b/src/views/TemplateBuilderModal.ts @@ -1,6 +1,7 @@ import { App, Modal } from "obsidian"; import { TemplateBuilderModel } from "./components/TemplateBuilder"; import TemplateBuilder from "./components/TemplateBuilder.svelte"; +import { copyToClipboard } from "./copyToClipboard"; /** * This class is just the minimum glue code to bind our core logic * with the svelte UI and obsidian API modal. @@ -23,7 +24,7 @@ export class TemplateBuilderModal extends Modal { const { contentEl } = this; this._component = new TemplateBuilder({ target: contentEl, - props: { model: this.deps }, + props: { model: this.deps, copyToClipboard }, }); } } diff --git a/src/views/TemplateBuilderView.ts b/src/views/TemplateBuilderView.ts index ad9ea33b..9c76a41b 100644 --- a/src/views/TemplateBuilderView.ts +++ b/src/views/TemplateBuilderView.ts @@ -1,19 +1,9 @@ -import { ItemView, Notice, ViewStateResult, WorkspaceLeaf } from "obsidian"; +import { ItemView, ViewStateResult, WorkspaceLeaf } from "obsidian"; import { FormDefinition } from "src/core/formDefinition"; import ModalFormPlugin from "src/main"; import { makeModel } from "./components/TemplateBuilder"; import TemplateBuilder from "./components/TemplateBuilder.svelte"; - -function copyToClipboard(text: string) { - navigator.clipboard.writeText(text).then( - () => { - new Notice("Template has been copied to the clipboard"); - }, - (err) => { - console.error("Could not copy text: ", err); - }, - ); -} +import { copyToClipboard } from "./copyToClipboard"; export const TEMPLATE_BUILDER_VIEW = "modal-form-template-builder-view"; /** diff --git a/src/views/copyToClipboard.ts b/src/views/copyToClipboard.ts new file mode 100644 index 00000000..053405c1 --- /dev/null +++ b/src/views/copyToClipboard.ts @@ -0,0 +1,12 @@ +import { Notice } from "obsidian"; + +export function copyToClipboard(text: string) { + navigator.clipboard.writeText(text).then( + () => { + new Notice("Template has been copied to the clipboard"); + }, + (err) => { + console.error("Could not copy text: ", err); + }, + ); +}