@tabnews/ui
Version:
TabNews UI
110 lines (109 loc) • 3.79 kB
JavaScript
"use client";
import { jsxs as k, jsx as c } from "react/jsx-runtime";
import L from "@bytemd/plugin-breaks";
import C from "@bytemd/plugin-gemoji";
import w from "@bytemd/plugin-gfm";
import S from "@bytemd/plugin-gfm/locales/pt_BR.json";
import v from "@bytemd/plugin-highlight-ssr";
import j from "@bytemd/plugin-math";
import z from "@bytemd/plugin-math/locales/pt_BR.json";
import E from "@bytemd/plugin-mermaid";
import M from "@bytemd/plugin-mermaid/locales/pt_BR.json";
import { Editor as R, Viewer as T } from "@bytemd/react";
import { Box as B, useTheme as N } from "@primer/react";
import V from "../node_modules/bytemd/locales/pt_BR.json.js";
import { useRef as q, useEffect as l, useState as H, useMemo as O } from "react";
import { anchorHeadersPlugin as $ } from "./plugins/anchor-headers.js";
import { copyCodeToClipboardPlugin as D } from "./plugins/copy-code-to-clipboard.js";
import { externalLinksPlugin as F } from "./plugins/external-links.js";
import { removeDuplicateClobberPrefix as G } from "./plugins/remove-duplicate-clobber-prefix.js";
import { EditorStyles as I } from "./styles/index.js";
/* empty css */
/* empty css */
const J = [
w({ locale: S }),
v(),
j({
locale: z,
katexOptions: { output: "html" }
}),
L(),
C(),
D()
];
function f({ areLinksTrusted: i, clobberPrefix: e, shouldAddNofollow: t }) {
const { colorScheme: o } = N();
return O(() => {
const n = o === "dark" ? "dark" : "default", r = [
...J,
E({ locale: M, theme: n }),
$({ prefix: e ?? "user-content-" }),
G({ clobberPrefix: e })
];
return i || r.push(F({ shouldAddNofollow: t })), r;
}, [i, e, o, t]);
}
function ut({ value: i, areLinksTrusted: e, clobberPrefix: t, shouldAddNofollow: o, ...a }) {
t = t == null ? void 0 : t.toLowerCase();
const n = f({ areLinksTrusted: e, clobberPrefix: t, shouldAddNofollow: o }), [r, s] = H(i);
return l(() => {
let u;
return s((p) => (u = setTimeout(() => s(p)), p + `
Š`)), () => clearTimeout(u);
}, [n]), l(() => s(i), [i]), /* @__PURE__ */ c(
T,
{
sanitize: y({ clobberPrefix: t }),
remarkRehype: { clobberPrefix: t },
plugins: n,
value: r,
...a
}
);
}
function pt({
areLinksTrusted: i,
clobberPrefix: e,
editorConfig: t = {},
initialHeight: o = "30vh",
isInvalid: a,
mode: n = "split",
// 'tab'
onKeyDown: r,
shouldAddNofollow: s,
...u
}) {
e = e == null ? void 0 : e.toLowerCase();
const p = f({ areLinksTrusted: i, clobberPrefix: e, shouldAddNofollow: s }), g = q();
return l(() => {
const m = g.current;
return m == null || m.addEventListener("keydown", r), () => m == null ? void 0 : m.removeEventListener("keydown", r);
}, [r]), l(() => {
var m, h, d;
(d = (h = (m = g.current) == null ? void 0 : m.getElementsByClassName("bytemd-toolbar-right")[0]) == null ? void 0 : h.querySelector('[bytemd-tippy-path="2"]')) == null || d.click();
}, []), /* @__PURE__ */ k(B, { sx: { width: "100%" }, ref: g, className: a ? "is-invalid" : "", children: [
/* @__PURE__ */ c(
R,
{
plugins: p,
mode: n,
locale: V,
sanitize: y({ clobberPrefix: e }),
editorConfig: { autocapitalize: "sentences", inputStyle: "contenteditable", spellcheck: !0, ...t },
remarkRehype: { clobberPrefix: e },
...u
}
),
/* @__PURE__ */ c(I, { height: o, mode: n })
] });
}
function y(i = {}) {
return (e) => {
const t = { ...e, ...i };
return t.attributes["*"] = t.attributes["*"].filter((o) => !["className", "target"].includes(o)), t.attributes["*"].push(["className", /^hljs|^language-|^bytemd-mermaid$|^math/]), t;
};
}
export {
pt as MarkdownEditor,
ut as MarkdownViewer
};