@particle-academy/react-fancy 4.9.0 → 4.11.0

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.
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { ButtonHTMLAttributes, AnchorHTMLAttributes, ReactNode, InputHTMLAttributes, TextareaHTMLAttributes, SelectHTMLAttributes, FormHTMLAttributes, TdHTMLAttributes, HTMLAttributes, ComponentType, CSSProperties, ReactElement, RefObject } from 'react';
2
+ import { ButtonHTMLAttributes, ElementType, AnchorHTMLAttributes, ReactNode, InputHTMLAttributes, TextareaHTMLAttributes, SelectHTMLAttributes, FormHTMLAttributes, TdHTMLAttributes, HTMLAttributes, ComponentType, CSSProperties, ReactElement, RefObject } from 'react';
3
3
  import { ClassValue } from 'clsx';
4
4
 
5
5
  type Size = "xs" | "sm" | "md" | "lg" | "xl";
@@ -59,6 +59,14 @@ interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "col
59
59
  disabled?: boolean;
60
60
  /** Render as anchor tag */
61
61
  href?: string;
62
+ /**
63
+ * Anchor-mode element override — the component to render INSTEAD of the
64
+ * plain `<a>` when `href` is set, e.g. a router's `<Link>` (Inertia, React
65
+ * Router, Next) so the button navigates client-side. Receives `href`,
66
+ * `className`, and the forwarded rest props. Ignored without `href` or when
67
+ * `disabled` (the plain `<button>` renders as always).
68
+ */
69
+ as?: ElementType;
62
70
  /** Anchor `target` — only applies in `href` (anchor) mode. */
63
71
  target?: AnchorHTMLAttributes<HTMLAnchorElement>["target"];
64
72
  /** Anchor `rel` — only applies in `href` (anchor) mode. */
