Emdash source with visual editor image upload fix
Fixes: 1. media.ts: wrap placeholder generation in try-catch 2. toolbar.ts: check r.ok, display error message in popover
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import type { ArbitraryTypedObject } from "@portabletext/types";
|
||||
|
||||
import type { ContentfulEntry } from "../types.js";
|
||||
|
||||
export function transformCodeBlock(entry: ContentfulEntry, key: string): ArbitraryTypedObject {
|
||||
return {
|
||||
_type: "code",
|
||||
_key: key,
|
||||
code: (entry.fields.code as string) ?? "",
|
||||
language: (entry.fields.language as string) ?? "",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import type { ArbitraryTypedObject } from "@portabletext/types";
|
||||
|
||||
import type { ContentfulEntry } from "../types.js";
|
||||
|
||||
/** HTML is preserved verbatim — sanitization is the renderer's responsibility. */
|
||||
export function transformEmbeddedHtml(entry: ContentfulEntry, key: string): ArbitraryTypedObject {
|
||||
return {
|
||||
_type: "htmlBlock",
|
||||
_key: key,
|
||||
html: (entry.fields.customHtml as string) ?? "",
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { ArbitraryTypedObject } from "@portabletext/types";
|
||||
|
||||
import { sanitizeUri } from "../sanitize.js";
|
||||
import type { ContentfulEntry, ContentfulIncludes } from "../types.js";
|
||||
|
||||
export function transformImageBlock(
|
||||
entry: ContentfulEntry,
|
||||
includes: ContentfulIncludes,
|
||||
key: string,
|
||||
): ArbitraryTypedObject {
|
||||
const assetLink = entry.fields.assetFile as { sys?: { id?: string } } | undefined;
|
||||
const assetId = assetLink?.sys?.id;
|
||||
const asset = assetId ? includes.assets.get(assetId) : undefined;
|
||||
|
||||
const src = asset?.url ? (asset.url.startsWith("//") ? `https:${asset.url}` : asset.url) : "";
|
||||
|
||||
return {
|
||||
_type: "image",
|
||||
_key: key,
|
||||
asset: {
|
||||
src,
|
||||
alt: asset?.description ?? asset?.title ?? "",
|
||||
width: asset?.width,
|
||||
height: asset?.height,
|
||||
},
|
||||
linkUrl: entry.fields.linkUrl ? sanitizeUri(entry.fields.linkUrl as string) : undefined,
|
||||
size: (entry.fields.size as string) ?? undefined,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user