feat: add image pasting, close #234
This commit is contained in:
1 parent
a5287b03e8
commit
b80d6bd930
6 files changed
+90
-22
No files matched your search
+1
-1
@@ -47,7 +47,7 @@
|
|||||||
"@dicebear/core": "^6.0.4",
|
"@dicebear/core": "^6.0.4",
|
||||||
"@dicebear/initials": "^6.0.4",
|
"@dicebear/initials": "^6.0.4",
|
||||||
"markdown-it": "^13.0.1",
|
"markdown-it": "^13.0.1",
|
||||||
"mono-svelte": "^1.4.5"
|
"mono-svelte": "latest"
|
||||||
},
|
},
|
||||||
"overrides": {
|
"overrides": {
|
||||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import {
|
import {
|
||||||
CodeBracket,
|
CodeBracket,
|
||||||
|
DocumentPlus,
|
||||||
ExclamationTriangle,
|
ExclamationTriangle,
|
||||||
Icon,
|
Icon,
|
||||||
Link,
|
Link,
|
||||||
@@ -60,16 +61,17 @@
|
|||||||
|
|
||||||
let uploadingImage = false
|
let uploadingImage = false
|
||||||
let loading = false
|
let loading = false
|
||||||
let image: FileList | null = null
|
let image: any
|
||||||
|
$: previewURL = image instanceof FileList ? URL.createObjectURL(image[0]) : image ? URL.createObjectURL(image) : ''
|
||||||
|
|
||||||
async function upload() {
|
async function upload() {
|
||||||
if (!$profile?.jwt || image == null) return
|
if (!$profile?.jwt || !image) return
|
||||||
|
|
||||||
loading = true
|
loading = true
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const uploaded = await uploadImage(
|
const uploaded = await uploadImage(
|
||||||
image[0],
|
image instanceof FileList ? image[0] : image,
|
||||||
$profile.instance,
|
$profile.instance,
|
||||||
$profile.jwt
|
$profile.jwt
|
||||||
)
|
)
|
||||||
@@ -105,7 +107,35 @@
|
|||||||
<Modal bind:open={uploadingImage}>
|
<Modal bind:open={uploadingImage}>
|
||||||
<span slot="title">Upload image</span>
|
<span slot="title">Upload image</span>
|
||||||
<form class="flex flex-col gap-4" on:submit|preventDefault={upload}>
|
<form class="flex flex-col gap-4" on:submit|preventDefault={upload}>
|
||||||
<ImageInput bind:files={image} />
|
<div class="flex flex-col gap-1">
|
||||||
|
<label
|
||||||
|
class="flex flex-col items-center px-8 py-4 mx-auto w-full rounded-lg
|
||||||
|
border border-slate-300 dark:border-zinc-700 bg-white dark:bg-black
|
||||||
|
cursor-pointer min-h-36 transition-colors
|
||||||
|
"
|
||||||
|
on:drop|preventDefault={(event) => (image = event.dataTransfer?.files?.[0])}
|
||||||
|
on:dragover|preventDefault={(event) => {
|
||||||
|
if (event.dataTransfer) {
|
||||||
|
event.dataTransfer.dropEffect = 'copy'
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{#if image}
|
||||||
|
<!-- svelte-ignore a11y-missing-attribute -->
|
||||||
|
<img
|
||||||
|
src={previewURL}
|
||||||
|
on:load={() => {
|
||||||
|
if (previewURL) URL.revokeObjectURL(previewURL)
|
||||||
|
}}
|
||||||
|
class="w-full max-w-sm h-full rounded-lg"
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
<Icon src={DocumentPlus} class="opacity-50" size="36" />
|
||||||
|
<p class="text-sm opacity-50">Attach a file</p>
|
||||||
|
{/if}
|
||||||
|
<input type="file" bind:files={image} accept="image/*" class="hidden" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
<Button {loading} disabled={loading} submit color="primary" size="lg">
|
<Button {loading} disabled={loading} submit color="primary" size="lg">
|
||||||
Upload
|
Upload
|
||||||
</Button>
|
</Button>
|
||||||
@@ -251,6 +281,14 @@ overflow-hidden focus-within:border-black focus-within:dark:border-white transit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
on:paste={(e) => {
|
||||||
|
if (!e.clipboardData?.files) return
|
||||||
|
const files = Array.from(e.clipboardData.files)
|
||||||
|
if (files[0]?.type.startsWith('image/')) {
|
||||||
|
image = e.clipboardData.files[0]
|
||||||
|
uploadingImage = true
|
||||||
|
}
|
||||||
|
}}
|
||||||
{rows}
|
{rows}
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
/>
|
/>
|
||||||
|
|||||||
+3
-14
@@ -116,7 +116,6 @@ export function colorsToVars(colors: Colors): string {
|
|||||||
let vars: string[] = []
|
let vars: string[] = []
|
||||||
for (let category in colors) {
|
for (let category in colors) {
|
||||||
for (let shade in colors[category as keyof Colors]) {
|
for (let shade in colors[category as keyof Colors]) {
|
||||||
console.log(shade)
|
|
||||||
if (category)
|
if (category)
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
vars.push(`--c-${category.slice(0, 1)}-${shade}:${colors[category][shade]}`)
|
vars.push(`--c-${category.slice(0, 1)}-${shade}:${colors[category][shade]}`)
|
||||||
@@ -128,14 +127,14 @@ export function colorsToVars(colors: Colors): string {
|
|||||||
export const colorToVar = (category: keyof Colors, shade: keyof keyof Colors): string =>
|
export const colorToVar = (category: keyof Colors, shade: keyof keyof Colors): string =>
|
||||||
`--c-${category.slice(0,2)}-${shade.toString()}`
|
`--c-${category.slice(0,2)}-${shade.toString()}`
|
||||||
|
|
||||||
colors.subscribe((v) => {
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
function loadColors() {
|
function loadColors() {
|
||||||
const loaded = localStorage.getItem('colors')
|
const loaded = localStorage.getItem('colors')
|
||||||
if (!loaded) return
|
if (!loaded) return
|
||||||
colors.set(JSON.parse(loaded))
|
colors.set(JSON.parse(loaded))
|
||||||
|
colors.subscribe((v) => {
|
||||||
|
localStorage.setItem('colors', JSON.stringify(v))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (browser) {
|
if (browser) {
|
||||||
@@ -143,16 +142,6 @@ if (browser) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const configuredLegacyTheme = env.PUBLIC_LEGACYTHEME ?? 'system'
|
const configuredLegacyTheme = env.PUBLIC_LEGACYTHEME ?? 'system'
|
||||||
export const legacyTheme = writable<'system' | 'light' | 'dark'>(
|
export const legacyTheme = writable<'system' | 'light' | 'dark'>(
|
||||||
configuredLegacyTheme as 'system' | 'light' | 'dark'
|
configuredLegacyTheme as 'system' | 'light' | 'dark'
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
import { pwaInfo } from 'virtual:pwa-info'
|
import { pwaInfo } from 'virtual:pwa-info'
|
||||||
import { inDarkLegacyTheme, legacyTheme } from '$lib/ui/colors.js'
|
import { inDarkLegacyTheme, legacyTheme } from '$lib/ui/colors.js'
|
||||||
import { userSettings } from '$lib/settings.js'
|
import { userSettings } from '$lib/settings.js'
|
||||||
import { Button, Spinner, ToastContainer } from 'mono-svelte'
|
import { Button, ModalContainer, Spinner, ToastContainer } from 'mono-svelte'
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import { browser } from '$app/environment'
|
import { browser } from '$app/environment'
|
||||||
import { Forward, Icon } from 'svelte-hero-icons'
|
import { Forward, Icon } from 'svelte-hero-icons'
|
||||||
@@ -95,6 +95,7 @@
|
|||||||
<Moderation />
|
<Moderation />
|
||||||
<ToastContainer />
|
<ToastContainer />
|
||||||
<ExpandableImage />
|
<ExpandableImage />
|
||||||
|
<ModalContainer />
|
||||||
|
|
||||||
<Navbar
|
<Navbar
|
||||||
slot="navbar"
|
slot="navbar"
|
||||||
|
|||||||
@@ -1,7 +1,21 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Button, Material, Modal, TextArea, toast } from 'mono-svelte'
|
import {
|
||||||
|
Button,
|
||||||
|
Material,
|
||||||
|
Modal,
|
||||||
|
TextArea,
|
||||||
|
action,
|
||||||
|
modal,
|
||||||
|
toast,
|
||||||
|
} from 'mono-svelte'
|
||||||
import { defaultColors, type Colors, colors } from '$lib/ui/colors'
|
import { defaultColors, type Colors, colors } from '$lib/ui/colors'
|
||||||
import { ArrowDownTray, ArrowUpTray, Bookmark, Icon } from 'svelte-hero-icons'
|
import {
|
||||||
|
ArrowDownTray,
|
||||||
|
ArrowPath,
|
||||||
|
ArrowUpTray,
|
||||||
|
Bookmark,
|
||||||
|
Icon,
|
||||||
|
} from 'svelte-hero-icons'
|
||||||
|
|
||||||
const c = defaultColors
|
const c = defaultColors
|
||||||
|
|
||||||
@@ -57,6 +71,32 @@
|
|||||||
<Icon src={ArrowDownTray} size="16" mini />
|
<Icon src={ArrowDownTray} size="16" mini />
|
||||||
Export
|
Export
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
on:click={() => {
|
||||||
|
modal({
|
||||||
|
actions: [
|
||||||
|
action({
|
||||||
|
content: 'Close',
|
||||||
|
close: true,
|
||||||
|
}),
|
||||||
|
action({
|
||||||
|
action: () => {
|
||||||
|
$colors = { other: {}, primary: {}, zinc: {}, slate: {} }
|
||||||
|
},
|
||||||
|
content: 'Reset',
|
||||||
|
close: true,
|
||||||
|
type: 'danger',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
title: 'Reset Theme',
|
||||||
|
body: 'This will reset all your colors to the default. We recommend exporting your theme first.',
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
size="lg"
|
||||||
|
>
|
||||||
|
<Icon src={ArrowPath} size="16" mini />
|
||||||
|
Reset
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">
|
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">
|
||||||
{#each svelteIntellisenseSucks() as category}
|
{#each svelteIntellisenseSucks() as category}
|
||||||
|
|||||||
Reference in new issue
Block a user