@@ -2062,6 +2070,17 @@ interface EditorProps {
2062
2070
  defaultValue?: string;
2063
2071
  onChange?: (value: string) => void;
2064
2072
  outputFormat?: "html" | "markdown";
2073
+ /**
2074
+ * The format of the INCOMING `value` / `defaultValue`. Default `"auto"`
2075
+ * keeps the historical sniff (`detectFormat`) — but real-world markdown that
2076
+ * merely mentions HTML-ish snippets (`<code>`, `<table`, …) flips the sniff
2077
+ * to html and renders as a wall of text. Callers with a KNOWN format
2078
+ * (file-typed content, values previously emitted with
2079
+ * `outputFormat="markdown"`) should declare it; explicit values bypass the
2080
+ * sniff entirely — in edit mode AND view mode.
2081
+ * @default "auto"
2082
+ */
2083
+ valueFormat?: "markdown" | "html" | "auto";
2065
2084
  lineSpacing?: number;
2066
2085
  placeholder?: string;
2067
2086
  /**
@@ -2099,7 +2118,7 @@ declare namespace EditorContent {
2099
2118
  var displayName: string;
2100
2119
  }
2101
2120
 
2102
- declare function EditorRoot({ children, className, value: controlledValue, defaultValue, onChange, outputFormat, lineSpacing, placeholder, mode: modeProp, extensions: instanceExtensions, unsafe, }: EditorProps): react.JSX.Element;
2121
+ declare function EditorRoot({ children, className, value: controlledValue, defaultValue, onChange, outputFormat, valueFormat, lineSpacing, placeholder, mode: modeProp, extensions: instanceExtensions, unsafe, }: EditorProps): react.JSX.Element;
2103
2122
  declare const Editor: typeof EditorRoot & {
2104
2123
  Toolbar: typeof EditorToolbar & {
2105
2124
  Separator: typeof EditorToolbarSeparator;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { ButtonHTMLAttributes, AnchorHTMLAttributes, ReactNode, InputHTMLAttributes, TextareaHTMLAttributes, SelectHTMLAttributes, FormHTMLAttributes, TdHTMLAttributes, HTMLAttributes, ComponentType, CSSProperties, ReactElement, RefObject } from 'react';
2
+ import { ButtonHTMLAttributes, ElementType, AnchorHTMLAttributes, ReactNode, InputHTMLAttributes, TextareaHTMLAttributes, SelectHTMLAttributes, FormHTMLAttributes, TdHTMLAttributes, HTMLAttributes, ComponentType, CSSProperties, ReactElement, RefObject } from 'react';
3
3
  import { ClassValue } from 'clsx';
4
4
 
5
5
  type Size = "xs" | "sm" | "md" | "lg" | "xl";
@@ -59,6 +59,14 @@ interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "col
59
59
  disabled?: boolean;
60
60
  /** Render as anchor tag */
61
61
  href?: string;
62
+ /**
63
+ * Anchor-mode element override — the component to render INSTEAD of the
64
+ * plain `<a>` when `href` is set, e.g. a router's `<Link>` (Inertia, React
65
+ * Router, Next) so the button navigates client-side. Receives `href`,
66
+ * `className`, and the forwarded rest props. Ignored without `href` or when
67
+ * `disabled` (the plain `<button>` renders as always).
68
+ */
69
+ as?: ElementType;
62
70
  /** Anchor `target` — only applies in `href` (anchor) mode. */
63
71
  target?: AnchorHTMLAttributes<HTMLAnchorElement>["target"];
64
72
  /** Anchor `rel` — only applies in `href` (anchor) mode. */
@@ -2062,6 +2070,17 @@ interface EditorProps {
2062
2070
  defaultValue?: string;
2063
2071
  onChange?: (value: string) => void;
2064
2072
  outputFormat?: "html" | "markdown";
2073
+ /**
2074
+ * The format of the INCOMING `value` / `defaultValue`. Default `"auto"`
2075
+ * keeps the historical sniff (`detectFormat`) — but real-world markdown that
2076
+ * merely mentions HTML-ish snippets (`<code>`, `<table`, …) flips the sniff
2077
+ * to html and renders as a wall of text. Callers with a KNOWN format
2078
+ * (file-typed content, values previously emitted with
2079
+ * `outputFormat="markdown"`) should declare it; explicit values bypass the
2080
+ * sniff entirely — in edit mode AND view mode.
2081
+ * @default "auto"
2082
+ */
2083
+ valueFormat?: "markdown" | "html" | "auto";
2065
2084
  lineSpacing?: number;
2066
2085
  placeholder?: string;
2067
2086
  /**
@@ -2099,7 +2118,7 @@ declare namespace EditorContent {
2099
2118
  var displayName: string;
2100
2119
  }
2101
2120
 
2102
- declare function EditorRoot({ children, className, value: controlledValue, defaultValue, onChange, outputFormat, lineSpacing, placeholder, mode: modeProp, extensions: instanceExtensions, unsafe, }: EditorProps): react.JSX.Element;
2121
+ declare function EditorRoot({ children, className, value: controlledValue, defaultValue, onChange, outputFormat, valueFormat, lineSpacing, placeholder, mode: modeProp, extensions: instanceExtensions, unsafe, }: EditorProps): react.JSX.Element;
2103
2122
  declare const Editor: typeof EditorRoot & {
2104
2123
  Toolbar: typeof EditorToolbar & {
2105
2124
  Separator: typeof EditorToolbarSeparator;
package/dist/index.js CHANGED
@@ -2419,6 +2419,7 @@ var Button = forwardRef(
2419
2419
  loading = false,
2420
2420
  disabled,
2421
2421
  href,
2422
+ as: As,
2422
2423
  responsive,
2423
2424
  labelClassName,
2424
2425
  ...props
@@ -2581,11 +2582,12 @@ var Button = forwardRef(
2581
2582
  trailingElements
2582
2583
  ] });
2583
2584
  const safeHref = sanitizeHref(href);
2585
+ const Anchor = As ?? "a";
2584
2586
  const buttonEl = safeHref && !disabled ? (
2585
2587
  // Anchor mode forwards the same rest props as the <button> branch so
2586
2588
  // onClick / target / rel / ref / ARIA / data-* reach the <a> (issue #7).
2587
2589
  /* @__PURE__ */ jsx(
2588
- "a",
2590
+ Anchor,
2589
2591
  {
2590
2592
  ref,
2591
2593
  href: safeHref,
@@ -11654,11 +11656,10 @@ function ContentRenderer({
11654
11656
  );
11655
11657
  }
11656
11658
  ContentRenderer.displayName = "ContentRenderer";
11657
- function toHtml(value, outputFormat, unsafe) {
11659
+ function toHtml(value, outputFormat, unsafe, valueFormat = "auto") {
11658
11660
  if (!value) return "";
11659
11661
  const raw = (() => {
11660
- if (outputFormat === "html") return value;
11661
- const format = detectFormat(value);
11662
+ const format = valueFormat !== "auto" ? valueFormat : outputFormat === "html" ? "html" : detectFormat(value);
11662
11663
  if (format === "html") return value;
11663
11664
  return marked.parse(value, { async: false }).trim();
11664
11665
  })();
@@ -11671,6 +11672,7 @@ function EditorRoot({
11671
11672
  defaultValue = "",
11672
11673
  onChange,
11673
11674
  outputFormat = "html",
11675
+ valueFormat = "auto",
11674
11676
  lineSpacing = 1.6,
11675
11677
  placeholder,
11676
11678
  mode: modeProp,
@@ -11682,13 +11684,13 @@ function EditorRoot({
11682
11684
  const mode = useFieldMode(modeProp);
11683
11685
  const isView = mode === "view";
11684
11686
  const initialHtml = useMemo(
11685
- () => toHtml(value, outputFormat, unsafe),
11687
+ () => toHtml(value, outputFormat, unsafe, valueFormat),
11686
11688
  // Seed the contentEditable from the LIVE value when (re)entering edit mode.
11687
11689
  // EditorContent reads this once on mount, and it only mounts in edit mode —
11688
11690
  // so this captures the current value on view→edit, not a stale mount snapshot,
11689
11691
  // and does NOT re-run on every keystroke.
11690
11692
  // eslint-disable-next-line react-hooks/exhaustive-deps
11691
- [isView, outputFormat, unsafe]
11693
+ [isView, outputFormat, unsafe, valueFormat]
11692
11694
  );
11693
11695
  const extensions = useMemo(
11694
11696
  () => mergeExtensions(instanceExtensions),
@@ -11765,7 +11767,7 @@ function EditorRoot({
11765
11767
  ContentRenderer,
11766
11768
  {
11767
11769
  value,
11768
- format: outputFormat,
11770
+ format: valueFormat !== "auto" ? valueFormat : outputFormat,
11769
11771
  lineSpacing,
11770
11772
  extensions: instanceExtensions,
11771
11773
  unsafe,