@plexui/ui 0.61.0 → 0.61.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,10 +35,15 @@ export function Markdown({ children, directives, includeMath = false, breakNewLi
35
35
  acc[directive.directiveName] = directive.render;
36
36
  return acc;
37
37
  }, baseComponents) ?? baseComponents;
38
+ // The directives this Markdown renders as elements: its own and the components' tags
39
+ const directiveNames = [
40
+ ...(directives?.map((directive) => directive.directiveName) ?? []),
41
+ ...Object.keys(propsComponents ?? {}),
42
+ ].join("\n");
38
43
  const mergedRemarkPlugins = useMemo(() => {
39
44
  const baseRemarkPlugins = [
40
45
  remarkDirective,
41
- reactMarkdownRemarkDirective,
46
+ [reactMarkdownRemarkDirective, { names: directiveNames.split("\n") }],
42
47
  ...mathPlugins.remarkPlugins,
43
48
  ];
44
49
  if (breakNewLines) {
@@ -52,7 +57,7 @@ export function Markdown({ children, directives, includeMath = false, breakNewLi
52
57
  baseRemarkPlugins.push([remarkGfm, { singleTilde: false }]);
53
58
  }
54
59
  return [...baseRemarkPlugins, ...(remarkPlugins ?? [])];
55
- }, [mathPlugins.remarkPlugins, remarkPlugins, breakNewLines]);
60
+ }, [mathPlugins.remarkPlugins, remarkPlugins, breakNewLines, directiveNames]);
56
61
  return (_jsx(ReactMarkdown, { className: clsx(s.MarkdownContent, className), remarkPlugins: mergedRemarkPlugins, rehypePlugins: [...(rehypePlugins ?? []), ...mathPlugins.rehypePlugins], components: components, allowedElements: allowedElements, disallowedElements: disallowedElements, skipHtml: skipHtml, urlTransform: urlTransform, children: children }));
57
62
  }
58
63
  const Pre = ({ children, className }) => {
@@ -1 +1 @@
1
- {"version":3,"file":"Markdown.js","sourceRoot":"","sources":["../../../../src/components/Markdown/Markdown.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAgD,MAAM,OA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,UAAU;IAChB,GAAG,EAAE,GAAG;IACR,CAAC,EAAE,MAAM;IACT,EAAE,EAAE,SAAS;CACd,CAAA;AAED,MAAM,oBAAoB,GAAsB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;IAC1E,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAA;IACxD,OAAO,CACL,KAAC,aAAa,IAAC,SAAS,EAAE,SAAS,YACjC,KAAC,aAAa,CAAC,IAAI,IAAC,QAAQ,EAAE,QAAQ,YAAG,IAAI,GAAsB,GACrD,CACjB,CAAA;AACH,CAAC,CAAA;AAED,MAAM,kCAAkC,GAAsC;IAC5E,GAAG,EAAE,oBAAoB;CACjB,CAAA;AAEV,MAAM,cAAc,GAAsB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;IACpE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAA;IACxD,OAAO,CACL,KAAC,oBAAoB,IAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,YAC3D,IAAI,GACgB,CACxB,CAAA;AACH,CAAC,CAAA;AAED,MAAM,iCAAiC,GAAsC;IAC3E,GAAG,EAAE,cAAc;CACX,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { Children, useMemo, type ComponentProps, type FC, type ReactNode } from \"react\"\nimport ReactMarkdown from \"react-markdown\"\nimport remarkBreaks from \"remark-breaks\"\nimport remarkDirective from \"remark-directive\"\nimport remarkGfm from \"remark-gfm\"\n\nimport { CodeBlock, CodeBlockBase } from \"../CodeBlock/CodeBlock\"\nimport { CollapsibleCodeBlock } from \"../CodeBlock/CollapsibleCodeBlock\"\nimport { TextLink } from \"../TextLink/TextLink\"\nimport { reactMarkdownRemarkDirective, type MarkdownDirective } from \"./directives\"\nimport s from \"@plexui/styles/components/Markdown/Markdown.module.css\"\nimport { defaultUrlTransform } from \"./urlTransform\"\nimport { useMathPlugins } from \"./useMathPlugins\"\nimport { useParseMarkdownPre } from \"./useParseMarkdownPre\"\n\nconst supportsLookbehind = (() => {\n try {\n new RegExp(\"(?<=a)b\")\n return true\n } catch {\n return false\n }\n})()\n\nexport type MarkdownComponent = FC<{\n children?: ReactNode\n className?: string\n node: Record<string, unknown>\n}>\n\nexport type MarkdownProps = {\n children: string\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n directives?: MarkdownDirective<any>[]\n /** Determines if remark-math plugins should be loaded for rendering LaTeX */\n includeMath?: boolean\n /** Determines whether single newlines should insert <br> tags */\n breakNewLines?: boolean\n components?: Record<string, MarkdownComponent>\n remarkPlugins?: ComponentProps<typeof ReactMarkdown>[\"remarkPlugins\"]\n rehypePlugins?: ComponentProps<typeof ReactMarkdown>[\"rehypePlugins\"]\n allowedElements?: ComponentProps<typeof ReactMarkdown>[\"allowedElements\"]\n disallowedElements?: ComponentProps<typeof ReactMarkdown>[\"disallowedElements\"]\n urlTransform?: ComponentProps<typeof ReactMarkdown>[\"urlTransform\"]\n skipHtml?: boolean\n className?: string\n copyableCodeBlocks?: boolean\n /** Determines if code blocks should use the collapsible view with \"View Code\" button */\n collapsibleCodeBlocks?: boolean\n}\n\nexport function Markdown({\n children,\n directives,\n includeMath = false,\n breakNewLines = false,\n components: propsComponents,\n remarkPlugins,\n rehypePlugins,\n allowedElements,\n disallowedElements,\n skipHtml,\n urlTransform = defaultUrlTransform,\n className,\n copyableCodeBlocks = true,\n collapsibleCodeBlocks = true,\n}: MarkdownProps) {\n const mathPlugins = useMathPlugins(includeMath)\n const baseComponents = {\n ...COMMON_COMPONENTS,\n ...(collapsibleCodeBlocks ? COLLAPSIBLE_CODE_BLOCK_COMPONENTS : null),\n ...(copyableCodeBlocks ? null : NON_COPYABLE_CODE_BLOCK_COMPONENTS),\n ...propsComponents,\n }\n const components =\n directives?.reduce((acc, directive) => {\n acc[directive.directiveName] = directive.render\n return acc\n }, baseComponents) ?? baseComponents\n\n const mergedRemarkPlugins = useMemo(() => {\n const baseRemarkPlugins = [\n remarkDirective,\n reactMarkdownRemarkDirective,\n ...mathPlugins.remarkPlugins,\n ]\n\n if (breakNewLines) {\n baseRemarkPlugins.push(remarkBreaks)\n }\n\n // remark-gfm requires lookbehind support, which will throw in <= Safari 16.4\n // with no easily available polyfill.\n if (supportsLookbehind) {\n // Do not treat single tilde as strikethrough to allow for more\n // conversational use cases such as \"~$20-$30\"\n baseRemarkPlugins.push([remarkGfm, { singleTilde: false }])\n }\n\n return [...baseRemarkPlugins, ...(remarkPlugins ?? [])]\n }, [mathPlugins.remarkPlugins, remarkPlugins, breakNewLines])\n\n return (\n <ReactMarkdown\n className={clsx(s.MarkdownContent, className)}\n remarkPlugins={mergedRemarkPlugins}\n rehypePlugins={[...(rehypePlugins ?? []), ...mathPlugins.rehypePlugins]}\n components={components}\n allowedElements={allowedElements}\n disallowedElements={disallowedElements}\n skipHtml={skipHtml}\n urlTransform={urlTransform}\n >\n {children}\n </ReactMarkdown>\n )\n}\n\nconst Pre: MarkdownComponent = ({ children, className }) => {\n const { code, language } = useParseMarkdownPre(children)\n return (\n <CodeBlock language={language} className={className}>\n {code}\n </CodeBlock>\n )\n}\n\nconst InlineCode: MarkdownComponent = ({ children, className }) => (\n <code className={clsx(s.InlineCode, className)}>{children}</code>\n)\n\nconst Anchor: MarkdownComponent = ({ children, node: _node, ...props }) => (\n <TextLink as=\"a\" {...props}>\n {children}\n </TextLink>\n)\n\n// Sourced from common markdown implementations\nconst TableCell: MarkdownComponent = ({ node: _node, children, ...rest }) => {\n return (\n <td {...rest}>\n {Children.map(children, (child, i) =>\n // ReactMarkdown does not support <br> tags in tables without using\n // remark-html (which may not be safe), so we need to manually handle them\n child === \"<br>\" ? <br key={i} /> : child,\n )}\n </td>\n )\n}\n\nconst COMMON_COMPONENTS: Record<string, MarkdownComponent> = {\n code: InlineCode,\n pre: Pre,\n a: Anchor,\n td: TableCell,\n}\n\nconst NonCopyableCodeBlock: MarkdownComponent = ({ children, className }) => {\n const { code, language } = useParseMarkdownPre(children)\n return (\n <CodeBlockBase className={className}>\n <CodeBlockBase.Code language={language}>{code}</CodeBlockBase.Code>\n </CodeBlockBase>\n )\n}\n\nconst NON_COPYABLE_CODE_BLOCK_COMPONENTS: Record<string, MarkdownComponent> = {\n pre: NonCopyableCodeBlock,\n} as const\n\nconst CollapsiblePre: MarkdownComponent = ({ children, className }) => {\n const { code, language } = useParseMarkdownPre(children)\n return (\n <CollapsibleCodeBlock language={language} className={className}>\n {code}\n </CollapsibleCodeBlock>\n )\n}\n\nconst COLLAPSIBLE_CODE_BLOCK_COMPONENTS: Record<string, MarkdownComponent> = {\n pre: CollapsiblePre,\n} as const\n"]}
1
+ {"version":3,"file":"Markdown.js","sourceRoot":"","sources":["../../../../src/components/Markdown/Markdown.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAgD,MAAM,OAAO,CAAA;AACvF,OAAO,aAAa,MAAM,gBAAgB,CAAA;AAC1C,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,OAAO,eAAe,MAAM,kBAAkB,CAAA;AAC9C,OAAO,SAAS,MAAM,YAAY,CAAA;AAElC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,4BAA4B,EAA0B,MAAM,cAAc,CAAA;AACnF,OAAO,CAAC,MAAM,wDAAwD,CAAA;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB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CAAC,QAAQ,CAAC,CAAA;IACxD,OAAO,CACL,KAAC,aAAa,IAAC,SAAS,EAAE,SAAS,YACjC,KAAC,aAAa,CAAC,IAAI,IAAC,QAAQ,EAAE,QAAQ,YAAG,IAAI,GAAsB,GACrD,CACjB,CAAA;AACH,CAAC,CAAA;AAED,MAAM,kCAAkC,GAAsC;IAC5E,GAAG,EAAE,oBAAoB;CACjB,CAAA;AAEV,MAAM,cAAc,GAAsB,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE;IACpE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAA;IACxD,OAAO,CACL,KAAC,oBAAoB,IAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,YAC3D,IAAI,GACgB,CACxB,CAAA;AACH,CAAC,CAAA;AAED,MAAM,iCAAiC,GAAsC;IAC3E,GAAG,EAAE,cAAc;CACX,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { Children, useMemo, type ComponentProps, type FC, type ReactNode } from \"react\"\nimport ReactMarkdown from \"react-markdown\"\nimport remarkBreaks from \"remark-breaks\"\nimport remarkDirective from \"remark-directive\"\nimport remarkGfm from \"remark-gfm\"\n\nimport { CodeBlock, CodeBlockBase } from \"../CodeBlock/CodeBlock\"\nimport { CollapsibleCodeBlock } from \"../CodeBlock/CollapsibleCodeBlock\"\nimport { TextLink } from \"../TextLink/TextLink\"\nimport { reactMarkdownRemarkDirective, type MarkdownDirective } from \"./directives\"\nimport s from \"@plexui/styles/components/Markdown/Markdown.module.css\"\nimport { defaultUrlTransform } from \"./urlTransform\"\nimport { useMathPlugins } from \"./useMathPlugins\"\nimport { useParseMarkdownPre } from \"./useParseMarkdownPre\"\n\nconst supportsLookbehind = (() => {\n try {\n new RegExp(\"(?<=a)b\")\n return true\n } catch {\n return false\n }\n})()\n\nexport type MarkdownComponent = FC<{\n children?: ReactNode\n className?: string\n node: Record<string, unknown>\n}>\n\nexport type MarkdownProps = {\n children: string\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n directives?: MarkdownDirective<any>[]\n /** Determines if remark-math plugins should be loaded for rendering LaTeX */\n includeMath?: boolean\n /** Determines whether single newlines should insert <br> tags */\n breakNewLines?: boolean\n components?: Record<string, MarkdownComponent>\n remarkPlugins?: ComponentProps<typeof ReactMarkdown>[\"remarkPlugins\"]\n rehypePlugins?: ComponentProps<typeof ReactMarkdown>[\"rehypePlugins\"]\n allowedElements?: ComponentProps<typeof ReactMarkdown>[\"allowedElements\"]\n disallowedElements?: ComponentProps<typeof ReactMarkdown>[\"disallowedElements\"]\n urlTransform?: ComponentProps<typeof ReactMarkdown>[\"urlTransform\"]\n skipHtml?: boolean\n className?: string\n copyableCodeBlocks?: boolean\n /** Determines if code blocks should use the collapsible view with \"View Code\" button */\n collapsibleCodeBlocks?: boolean\n}\n\nexport function Markdown({\n children,\n directives,\n includeMath = false,\n breakNewLines = false,\n components: propsComponents,\n remarkPlugins,\n rehypePlugins,\n allowedElements,\n disallowedElements,\n skipHtml,\n urlTransform = defaultUrlTransform,\n className,\n copyableCodeBlocks = true,\n collapsibleCodeBlocks = true,\n}: MarkdownProps) {\n const mathPlugins = useMathPlugins(includeMath)\n const baseComponents = {\n ...COMMON_COMPONENTS,\n ...(collapsibleCodeBlocks ? COLLAPSIBLE_CODE_BLOCK_COMPONENTS : null),\n ...(copyableCodeBlocks ? null : NON_COPYABLE_CODE_BLOCK_COMPONENTS),\n ...propsComponents,\n }\n const components =\n directives?.reduce((acc, directive) => {\n acc[directive.directiveName] = directive.render\n return acc\n }, baseComponents) ?? baseComponents\n\n // The directives this Markdown renders as elements: its own and the components' tags\n const directiveNames = [\n ...(directives?.map((directive) => directive.directiveName) ?? []),\n ...Object.keys(propsComponents ?? {}),\n ].join(\"\\n\")\n\n const mergedRemarkPlugins = useMemo(() => {\n const baseRemarkPlugins: NonNullable<MarkdownProps[\"remarkPlugins\"]> = [\n remarkDirective,\n [reactMarkdownRemarkDirective, { names: directiveNames.split(\"\\n\") }],\n ...mathPlugins.remarkPlugins,\n ]\n\n if (breakNewLines) {\n baseRemarkPlugins.push(remarkBreaks)\n }\n\n // remark-gfm requires lookbehind support, which will throw in <= Safari 16.4\n // with no easily available polyfill.\n if (supportsLookbehind) {\n // Do not treat single tilde as strikethrough to allow for more\n // conversational use cases such as \"~$20-$30\"\n baseRemarkPlugins.push([remarkGfm, { singleTilde: false }])\n }\n\n return [...baseRemarkPlugins, ...(remarkPlugins ?? [])]\n }, [mathPlugins.remarkPlugins, remarkPlugins, breakNewLines, directiveNames])\n\n return (\n <ReactMarkdown\n className={clsx(s.MarkdownContent, className)}\n remarkPlugins={mergedRemarkPlugins}\n rehypePlugins={[...(rehypePlugins ?? []), ...mathPlugins.rehypePlugins]}\n components={components}\n allowedElements={allowedElements}\n disallowedElements={disallowedElements}\n skipHtml={skipHtml}\n urlTransform={urlTransform}\n >\n {children}\n </ReactMarkdown>\n )\n}\n\nconst Pre: MarkdownComponent = ({ children, className }) => {\n const { code, language } = useParseMarkdownPre(children)\n return (\n <CodeBlock language={language} className={className}>\n {code}\n </CodeBlock>\n )\n}\n\nconst InlineCode: MarkdownComponent = ({ children, className }) => (\n <code className={clsx(s.InlineCode, className)}>{children}</code>\n)\n\nconst Anchor: MarkdownComponent = ({ children, node: _node, ...props }) => (\n <TextLink as=\"a\" {...props}>\n {children}\n </TextLink>\n)\n\n// Sourced from common markdown implementations\nconst TableCell: MarkdownComponent = ({ node: _node, children, ...rest }) => {\n return (\n <td {...rest}>\n {Children.map(children, (child, i) =>\n // ReactMarkdown does not support <br> tags in tables without using\n // remark-html (which may not be safe), so we need to manually handle them\n child === \"<br>\" ? <br key={i} /> : child,\n )}\n </td>\n )\n}\n\nconst COMMON_COMPONENTS: Record<string, MarkdownComponent> = {\n code: InlineCode,\n pre: Pre,\n a: Anchor,\n td: TableCell,\n}\n\nconst NonCopyableCodeBlock: MarkdownComponent = ({ children, className }) => {\n const { code, language } = useParseMarkdownPre(children)\n return (\n <CodeBlockBase className={className}>\n <CodeBlockBase.Code language={language}>{code}</CodeBlockBase.Code>\n </CodeBlockBase>\n )\n}\n\nconst NON_COPYABLE_CODE_BLOCK_COMPONENTS: Record<string, MarkdownComponent> = {\n pre: NonCopyableCodeBlock,\n} as const\n\nconst CollapsiblePre: MarkdownComponent = ({ children, className }) => {\n const { code, language } = useParseMarkdownPre(children)\n return (\n <CollapsibleCodeBlock language={language} className={className}>\n {code}\n </CollapsibleCodeBlock>\n )\n}\n\nconst COLLAPSIBLE_CODE_BLOCK_COMPONENTS: Record<string, MarkdownComponent> = {\n pre: CollapsiblePre,\n} as const\n"]}
@@ -1,5 +1,5 @@
1
1
  import {} from "react";
2
- import { visit } from "unist-util-visit";
2
+ import { SKIP, visit } from "unist-util-visit";
3
3
  import { createId } from "../../lib/ids.js";
4
4
  import { decodeBase64, encodeBase64 } from "../../lib/safeBase64.js";
5
5
  export function createMarkdownDirective({ render, name, mode, }) {
@@ -18,16 +18,58 @@ export function createMarkdownDirective({ render, name, mode, }) {
18
18
  };
19
19
  return directive;
20
20
  }
21
- export function reactMarkdownRemarkDirective() {
21
+ /**
22
+ * A directive's attribute reaches its element only as a plain HTML attribute: a lowercase name (`title`, `data-*`,
23
+ * `aria-*`), so never a DOM property such as `innerHTML` or React's `dangerouslySetInnerHTML`; never an event handler,
24
+ * an inline style, a frame's document or `is`.
25
+ */
26
+ const ATTRIBUTE_NAME = /^[a-z][a-z0-9-]*$/;
27
+ const UNSAFE_ATTRIBUTE = /^(?:on|style$|srcdoc$|formaction$|is$)/;
28
+ /** The attributes that load or open a URL: one with a protocol other than Markdown's safe ones is dropped. */
29
+ const URL_ATTRIBUTES = new Set(["href", "src", "action", "cite", "poster", "background", "ping", "data", "codebase"]);
30
+ const SAFE_PROTOCOL = /^(?:https?|ircs?|mailto|xmpp|tel|sms)$/i;
31
+ /** react-markdown's `defaultUrlTransform` test, with `tel:` and `sms:` as the Markdown's own transform. */
32
+ const isSafeUrl = (value) => {
33
+ const colon = value.indexOf(":");
34
+ const firstOf = (char) => value.indexOf(char);
35
+ return (colon === -1 ||
36
+ [firstOf("/"), firstOf("?"), firstOf("#")].some((index) => index !== -1 && colon > index) ||
37
+ SAFE_PROTOCOL.test(value.slice(0, colon).trim()));
38
+ };
39
+ const safeAttributes = (attributes) => Object.fromEntries(Object.entries(attributes ?? {}).filter(([key, value]) => ATTRIBUTE_NAME.test(key) &&
40
+ !UNSAFE_ATTRIBUTE.test(key) &&
41
+ !(URL_ATTRIBUTES.has(key) && !isSafeUrl(String(value ?? "")))));
42
+ /**
43
+ * Directives become elements only when the Markdown knows them: a `directives` entry or a `components` key, with
44
+ * their attributes minus event handlers, `style` and `srcdoc`. Any other directive stays what was written: an inline
45
+ * or leaf one its source text, a container one its content in a plain `div`. Text from elsewhere (a server, a user)
46
+ * can't make an element of its choosing with attributes of its choosing.
47
+ */
48
+ export function reactMarkdownRemarkDirective(options = {}) {
49
+ const names = new Set(options.names ?? []);
22
50
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
- return (tree) => {
24
- visit(tree, ["textDirective", "leafDirective", "containerDirective"], (node) => {
25
- node.data = {
26
- hName: node.name,
27
- hProperties: node.attributes,
28
- ...node.data,
29
- };
30
- return node;
51
+ return (tree, file) => {
52
+ const source = file?.value == null ? "" : String(file.value);
53
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
+ visit(tree, ["textDirective", "leafDirective", "containerDirective"], (node, index, parent) => {
55
+ if (names.has(node.name)) {
56
+ node.data = { hName: node.name, hProperties: safeAttributes(node.attributes), ...node.data };
57
+ return;
58
+ }
59
+ if (node.type === "containerDirective") {
60
+ node.data = { hName: "div", hProperties: {}, ...node.data };
61
+ return;
62
+ }
63
+ if (!parent || typeof index !== "number")
64
+ return;
65
+ const start = node.position?.start?.offset;
66
+ const end = node.position?.end?.offset;
67
+ const value = typeof start === "number" && typeof end === "number" && end <= source.length
68
+ ? source.slice(start, end)
69
+ : `${node.type === "leafDirective" ? "::" : ":"}${node.name}`;
70
+ const text = { type: "text", value };
71
+ parent.children[index] = node.type === "leafDirective" ? { type: "paragraph", children: [text] } : text;
72
+ return SKIP;
31
73
  });
32
74
  };
33
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"directives.js","sourceRoot":"","sources":["../../../../src/components/Markdown/directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAUjE,MAAM,UAAU,uBAAuB,CAAgC,EACrE,MAAM,EACN,IAAI,EACJ,IAAI,GAKL;IACC,MAAM,MAAM,GAAG,kBAAkB,IAAI,EAAE,CAAA;IACvC,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAEtD,SAAS,SAAS,CAAC,KAAQ;QACzB,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,GAAG,KAAK,CAAA;QACzC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAA;QAC9F,MAAM,MAAM,GAAG,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;QAEnD,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,KAAK,GAAG,CAAA;IAC7E,CAAC;IAED,SAAS,CAAC,aAAa,GAAG,UAAU,CAAA;IACpC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,QAAQ,EAAE,KAAK,EAA4C,EAAE,EAAE;QACnF,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,YAAY,CAAI,KAAK,CAAC,CAAC,CAAC,CAAE,EAAQ,CAAA;QAC9D,OAAO,MAAM,CAAC,EAAE,GAAG,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC7C,CAAC,CAAA;IAED,OAAO,SAAS,CAAA;AAClB,CAAC;AAED,MAAM,UAAU,4BAA4B;IAC1C,8DAA8D;IAC9D,OAAO,CAAC,IAAS,EAAE,EAAE;QACnB,KAAK,CAAC,IAAI,EAAE,CAAC,eAAe,EAAE,eAAe,EAAE,oBAAoB,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE;YAC7E,IAAI,CAAC,IAAI,GAAG;gBACV,KAAK,EAAE,IAAI,CAAC,IAAI;gBAChB,WAAW,EAAE,IAAI,CAAC,UAAU;gBAC5B,GAAG,IAAI,CAAC,IAAI;aACb,CAAA;YACD,OAAO,IAAI,CAAA;QACb,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC","sourcesContent":["import { type ReactNode } from \"react\"\nimport { visit } from \"unist-util-visit\"\nimport { createId } from \"../../lib/ids\"\nimport { decodeBase64, encodeBase64 } from \"../../lib/safeBase64\"\n\ntype ValidDirectiveProps = { children?: string } & Partial<Record<string, unknown>>\n\nexport interface MarkdownDirective<T extends ValidDirectiveProps = ValidDirectiveProps> {\n directiveName: string\n render: (props: { attrs?: string; children?: ReactNode }) => ReactNode\n (props: T): string\n}\n\nexport function createMarkdownDirective<T extends ValidDirectiveProps>({\n render,\n name,\n mode,\n}: {\n render: (props: T) => ReactNode\n name: string\n mode: \"inline\" | \"block\"\n}): MarkdownDirective<T> {\n const prefix = `OaiMdDirective_${name}`\n const uniqueName = createId(prefix, prefix.length + 6)\n\n function directive(props: T) {\n const { children, ...attributes } = props\n const attrs = Object.keys(attributes).length >= 0 ? `attrs=\"${encodeBase64(attributes)}\"` : \"\"\n const leader = mode === \"inline\" ? \" :\" : \"\\n\\n:::\"\n\n return `${leader}${uniqueName}${children ? `[${children}]` : \"\"}{${attrs}}`\n }\n\n directive.directiveName = uniqueName\n directive.render = ({ children, attrs }: { children?: ReactNode; attrs?: string }) => {\n const parsedAttrs = attrs ? decodeBase64<T>(attrs) : ({} as T)\n return render({ ...parsedAttrs, children })\n }\n\n return directive\n}\n\nexport function reactMarkdownRemarkDirective() {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (tree: any) => {\n visit(tree, [\"textDirective\", \"leafDirective\", \"containerDirective\"], (node) => {\n node.data = {\n hName: node.name,\n hProperties: node.attributes,\n ...node.data,\n }\n return node\n })\n }\n}\n"]}
1
+ {"version":3,"file":"directives.js","sourceRoot":"","sources":["../../../../src/components/Markdown/directives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAUjE,MAAM,UAAU,uBAAuB,CAAgC,EACrE,MAAM,EACN,IAAI,EACJ,IAAI,GAKL;IACC,MAAM,MAAM,GAAG,kBAAkB,IAAI,EAAE,CAAA;IACvC,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAEtD,SAAS,SAAS,CAAC,KAAQ;QACzB,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,EAAE,GAAG,KAAK,CAAA;QACzC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EA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AAE,CAAC,CAAC,CAAC,IAAI,CAAA;YACvG,OAAO,IAAI,CAAA;QACb,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC","sourcesContent":["import { type ReactNode } from \"react\"\nimport { SKIP, visit } from \"unist-util-visit\"\nimport { createId } from \"../../lib/ids\"\nimport { decodeBase64, encodeBase64 } from \"../../lib/safeBase64\"\n\ntype ValidDirectiveProps = { children?: string } & Partial<Record<string, unknown>>\n\nexport interface MarkdownDirective<T extends ValidDirectiveProps = ValidDirectiveProps> {\n directiveName: string\n render: (props: { attrs?: string; children?: ReactNode }) => ReactNode\n (props: T): string\n}\n\nexport function createMarkdownDirective<T extends ValidDirectiveProps>({\n render,\n name,\n mode,\n}: {\n render: (props: T) => ReactNode\n name: string\n mode: \"inline\" | \"block\"\n}): MarkdownDirective<T> {\n const prefix = `OaiMdDirective_${name}`\n const uniqueName = createId(prefix, prefix.length + 6)\n\n function directive(props: T) {\n const { children, ...attributes } = props\n const attrs = Object.keys(attributes).length >= 0 ? `attrs=\"${encodeBase64(attributes)}\"` : \"\"\n const leader = mode === \"inline\" ? \" :\" : \"\\n\\n:::\"\n\n return `${leader}${uniqueName}${children ? `[${children}]` : \"\"}{${attrs}}`\n }\n\n directive.directiveName = uniqueName\n directive.render = ({ children, attrs }: { children?: ReactNode; attrs?: string }) => {\n const parsedAttrs = attrs ? decodeBase64<T>(attrs) : ({} as T)\n return render({ ...parsedAttrs, children })\n }\n\n return directive\n}\n\n/**\n * A directive's attribute reaches its element only as a plain HTML attribute: a lowercase name (`title`, `data-*`,\n * `aria-*`), so never a DOM property such as `innerHTML` or React's `dangerouslySetInnerHTML`; never an event handler,\n * an inline style, a frame's document or `is`.\n */\nconst ATTRIBUTE_NAME = /^[a-z][a-z0-9-]*$/\nconst UNSAFE_ATTRIBUTE = /^(?:on|style$|srcdoc$|formaction$|is$)/\n\n/** The attributes that load or open a URL: one with a protocol other than Markdown's safe ones is dropped. */\nconst URL_ATTRIBUTES = new Set([\"href\", \"src\", \"action\", \"cite\", \"poster\", \"background\", \"ping\", \"data\", \"codebase\"])\nconst SAFE_PROTOCOL = /^(?:https?|ircs?|mailto|xmpp|tel|sms)$/i\n\n/** react-markdown's `defaultUrlTransform` test, with `tel:` and `sms:` as the Markdown's own transform. */\nconst isSafeUrl = (value: string) => {\n const colon = value.indexOf(\":\")\n const firstOf = (char: string) => value.indexOf(char)\n return (\n colon === -1 ||\n [firstOf(\"/\"), firstOf(\"?\"), firstOf(\"#\")].some((index) => index !== -1 && colon > index) ||\n SAFE_PROTOCOL.test(value.slice(0, colon).trim())\n )\n}\n\nconst safeAttributes = (attributes: Record<string, unknown> | null | undefined) =>\n Object.fromEntries(\n Object.entries(attributes ?? {}).filter(\n ([key, value]) =>\n ATTRIBUTE_NAME.test(key) &&\n !UNSAFE_ATTRIBUTE.test(key) &&\n !(URL_ATTRIBUTES.has(key) && !isSafeUrl(String(value ?? \"\"))),\n ),\n )\n\n/**\n * Directives become elements only when the Markdown knows them: a `directives` entry or a `components` key, with\n * their attributes minus event handlers, `style` and `srcdoc`. Any other directive stays what was written: an inline\n * or leaf one its source text, a container one its content in a plain `div`. Text from elsewhere (a server, a user)\n * can't make an element of its choosing with attributes of its choosing.\n */\nexport function reactMarkdownRemarkDirective(options: { names?: Iterable<string> } = {}) {\n const names = new Set(options.names ?? [])\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (tree: any, file?: { value?: unknown }) => {\n const source = file?.value == null ? \"\" : String(file.value)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n visit(tree, [\"textDirective\", \"leafDirective\", \"containerDirective\"], (node: any, index, parent: any) => {\n if (names.has(node.name)) {\n node.data = { hName: node.name, hProperties: safeAttributes(node.attributes), ...node.data }\n return\n }\n if (node.type === \"containerDirective\") {\n node.data = { hName: \"div\", hProperties: {}, ...node.data }\n return\n }\n if (!parent || typeof index !== \"number\") return\n const start = node.position?.start?.offset\n const end = node.position?.end?.offset\n const value =\n typeof start === \"number\" && typeof end === \"number\" && end <= source.length\n ? source.slice(start, end)\n : `${node.type === \"leafDirective\" ? \"::\" : \":\"}${node.name}`\n const text = { type: \"text\", value }\n parent.children[index] = node.type === \"leafDirective\" ? { type: \"paragraph\", children: [text] } : text\n return SKIP\n })\n }\n}\n"]}
@@ -15,5 +15,15 @@ export declare function createMarkdownDirective<T extends ValidDirectiveProps>({
15
15
  name: string;
16
16
  mode: "inline" | "block";
17
17
  }): MarkdownDirective<T>;
18
- export declare function reactMarkdownRemarkDirective(): (tree: any) => void;
18
+ /**
19
+ * Directives become elements only when the Markdown knows them: a `directives` entry or a `components` key, with
20
+ * their attributes minus event handlers, `style` and `srcdoc`. Any other directive stays what was written: an inline
21
+ * or leaf one its source text, a container one its content in a plain `div`. Text from elsewhere (a server, a user)
22
+ * can't make an element of its choosing with attributes of its choosing.
23
+ */
24
+ export declare function reactMarkdownRemarkDirective(options?: {
25
+ names?: Iterable<string>;
26
+ }): (tree: any, file?: {
27
+ value?: unknown;
28
+ }) => void;
19
29
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexui/ui",
3
- "version": "0.61.0",
3
+ "version": "0.61.1",
4
4
  "description": "Modern design system for building high-quality applications",
5
5
  "type": "module",
6
6
  "license": "MIT",