mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-02 15:50:27 +00:00
Add New Detail Type :: Image
This commit is contained in:
parent
2cbcc8bb1d
commit
44df0c3d09
4 changed files with 30 additions and 2 deletions
|
@ -21,6 +21,13 @@
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
<template v-else-if="detail.type === 'image'">
|
||||||
|
<div class="tooltip tooltip-primary tooltip-right" :data-tip="detail.href">
|
||||||
|
<a class="btn btn-primary btn-xs" :href="detail.href" target="_blank">
|
||||||
|
<img :src="detail.href" class="w-6 h-6">
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
<template v-else-if="detail.type === 'markdown'">
|
<template v-else-if="detail.type === 'markdown'">
|
||||||
<ClientOnly>
|
<ClientOnly>
|
||||||
<Markdown :source="detail.text" />
|
<Markdown :source="detail.text" />
|
||||||
|
|
|
@ -33,7 +33,13 @@ export type Detail = BaseDetail & {
|
||||||
copyable?: boolean;
|
copyable?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type AnyDetail = DateDetail | CurrencyDetail | LinkDetail | MarkdownDetail | Detail;
|
type ImageDetail = BaseDetail & {
|
||||||
|
type: "image";
|
||||||
|
text: string;
|
||||||
|
href: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AnyDetail = DateDetail | CurrencyDetail | LinkDetail | MarkdownDetail | Detail | ImageDetail;
|
||||||
|
|
||||||
export type Details = Array<Detail | AnyDetail>;
|
export type Details = Array<Detail | AnyDetail>;
|
||||||
|
|
||||||
|
@ -46,6 +52,8 @@ export function filterZeroValues(details: Details): Details {
|
||||||
return !!detail.text;
|
return !!detail.text;
|
||||||
case "link":
|
case "link":
|
||||||
return !!detail.text && !!detail.href;
|
return !!detail.text && !!detail.href;
|
||||||
|
case "image":
|
||||||
|
return !!detail.text && !!detail.href;
|
||||||
case undefined:
|
case undefined:
|
||||||
case "text":
|
case "text":
|
||||||
case "markdown":
|
case "markdown":
|
||||||
|
|
|
@ -38,7 +38,12 @@ export function fmtCurrency(value: number | string, currency = "USD", locale = "
|
||||||
return formatter.format(value);
|
return formatter.format(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isImage(url: string) {
|
||||||
|
return /\.(jpg|jpeg|png|webp|avif|gif|svg)$/.test(url);
|
||||||
|
}
|
||||||
|
|
||||||
export type MaybeUrlResult = {
|
export type MaybeUrlResult = {
|
||||||
|
isImage: boolean,
|
||||||
isUrl: boolean;
|
isUrl: boolean;
|
||||||
url: string;
|
url: string;
|
||||||
text: string;
|
text: string;
|
||||||
|
@ -46,6 +51,7 @@ export type MaybeUrlResult = {
|
||||||
|
|
||||||
export function maybeUrl(str: string): MaybeUrlResult {
|
export function maybeUrl(str: string): MaybeUrlResult {
|
||||||
const result: MaybeUrlResult = {
|
const result: MaybeUrlResult = {
|
||||||
|
isImage: isImage(str),
|
||||||
isUrl: str.startsWith("http://") || str.startsWith("https://"),
|
isUrl: str.startsWith("http://") || str.startsWith("https://"),
|
||||||
url: "",
|
url: "",
|
||||||
text: "",
|
text: "",
|
||||||
|
|
|
@ -186,7 +186,14 @@
|
||||||
* Support Special URL Syntax
|
* Support Special URL Syntax
|
||||||
*/
|
*/
|
||||||
const url = maybeUrl(field.textValue);
|
const url = maybeUrl(field.textValue);
|
||||||
if (url.isUrl) {
|
if (url.isImage) {
|
||||||
|
return {
|
||||||
|
type: "image",
|
||||||
|
name: field.name,
|
||||||
|
text: url.text,
|
||||||
|
href: url.url,
|
||||||
|
} as AnyDetail;
|
||||||
|
} else {
|
||||||
return {
|
return {
|
||||||
type: "link",
|
type: "link",
|
||||||
name: field.name,
|
name: field.name,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue