import type { Language } from "prism-react-renderer";
import { Highlight } from "prism-react-renderer";
import queryString from "query-string";
import * as React from "react";
import { useHotkeys } from "react-hotkeys-hook";
import {
stories,
storySource,
StorySourceHeader,
} from "virtual:generated-list";
import { ActionType, AddonProps, GlobalState } from "../../../shared/types";
import config from "../get-config";
import { Source } from "../icons";
import { Modal } from "../ui";
export const getQuery = (locationSearch: string) => {
const urlVal = queryString.parse(locationSearch).source;
if (urlVal === "true") return true;
if (urlVal === "false") return false;
return config.addons.source.defaultState;
};
export const CodeHighlight = ({
children,
theme,
language = "tsx",
locStart,
locEnd,
className,
}: {
children: string;
theme: string;
language?: Language;
locStart?: number;
locEnd?: number;
className?: string;
}) => {
const withLoc =
typeof locStart !== "undefined" && typeof locEnd !== "undefined";
const match = /language-(\w+)/.exec(className || "");
if (match) {
language = match[1] as Language;
return (
{tokens.map((line, i) => (
)}
{children};
};
const CodeFrame = ({ globalState }: { globalState: GlobalState }) => {
if (!stories[globalState.story]) {
return <>There is no story loaded.>;
}
const { entry, locStart, locEnd } = stories[globalState.story];
React.useEffect(() => {
window.location.hash = ``;
window.location.hash = `ladle_loc_${locStart}`;
}, [locStart]);
return (
<>