generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #342 from danielo515/feat/file-input
Feat/file-input
- Loading branch information
Showing
16 changed files
with
380 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<%* | ||
const modalForm = app.plugins.plugins.modalforms.api; | ||
const result = await modalForm.openForm('file_input'); | ||
tR += result.asFrontmatterString(); | ||
console.log(result.file) | ||
-%> | ||
|
||
Here is the file manually rendered | ||
![[<% result.file.value.name %>]] | ||
|
||
And here is the file leveraging the shorthand to get a markdown link | ||
<% result.file.link %> | ||
|
||
Some TFile proxy properties: | ||
|
||
- path: <% result.file.value.path %> | ||
- name: <% result.file.value.name %> | ||
- basename: <% result.file.value.basename %> | ||
- extension: <% result.file.value.extension %> | ||
|
||
Some TFile properties: | ||
|
||
- ctime: <% result.file.value.TFile.stat.ctime %> | ||
- mtime: <% result.file.value.TFile.stat.mtime %> | ||
- size: <% result.file.value.TFile.stat.size %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<script lang="ts"> | ||
import { E } from "@std"; | ||
import { FileProxy } from "src/core/files/FileProxy"; | ||
import { FileInputModel } from "./FileInputModel"; | ||
export let id: string; | ||
export let model: FileInputModel; | ||
export let value: FileProxy | null = null; | ||
let input: HTMLInputElement; | ||
function handleFileChange(event: Event) { | ||
const files = (event.target as HTMLInputElement).files; | ||
if (files?.[0]) { | ||
model.handleFileChange(files[0]); | ||
} | ||
} | ||
$: ({ error, result } = model); | ||
$: if (E.isRight($result)) { | ||
value = $result.right ?? null; | ||
} | ||
</script> | ||
|
||
<div class="file-input"> | ||
{#if value} | ||
<div class="file-preview"> | ||
<span>{value.path}</span> | ||
</div> | ||
{:else} | ||
<input | ||
bind:this={input} | ||
{id} | ||
type="file" | ||
accept={model.accepted} | ||
on:change={handleFileChange} | ||
/> | ||
{/if} | ||
{#if $error} | ||
<div class="error">{$error}</div> | ||
{/if} | ||
</div> | ||
|
||
<style> | ||
.file-input { | ||
width: 100%; | ||
} | ||
.file-preview { | ||
display: flex; | ||
align-items: center; | ||
gap: 0.5rem; | ||
padding: 0.5rem; | ||
background-color: var(--background-modifier-form-field); | ||
border-radius: var(--radius-s); | ||
} | ||
.clear-button { | ||
padding: 0 0.5rem; | ||
background: none; | ||
border: none; | ||
cursor: pointer; | ||
font-size: 1.2rem; | ||
color: var(--text-muted); | ||
} | ||
.clear-button:hover { | ||
color: var(--text-normal); | ||
} | ||
input[type="file"] { | ||
width: 100%; | ||
padding: 0.5rem; | ||
background-color: var(--background-modifier-form-field); | ||
border-radius: var(--radius-s); | ||
} | ||
.error { | ||
color: var(--text-error); | ||
} | ||
</style> |
Oops, something went wrong.