migrate: convert most components to svelte 5
This commit is contained in:
1 parent
d670f39f0a
commit
10ef4123da
225 files changed
+5441
-3341
No files matched your search
@@ -1,4 +1,4 @@
|
||||
<script lang="ts" context="module">
|
||||
<script lang="ts" module>
|
||||
import { marked } from 'marked'
|
||||
import {
|
||||
MdCode,
|
||||
@@ -88,20 +88,32 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import SvelteMarkdown from 'svelte-markdown'
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
export let source: string = ''
|
||||
export let inline: boolean = false
|
||||
import SvelteMarkdown from 'svelte-markdown'
|
||||
|
||||
options.inline = inline
|
||||
|
||||
export let noStyle: boolean = false
|
||||
interface Props {
|
||||
source?: string
|
||||
inline?: boolean
|
||||
noStyle?: boolean
|
||||
style?: string
|
||||
class?: string
|
||||
}
|
||||
|
||||
$: tokens = marked.lexer(source)
|
||||
let {
|
||||
source = '',
|
||||
inline = false,
|
||||
noStyle = false,
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
}: Props = $props()
|
||||
|
||||
export let style: string = ''
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let tokens
|
||||
run(() => {
|
||||
tokens = marked.lexer(source)
|
||||
})
|
||||
</script>
|
||||
|
||||
<div
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/auth.js'
|
||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
@@ -22,30 +24,21 @@
|
||||
} from 'svelte-hero-icons'
|
||||
import ImageUploadModal from '../lemmy/modal/ImageUploadModal.svelte'
|
||||
|
||||
export let images: boolean = true
|
||||
export let value: string = ''
|
||||
export let label: string | undefined = undefined
|
||||
export let previewButton: boolean = true
|
||||
export let tools: boolean = true
|
||||
export let disabled: boolean = false
|
||||
export let rows: number = 2
|
||||
|
||||
export let beforePreview: (input: string) => string = (input) => input
|
||||
|
||||
const dispatcher = createEventDispatcher<{ confirm: string }>()
|
||||
|
||||
let textArea: HTMLTextAreaElement
|
||||
let textArea: HTMLTextAreaElement | undefined = $state()
|
||||
|
||||
function replaceTextAtIndices(
|
||||
str: string,
|
||||
startIndex: number,
|
||||
endIndex: number,
|
||||
replacement: string
|
||||
replacement: string,
|
||||
) {
|
||||
return str.substring(0, startIndex) + replacement + str.substring(endIndex)
|
||||
}
|
||||
|
||||
function wrapSelection(start: string, end: string) {
|
||||
if (!textArea) return
|
||||
const startPos = textArea.selectionStart
|
||||
const endPos = textArea.selectionEnd
|
||||
|
||||
@@ -56,7 +49,7 @@
|
||||
textArea.value,
|
||||
startPos,
|
||||
endPos,
|
||||
newText
|
||||
newText,
|
||||
)
|
||||
|
||||
textArea.focus()
|
||||
@@ -66,10 +59,8 @@
|
||||
value = textArea.value
|
||||
}
|
||||
|
||||
let uploadingImage = false
|
||||
let image: any
|
||||
|
||||
export let previewing = false
|
||||
let uploadingImage = $state(false)
|
||||
let image: any = $state()
|
||||
|
||||
const shortcuts = {
|
||||
KeyB: () => wrapSelection('**', '**'),
|
||||
@@ -92,10 +83,41 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: if (!previewing && value) adjustHeight()
|
||||
interface Props {
|
||||
images?: boolean
|
||||
value?: string
|
||||
label?: string | undefined
|
||||
previewButton?: boolean
|
||||
tools?: boolean
|
||||
disabled?: boolean
|
||||
rows?: number
|
||||
beforePreview?: (input: string) => string
|
||||
previewing?: boolean
|
||||
class?: string
|
||||
customLabel?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let clazz: string = ''
|
||||
export { clazz as class }
|
||||
let {
|
||||
images = true,
|
||||
value = $bindable(''),
|
||||
label = undefined,
|
||||
previewButton = true,
|
||||
tools = true,
|
||||
disabled = false,
|
||||
rows = 2,
|
||||
beforePreview = (input) => input,
|
||||
previewing = $bindable(false),
|
||||
class: clazz = '',
|
||||
customLabel,
|
||||
children,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
run(() => {
|
||||
if (!previewing && value) adjustHeight()
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if uploadingImage && images}
|
||||
@@ -111,12 +133,12 @@
|
||||
{/if}
|
||||
|
||||
<div>
|
||||
{#if label || $$slots.label}
|
||||
{#if label || customLabel}
|
||||
<Label>
|
||||
{#if label}
|
||||
{label}
|
||||
{:else if $$slots.label}
|
||||
<slot name="label" />
|
||||
{:else if customLabel}
|
||||
{@render customLabel?.()}
|
||||
{/if}
|
||||
</Label>
|
||||
{/if}
|
||||
@@ -264,7 +286,7 @@ overflow-hidden transition-colors {clazz}"
|
||||
}
|
||||
}}
|
||||
{rows}
|
||||
{...$$restProps}
|
||||
{...rest}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
@@ -279,7 +301,7 @@ overflow-hidden transition-colors {clazz}"
|
||||
optionNames={[$t('form.edit'), $t('form.preview')]}
|
||||
/>
|
||||
{/if}
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
import { Button, Material, toast } from 'mono-svelte'
|
||||
import { Icon, ClipboardDocument } from 'svelte-hero-icons'
|
||||
|
||||
export let raw: string
|
||||
interface Props {
|
||||
raw: string
|
||||
}
|
||||
|
||||
let { raw }: Props = $props()
|
||||
|
||||
function parseCodeblock(src: string): {
|
||||
code: string
|
||||
@@ -21,7 +25,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: codeblock = parseCodeblock(raw)
|
||||
let codeblock = $derived(parseCodeblock(raw))
|
||||
</script>
|
||||
|
||||
<Material
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
<script lang="ts">
|
||||
export let depth: number = 0
|
||||
export let raw: string | undefined = undefined
|
||||
interface Props {
|
||||
depth?: number
|
||||
raw?: string | undefined
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { depth = 0, raw = undefined, children }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if depth === 1}
|
||||
<h1 class="font-bold text-4xl"><slot></slot></h1>
|
||||
<h1 class="font-bold text-4xl">{@render children?.()}</h1>
|
||||
{:else if depth === 2}
|
||||
<h2 class="font-bold text-3xl"><slot></slot></h2>
|
||||
<h2 class="font-bold text-3xl">{@render children?.()}</h2>
|
||||
{:else if depth === 3}
|
||||
<h3 class="font-bold text-2xl"><slot></slot></h3>
|
||||
<h3 class="font-bold text-2xl">{@render children?.()}</h3>
|
||||
{:else if depth === 4}
|
||||
<h4 class="font-semibold text-xl"><slot></slot></h4>
|
||||
<h4 class="font-semibold text-xl">{@render children?.()}</h4>
|
||||
{:else if depth === 5}
|
||||
<h5 class="font-semibold text-lg"><slot></slot></h5>
|
||||
<h5 class="font-semibold text-lg">{@render children?.()}</h5>
|
||||
{:else if depth === 6}
|
||||
<h6 class="font-semibold text-base"><slot></slot></h6>
|
||||
<h6 class="font-semibold text-base">{@render children?.()}</h6>
|
||||
{:else}
|
||||
{raw}
|
||||
{/if}
|
||||
@@ -1,5 +1,9 @@
|
||||
<script lang="ts">
|
||||
export let text: string
|
||||
interface Props {
|
||||
text: string
|
||||
}
|
||||
|
||||
let { text }: Props = $props()
|
||||
</script>
|
||||
|
||||
<p>
|
||||
|
||||
@@ -7,11 +7,15 @@
|
||||
} from '$lib/components/lemmy/post/helpers'
|
||||
import PostIframe from '$lib/components/lemmy/post/media/PostIframe.svelte'
|
||||
|
||||
export let href: string
|
||||
export let title: string | undefined = undefined
|
||||
export let text: string = ''
|
||||
interface Props {
|
||||
href: string
|
||||
title?: string | undefined
|
||||
text?: string
|
||||
}
|
||||
|
||||
$: type = mediaType(href, 'cozy')
|
||||
let { href, title = undefined, text = '' }: Props = $props()
|
||||
|
||||
let type = $derived(mediaType(href, 'cozy'))
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -29,7 +33,7 @@
|
||||
{:else}
|
||||
<button
|
||||
class="inline"
|
||||
on:click={() => showImage(optimizeImageURL(href, -1), text)}
|
||||
onclick={() => showImage(optimizeImageURL(href, -1), text)}
|
||||
>
|
||||
<img
|
||||
src={optimizeImageURL(href, 1024)}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { photonify } from './plugins'
|
||||
|
||||
export let href = ''
|
||||
export let title = undefined
|
||||
interface Props {
|
||||
href?: string
|
||||
title?: any
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { href = '', title = undefined, children }: Props = $props()
|
||||
|
||||
export const parseURL = (href: string) => {
|
||||
try {
|
||||
@@ -12,7 +17,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: photonified = photonify(href)
|
||||
let photonified = $derived(photonify(href))
|
||||
</script>
|
||||
|
||||
<a
|
||||
@@ -20,5 +25,5 @@
|
||||
{title}
|
||||
class="hover:underline text-sky-600 dark:text-sky-500"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</a>
|
||||
@@ -1,6 +1,11 @@
|
||||
<script lang="ts">
|
||||
export let ordered: boolean
|
||||
export let start: number
|
||||
interface Props {
|
||||
ordered: boolean
|
||||
start: number
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { ordered, start, children }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if ordered}
|
||||
@@ -8,12 +13,12 @@
|
||||
{start}
|
||||
class="pl-5 list-decimal *:marker:font-medium *:marker:text-primary-900 *:marker:dark:text-primary-100"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</ol>
|
||||
{:else}
|
||||
<ul
|
||||
class="list-disc pl-4 *:marker:text-primary-900 *:marker:dark:text-primary-100"
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</ul>
|
||||
{/if}
|
||||
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
export let tokens
|
||||
let { tokens, children } = $props()
|
||||
</script>
|
||||
|
||||
<li>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</li>
|
||||
@@ -1,9 +1,16 @@
|
||||
<script>
|
||||
import { options } from '../Markdown.svelte'
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<p class="leading-[1.5] {options.inline ? '' : 'max-w'}">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</p>
|
||||
|
||||
<style>
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<blockquote class="border-l-2 dark:border-zinc-700 border-slate-300 p-1 px-3">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</blockquote>
|
||||
@@ -6,7 +6,11 @@
|
||||
import { Icon } from 'svelte-hero-icons'
|
||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||
|
||||
export let raw: string
|
||||
interface Props {
|
||||
raw: string
|
||||
}
|
||||
|
||||
let { raw }: Props = $props()
|
||||
|
||||
function extractTitle(text: string) {
|
||||
const spoilerRegex = /^::: ?spoiler (.+)\n([\s\S]+?)\n:::/gm
|
||||
@@ -25,12 +29,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
$: data = extractTitle(raw)
|
||||
let data = $derived(extractTitle(raw))
|
||||
</script>
|
||||
|
||||
<Expandable class="border-y border-slate-200 dark:border-zinc-800 py-2">
|
||||
<div slot="title" class="text-left">
|
||||
<SvelteMarkdown source={data.title} {renderers} {options} isInline />
|
||||
</div>
|
||||
{#snippet title()}
|
||||
<div class="text-left">
|
||||
<SvelteMarkdown source={data.title} {renderers} {options} isInline />
|
||||
</div>
|
||||
{/snippet}
|
||||
<SvelteMarkdown source={data.content} {renderers} {options} />
|
||||
</Expandable>
|
||||
@@ -1,5 +1,9 @@
|
||||
<script lang="ts">
|
||||
export let text: string
|
||||
interface Props {
|
||||
text: string
|
||||
}
|
||||
|
||||
let { text }: Props = $props()
|
||||
</script>
|
||||
|
||||
<sub>{text}</sub>
|
||||
@@ -1,5 +1,9 @@
|
||||
<script lang="ts">
|
||||
export let text: string
|
||||
interface Props {
|
||||
text: string
|
||||
}
|
||||
|
||||
let { text }: Props = $props()
|
||||
</script>
|
||||
|
||||
<sup>{text}</sup>
|
||||
@@ -1 +1,11 @@
|
||||
<slot />
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
{@render children?.()}
|
||||
@@ -37,7 +37,7 @@ export const linkify = markedLinkifyIt(
|
||||
|
||||
if (!self.re.community) {
|
||||
self.re.community = new RegExp(
|
||||
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,63})/i
|
||||
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,63})/i,
|
||||
)
|
||||
}
|
||||
if (self.re.community.test(tail)) {
|
||||
@@ -63,7 +63,7 @@ export const linkify = markedLinkifyIt(
|
||||
|
||||
if (!self.re.user) {
|
||||
self.re.user = new RegExp(
|
||||
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,63})/i
|
||||
/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z]{2,63})/i,
|
||||
)
|
||||
}
|
||||
if (self.re.user.test(tail)) {
|
||||
@@ -86,7 +86,7 @@ export const linkify = markedLinkifyIt(
|
||||
},
|
||||
{
|
||||
fuzzyEmail: false,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
const regexes = {
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<table class="overflow-auto w-full table-fixed rounded-xl">
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</table>
|
||||
@@ -1 +1,11 @@
|
||||
<tbody><slot /></tbody>
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<tbody>{@render children?.()}</tbody>
|
||||
@@ -1,13 +1,11 @@
|
||||
<script lang="ts">
|
||||
export let header: boolean
|
||||
export let align:
|
||||
| 'left'
|
||||
| 'center'
|
||||
| 'right'
|
||||
| 'justify'
|
||||
| 'char'
|
||||
| null
|
||||
| undefined = undefined
|
||||
interface Props {
|
||||
header: boolean
|
||||
align?: 'left' | 'center' | 'right' | 'justify' | 'char' | null | undefined
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let { header, align = undefined, children }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if header}
|
||||
@@ -15,13 +13,13 @@
|
||||
class="bg-slate-50 dark:bg-zinc-900 border border-slate-200 dark:border-zinc-800 py-2 px-3"
|
||||
{align}
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</th>
|
||||
{:else}
|
||||
<td
|
||||
class="bg-slate-25 dark:bg-zinc-950 border border-slate-200 dark:border-zinc-800 py-2 px-3"
|
||||
{align}
|
||||
>
|
||||
<slot />
|
||||
{@render children?.()}
|
||||
</td>
|
||||
{/if}
|
||||
@@ -1 +1,11 @@
|
||||
<thead><slot /></thead>
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<thead>{@render children?.()}</thead>
|
||||
@@ -1 +1,11 @@
|
||||
<tr><slot /></tr>
|
||||
<script>
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
*/
|
||||
|
||||
/** @type {Props} */
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<tr>{@render children?.()}</tr>
|
||||
Reference in new issue
Block a user