fix: Fix lint errors (#559)
* cleanup: postactions styling * misc: fix first round of errors * pkg: remove vitest * fix: fix lint errors stage 2 * fix: fix lint errors stage 3 * fix: fix lint errors, stage 3 * misc: update eslint rules to warn for writable derived
This commit is contained in:
1 parent
1824245f13
commit
76c581123a
225 files changed
+1553
-2352
No files matched your search
@@ -21,19 +21,22 @@
|
||||
MdSuperscript,
|
||||
MdText,
|
||||
} from './renderers/index'
|
||||
import { linkify, subSupscriptExtension } from './renderers/plugins'
|
||||
import containerExtension from './renderers/spoiler/spoiler'
|
||||
import { linkify, subSupscriptExtension } from './renderers/plugins.js'
|
||||
import containerExtension from './renderers/spoiler/spoiler.js'
|
||||
|
||||
export const options: any = {
|
||||
export const options = {
|
||||
mangle: false,
|
||||
headerIds: false,
|
||||
pedantic: false,
|
||||
inline: false,
|
||||
}
|
||||
|
||||
marked.setOptions(options)
|
||||
|
||||
marked.use(linkify, {
|
||||
extensions: [
|
||||
// @ts-expect-error hell with marked
|
||||
// eslint-disable-next-line
|
||||
containerExtension((params: any) => {
|
||||
if (params.type == 'spoiler') {
|
||||
return {
|
||||
@@ -45,6 +48,8 @@
|
||||
}
|
||||
return null
|
||||
}),
|
||||
// @ts-expect-error hell with marked
|
||||
// eslint-disable-next-line
|
||||
subSupscriptExtension((params: any) => {
|
||||
if (params.type == 'subscript') {
|
||||
return {
|
||||
@@ -74,7 +79,6 @@
|
||||
html: MdHtml,
|
||||
code: MdCode,
|
||||
list: MdList,
|
||||
// @ts-ignore
|
||||
spoiler: MdSpoiler,
|
||||
table: MdTable,
|
||||
tablebody: MdTableBody,
|
||||
@@ -96,7 +100,6 @@
|
||||
html: MdText,
|
||||
code: MdText,
|
||||
list: MdText,
|
||||
// @ts-ignore
|
||||
spoiler: MdText,
|
||||
table: MdText,
|
||||
tablebody: MdText,
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
<script lang="ts">
|
||||
import { run } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/auth.svelte.js'
|
||||
import MultiSelect from '$lib/components/input/Switch.svelte'
|
||||
import Markdown from '$lib/components/markdown/Markdown.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { uploadImage } from '$lib/util.svelte.js'
|
||||
import { ImageInput, toast } from 'mono-svelte'
|
||||
import { Button, Label, Modal, TextArea } from 'mono-svelte'
|
||||
import { createEventDispatcher, tick } from 'svelte'
|
||||
import { Button, Label, TextArea } from 'mono-svelte'
|
||||
import type { TextAreaProps } from 'mono-svelte/forms/TextArea.svelte'
|
||||
import { tick } from 'svelte'
|
||||
import {
|
||||
Bold,
|
||||
CodeBracket,
|
||||
DocumentPlus,
|
||||
ExclamationTriangle,
|
||||
H1,
|
||||
Icon,
|
||||
@@ -23,8 +18,7 @@
|
||||
Strikethrough,
|
||||
} from 'svelte-hero-icons'
|
||||
import ImageUploadModal from '../lemmy/modal/ImageUploadModal.svelte'
|
||||
import type { HTMLTextareaAttributes } from 'svelte/elements'
|
||||
import type { TextAreaProps } from 'mono-svelte/forms/TextArea.svelte'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
let textArea: HTMLTextAreaElement | undefined = $state()
|
||||
|
||||
@@ -60,7 +54,7 @@
|
||||
}
|
||||
|
||||
let uploadingImage = $state(false)
|
||||
let image = $state<any>(null)
|
||||
let image = $state<FileList | null | undefined>(null)
|
||||
|
||||
const shortcuts = {
|
||||
KeyB: () => wrapSelection('**', '**'),
|
||||
@@ -68,11 +62,6 @@
|
||||
KeyS: () => wrapSelection('~~', '~~'),
|
||||
KeyH: () => wrapSelection('\n# ', ''),
|
||||
KeyK: () => wrapSelection('[](', ')'),
|
||||
Enter: (e: any) => {
|
||||
onconfirm?.(value)
|
||||
const newEvent = new Event('submit', { cancelable: true })
|
||||
e?.target?.form?.dispatchEvent(newEvent)
|
||||
},
|
||||
}
|
||||
|
||||
async function adjustHeight() {
|
||||
@@ -93,10 +82,9 @@
|
||||
rows?: number
|
||||
beforePreview?: (input: string) => string
|
||||
previewing?: boolean
|
||||
class?: string
|
||||
class?: ClassValue
|
||||
customLabel?: import('svelte').Snippet
|
||||
children?: import('svelte').Snippet
|
||||
onconfirm?: (value: string) => void
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -107,12 +95,11 @@
|
||||
tools = true,
|
||||
disabled = false,
|
||||
rows = 2,
|
||||
beforePreview = (input) => input,
|
||||
beforePreview = input => input,
|
||||
previewing = $bindable(false),
|
||||
class: clazz = '',
|
||||
customLabel,
|
||||
children,
|
||||
onconfirm,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
|
||||
@@ -125,8 +112,8 @@
|
||||
<ImageUploadModal
|
||||
bind:open={uploadingImage}
|
||||
bind:image
|
||||
onupload={(e) => {
|
||||
e.forEach((i) => {
|
||||
onupload={e => {
|
||||
e.forEach(i => {
|
||||
wrapSelection(`\n\n`, '')
|
||||
})
|
||||
}}
|
||||
@@ -265,10 +252,10 @@ overflow-hidden transition-colors {clazz}"
|
||||
class="bg-inherit z-0 border-0 rounded-none ring-0! focus:ring-transparent! transition-none! resize-none"
|
||||
bind:value
|
||||
bind:element={textArea}
|
||||
onkeydown={(e) => {
|
||||
onkeydown={e => {
|
||||
if (disabled) return
|
||||
if (e.ctrlKey || e.metaKey) {
|
||||
// @ts-ignore
|
||||
// @ts-expect-error yes it can
|
||||
let shortcut = shortcuts[e.code]
|
||||
if (shortcut) {
|
||||
e.preventDefault()
|
||||
@@ -277,11 +264,11 @@ overflow-hidden transition-colors {clazz}"
|
||||
}
|
||||
}}
|
||||
oninput={adjustHeight}
|
||||
onpaste={(e) => {
|
||||
onpaste={e => {
|
||||
if (!e.clipboardData?.files) return
|
||||
const files = Array.from(e.clipboardData.files)
|
||||
if (files[0]?.type.startsWith('image/')) {
|
||||
image = e.clipboardData.files[0]
|
||||
image = e.clipboardData.files[0] as unknown as FileList | null
|
||||
uploadingImage = true
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
||||
import {
|
||||
iframeType,
|
||||
mediaType,
|
||||
optimizeImageURL,
|
||||
} from '$lib/components/lemmy/post/helpers'
|
||||
import PostIframe from '$lib/components/lemmy/post/media/PostIframe.svelte'
|
||||
import { getContext } from 'svelte'
|
||||
import { ArrowDown, ArrowDownTray, Icon } from 'svelte-hero-icons'
|
||||
import { showImage } from '$lib/components/ui/ExpandableImage.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { getContext } from 'svelte'
|
||||
import { ArrowDownTray, Icon } from 'svelte-hero-icons'
|
||||
|
||||
let loaded: boolean = $state(
|
||||
(getContext('options') as { autoloadImages: boolean })?.autoloadImages ??
|
||||
@@ -42,7 +42,7 @@
|
||||
{:else}
|
||||
<button
|
||||
class="inline"
|
||||
onclick={() => showImage(optimizeImageURL(href, -1), text)}
|
||||
onclick={() => showImage(optimizeImageURL(href, -1))}
|
||||
>
|
||||
<img
|
||||
src={optimizeImageURL(href, 1024)}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { photonify } from './plugins'
|
||||
import { photonify } from './plugins.js'
|
||||
|
||||
interface Props {
|
||||
href?: string
|
||||
title?: any
|
||||
title?: string
|
||||
children?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
export const parseURL = (href: string) => {
|
||||
try {
|
||||
return new URL(href)
|
||||
} catch (e) {
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
let { tokens, children } = $props()
|
||||
let { children } = $props()
|
||||
</script>
|
||||
|
||||
<li>
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { marked } from 'marked'
|
||||
import SvelteMarkdown from 'svelte-markdown'
|
||||
import { options, renderers } from '../Markdown.svelte'
|
||||
import { Disclosure } from 'mono-svelte'
|
||||
import { Icon } from 'svelte-hero-icons'
|
||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||
|
||||
interface Props {
|
||||
|
||||
+19
-17
@@ -4,10 +4,11 @@ import markedLinkifyIt from 'marked-linkify-it'
|
||||
export const spoilerPlugin = {
|
||||
name: 'spoiler',
|
||||
level: 'block',
|
||||
start(src: string) {
|
||||
start(src) {
|
||||
return src.match(/^:::/)?.index
|
||||
},
|
||||
tokenizer(src: string, tokens: any) {
|
||||
// eslint-disable-next-line
|
||||
tokenizer(src, tokens) {
|
||||
const rule = /^::: spoiler (.+)\n([\s\S]*?)\n:::/
|
||||
const match = rule.exec(src)
|
||||
if (match) {
|
||||
@@ -19,7 +20,7 @@ export const spoilerPlugin = {
|
||||
}
|
||||
}
|
||||
},
|
||||
renderer(token: any) {
|
||||
renderer(token) {
|
||||
return `
|
||||
<details>
|
||||
<summary>${marked.parseInline(token.title)}</summary>
|
||||
@@ -32,12 +33,12 @@ export const spoilerPlugin = {
|
||||
export const linkify = markedLinkifyIt(
|
||||
{
|
||||
'!': {
|
||||
validate: function (text: any, pos: any, self: any) {
|
||||
validate: function (text, pos, self) {
|
||||
var tail = text.slice(pos)
|
||||
|
||||
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)) {
|
||||
@@ -46,11 +47,11 @@ export const linkify = markedLinkifyIt(
|
||||
if (pos >= 2 && tail[pos - 2] === '!') {
|
||||
return false
|
||||
}
|
||||
return tail.match(self.re.community)![0].length
|
||||
return tail.match(self.re.community)[0].length
|
||||
}
|
||||
return 0
|
||||
},
|
||||
normalize: function (match: any) {
|
||||
normalize: function (match) {
|
||||
let prefix = match.url
|
||||
prefix = prefix.startsWith('c/') ? prefix.slice(2) : prefix.slice(1)
|
||||
|
||||
@@ -58,12 +59,12 @@ export const linkify = markedLinkifyIt(
|
||||
},
|
||||
},
|
||||
'@': {
|
||||
validate: function (text: any, pos: any, self: any) {
|
||||
validate: function (text, pos, self) {
|
||||
var tail = text.slice(pos)
|
||||
|
||||
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)) {
|
||||
@@ -72,11 +73,11 @@ export const linkify = markedLinkifyIt(
|
||||
if (pos >= 2 && tail[pos - 2] === '!') {
|
||||
return false
|
||||
}
|
||||
return tail.match(self.re.user)![0].length
|
||||
return tail.match(self.re.user)[0].length
|
||||
}
|
||||
return 0
|
||||
},
|
||||
normalize: function (match: any) {
|
||||
normalize: function (match) {
|
||||
let prefix = match.url
|
||||
prefix = prefix.startsWith('u/') ? prefix.slice(2) : prefix.slice(1)
|
||||
|
||||
@@ -94,13 +95,13 @@ const regexes = {
|
||||
comment: /^https:\/\/([a-zA-Z0-9.-]+)\/comment\/(\d+)$/i,
|
||||
user: /^https:\/\/([a-zA-Z0-9.-]+)(\/u\/)([a-zA-Z0-9.-_]+)$/i,
|
||||
community: /^https:\/\/([a-zA-Z0-9.-]+)(\/c\/)([a-zA-Z0-9.-_]+)$/i,
|
||||
implicitUser: /^mailto:([a-z0-9_\.-]+)@(([\da-z\.-]+)\.([a-z]{2,63}))/i,
|
||||
implicitUser: /^mailto:([a-z0-9_.-]+)@(([\da-z.-]+)\.([a-z]{2,63}))/i,
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert links to photon links
|
||||
*/
|
||||
export const photonify = (link: string) => {
|
||||
export const photonify = link => {
|
||||
if (regexes.community.test(link)) {
|
||||
const match = link.match(regexes.community)
|
||||
if (!match) return
|
||||
@@ -136,16 +137,17 @@ export const photonify = (link: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
export function subSupscriptExtension(tokensExtractor: any): any {
|
||||
export function subSupscriptExtension(tokensExtractor) {
|
||||
return {
|
||||
name: 'subscriptSuperscript',
|
||||
level: 'inline',
|
||||
start(src: string) {
|
||||
start(src) {
|
||||
return src.match(/[~^]/)?.index
|
||||
},
|
||||
tokenizer(src: string, tokens: any[]): any {
|
||||
// eslint-disable-next-line
|
||||
tokenizer(src, tokens) {
|
||||
const subscriptRule = /^~([^~\s](?:[^~]*[^~\s])?)~/
|
||||
const superscriptRule = /^\^([^\^\s](?:[^\^]*[^\^\s])?)\^/
|
||||
const superscriptRule = /^\^([^^\s](?:[^^]*[^^\s])?)\^/
|
||||
|
||||
let match
|
||||
|
||||
+6
-35
@@ -1,32 +1,3 @@
|
||||
import { Lexer } from 'marked'
|
||||
|
||||
export type ContainerOptions = Record<string, boolean | string>
|
||||
|
||||
export type TokenExtractionParameters = {
|
||||
/**
|
||||
* The type of container
|
||||
*/
|
||||
type: string
|
||||
/**
|
||||
* The content inside the container
|
||||
*/
|
||||
content: string
|
||||
/**
|
||||
* The raw full container block
|
||||
*/
|
||||
raw: string
|
||||
/**
|
||||
* The options of the container
|
||||
*/
|
||||
options: ContainerOptions
|
||||
/**
|
||||
* The lexer that can be used to render nested tokens if needed
|
||||
*/
|
||||
lexer: Lexer
|
||||
}
|
||||
|
||||
export type TokenExtractor = (params: any) => any
|
||||
|
||||
/**
|
||||
* Container extension is a marked extension that parses a block of text surrounded by :::
|
||||
*
|
||||
@@ -48,14 +19,14 @@ export type TokenExtractor = (params: any) => any
|
||||
* **content**: `Something inside the container`
|
||||
* **options**: { 'option': 'option-1', 'option-2': 'option-2', 'boolean-option': true }
|
||||
*/
|
||||
export default function (tokensExtractor: any): any {
|
||||
export default function (tokensExtractor) {
|
||||
return {
|
||||
name: 'container',
|
||||
level: 'block',
|
||||
start(src: any) {
|
||||
start(src) {
|
||||
return src.match(/^:::[^:\n]/)?.index
|
||||
},
|
||||
tokenizer(src: any): any {
|
||||
tokenizer(src) {
|
||||
const rule =
|
||||
/^:::[\s]?(?<type>[a-z0-9-]+)(?<options>.*)?\n(?<content>(?:.|\n)*)\n:::(?:\n|$)/i
|
||||
|
||||
@@ -83,7 +54,7 @@ export default function (tokensExtractor: any): any {
|
||||
}
|
||||
}
|
||||
|
||||
function findRawContainer(src: any): any {
|
||||
function findRawContainer(src) {
|
||||
if (!src.startsWith(':::')) return undefined
|
||||
const lines = src.split('\n')
|
||||
let open = 1
|
||||
@@ -107,8 +78,8 @@ function findRawContainer(src: any): any {
|
||||
return lines.slice(0, lineNumber + 1).join('\n')
|
||||
}
|
||||
|
||||
function parseOptions(options: string): ContainerOptions {
|
||||
const output: any = {}
|
||||
function parseOptions(options) {
|
||||
const output = {}
|
||||
let remaining = options
|
||||
|
||||
while (true) {
|
||||
Reference in new issue
Block a user