import VideoPlayer from "./video-player";
import { createEffect, createSignal, For, Show } from "solid-js";
import { A } from "@solidjs/router";
import { pds } from "./navbar";
import Tooltip from "./tooltip";
import { hideMedia } from "./settings";
interface AtBlob {
$type: string;
ref: { $link: string };
mimeType: string;
}
const ATURI_RE =
/^at:\/\/([a-zA-Z0-9._:%-]+)(?:\/([a-zA-Z0-9-.]+)(?:\/([a-zA-Z0-9._~:@!$&%')(*+,;=-]+))?)?(?:#(\/[a-zA-Z0-9._~:@!$&%')(*+,;=\-[\]/\\]*))?$/;
const DID_RE = /^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$/;
const JSONString = ({ data }: { data: string }) => {
const isURL =
URL.canParse ??
((url, base) => {
try {
new URL(url, base);
return true;
} catch {
return false;
}
});
return (
"
{(part) => (
<>
{ATURI_RE.test(part) ?
{part}
: DID_RE.test(part) ?
{part}
: (
isURL(part) &&
["http:", "https:", "web+at:"].includes(new URL(part).protocol) &&
part.split("\n").length === 1
) ?
{part}
: part}
>
)}
"
);
};
const JSONNumber = ({ data }: { data: number }) => {
return {data};
};
const JSONBoolean = ({ data }: { data: boolean }) => {
return {data ? "true" : "false"};
};
const JSONNull = () => {
return null;
};
const JSONObject = ({ data, repo }: { data: { [x: string]: JSONType }; repo: string }) => {
const [hide, setHide] = createSignal(localStorage.hideMedia === "true");
createEffect(() => setHide(hideMedia()));
const Obj = ({ key, value }: { key: string; value: JSONType }) => {
const [show, setShow] = createSignal(true);
return (
);
};
const rawObj = (
{([key, value]) => }
);
const blob: AtBlob = data as any;
if (blob.$type === "blob") {
return (
<>
{rawObj}
>
);
}
return rawObj;
};
const JSONArray = ({ data, repo }: { data: JSONType[]; repo: string }) => {
return (
{(value, index) => (
)}
);
};
export const JSONValue = ({ data, repo }: { data: JSONType; repo: string }) => {
if (typeof data === "string") return ;
if (typeof data === "number") return ;
if (typeof data === "boolean") return ;
if (data === null) return ;
if (Array.isArray(data)) return ;
return ;
};
export type JSONType = string | number | boolean | null | { [x: string]: JSONType } | JSONType[];