@particle-academy/react-fancy 2.4.0 → 2.5.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
@@ -1615,6 +1615,14 @@ interface EditorProps {
1615
1615
  placeholder?: string;
1616
1616
  /** Per-instance render extensions. Merged with any globally-registered extensions. */
1617
1617
  extensions?: RenderExtension[];
1618
+ /**
1619
+ * Skip HTML sanitization of the initial value. By default the initial markdown/HTML
1620
+ * is sanitized to remove `<script>`, `<iframe>`, event handlers, and `javascript:`
1621
+ * URIs before being placed into contentEditable. Pass `unsafe` only when the
1622
+ * initial value is fully trusted.
1623
+ * @default false
1624
+ */
1625
+ unsafe?: boolean;
1618
1626
  }
1619
1627
 
1620
1628
  declare function EditorToolbar({ actions, onAction, children, className, }: EditorToolbarProps): react_jsx_runtime.JSX.Element;
@@ -1632,7 +1640,7 @@ declare namespace EditorContent {
1632
1640
  var displayName: string;
1633
1641
  }
1634
1642
 
1635
- declare function EditorRoot({ children, className, value: controlledValue, defaultValue, onChange, outputFormat, lineSpacing, placeholder, extensions: instanceExtensions, }: EditorProps): react_jsx_runtime.JSX.Element;
1643
+ declare function EditorRoot({ children, className, value: controlledValue, defaultValue, onChange, outputFormat, lineSpacing, placeholder, extensions: instanceExtensions, unsafe, }: EditorProps): react_jsx_runtime.JSX.Element;
1636
1644
  declare const Editor: typeof EditorRoot & {
1637
1645
  Toolbar: typeof EditorToolbar & {
1638
1646
  Separator: typeof EditorToolbarSeparator;
@@ -1664,9 +1672,17 @@ interface ContentRendererProps {
1664
1672
  className?: string;
1665
1673
  /** Per-instance render extensions. Merged with any globally-registered extensions. */
1666
1674
  extensions?: RenderExtension[];
1675
+ /**
1676
+ * Skip HTML sanitization. By default, rendered output is sanitized to remove
1677
+ * `<script>`, `<iframe>`, event handlers, and `javascript:` URIs. Pass
1678
+ * `unsafe` only when the input is fully trusted (e.g. server-rendered
1679
+ * markdown from your own CMS).
1680
+ * @default false
1681
+ */
1682
+ unsafe?: boolean;
1667
1683
  }
1668
1684
 
1669
- declare function ContentRenderer({ value, format, lineSpacing, className, extensions: instanceExtensions, }: ContentRendererProps): react_jsx_runtime.JSX.Element;
1685
+ declare function ContentRenderer({ value, format, lineSpacing, className, extensions: instanceExtensions, unsafe, }: ContentRendererProps): react_jsx_runtime.JSX.Element;
1670
1686
  declare namespace ContentRenderer {
1671
1687
  var displayName: string;
1672
1688
  }
@@ -2243,6 +2259,35 @@ declare function useTreeNav(): TreeNavContextValue;
2243
2259
 
2244
2260
  declare function cn(...inputs: ClassValue[]): string;
2245
2261
 
2262
+ /**
2263
+ * HTML and URL sanitization utilities.
2264
+ *
2265
+ * Hand-rolled (no third-party deps) using browser-native `DOMParser`. Designed
2266
+ * for the trust model "consumer passes user-generated markdown/HTML to a
2267
+ * react-fancy component" — strips script tags, event handlers, and dangerous
2268
+ * URI schemes from `href`/`src` attributes.
2269
+ *
2270
+ * For server-side rendering (no `window`), `sanitizeHtml` returns the input
2271
+ * unchanged. Consumers SSR-rendering untrusted content should sanitize on the
2272
+ * server with their own pipeline.
2273
+ */
2274
+ /**
2275
+ * Validate a URL/href against an allow-list of safe protocols. Returns the
2276
+ * input if safe, or `undefined` if it begins with a dangerous scheme like
2277
+ * `javascript:`, `data:`, or `vbscript:`. Relative URLs and fragment links
2278
+ * are allowed.
2279
+ */
2280
+ declare function sanitizeHref(href: string | undefined | null): string | undefined;
2281
+ /**
2282
+ * Sanitize an HTML string by removing dangerous tags (script, iframe, etc.),
2283
+ * event-handler attributes (`onclick`, `onerror`, ...), and dangerous URI
2284
+ * schemes in `href`/`src` attributes.
2285
+ *
2286
+ * Uses the browser's `DOMParser`. In non-browser environments returns the
2287
+ * input unchanged — sanitize on the server in those cases.
2288
+ */
2289
+ declare function sanitizeHtml(html: string): string;
2290
+
2246
2291
  declare function useControllableState<T>(controlledValue: T | undefined, defaultValue: T, onChange?: (value: T) => void): [T, (value: T | ((prev: T) => T)) => void];
2247
2292
 
2248
2293
  declare function useOutsideClick(ref: RefObject<HTMLElement | null>, handler: (event: MouseEvent | TouchEvent) => void, enabled?: boolean, ignoreRef?: RefObject<HTMLElement | null>): void;
@@ -2277,4 +2322,4 @@ declare function useAnimation({ open, enterClass, exitClass, }: UseAnimationOpti
2277
2322
 
2278
2323
  declare function useId(prefix?: string): string;
2279
2324
 
2280
- export { Accordion, type AccordionContentProps, type AccordionContextValue, type AccordionItemProps, type AccordionProps, type AccordionTriggerProps, Action, type ActionColor, type ActionProps, type AffixPosition, Autocomplete, type AutocompleteOption, type AutocompleteProps, Avatar, type AvatarProps, Badge, type BadgeProps, Brand, type BrandProps, Breadcrumbs, type BreadcrumbsItemProps, type BreadcrumbsProps, Calendar, type CalendarMode, type CalendarProps, Callout, type CalloutProps, Canvas, type CanvasContextValue, type CanvasControlsProps, type CanvasEdgeProps, type CanvasMinimapProps, type CanvasNodeProps, type CanvasProps, Card, type CardBodyProps, type CardFooterProps, type CardHeaderProps, type CardProps, Carousel, type CarouselContextValue, type CarouselControlsProps, type CarouselPanelsProps, type CarouselProps, type CarouselSlideProps, type CarouselStepsProps, type CarouselVariant, Chart, type ChartAreaProps, type ChartBarData, type ChartBarProps, type ChartCommonProps, type ChartDonutData, type ChartDonutProps, type ChartHorizontalBarProps, type ChartLineProps, type ChartPieData, type ChartPieProps, type ChartSeries, type ChartSparklineProps, type ChartStackedBarProps, Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps, type Color, ColorPicker, type ColorPickerProps, Command, type CommandContextValue, type CommandEmptyProps, type CommandGroupProps, type CommandInputProps, type CommandItemProps, type CommandListProps, type CommandProps, Composer, type ComposerProps, ContentRenderer, type ContentRendererProps, ContextMenu, type ContextMenuContentProps, type ContextMenuContextValue, type ContextMenuItemProps, type ContextMenuProps, type ContextMenuSeparatorProps, type ContextMenuTriggerProps, DatePicker, type DatePickerProps, type DateRange, Diagram, type DiagramContextValue, type DiagramEntityData, type DiagramEntityProps, type DiagramFieldData, type DiagramFieldProps, type DiagramProps, type DiagramRelationData, type DiagramRelationProps, type DiagramSchema, type DiagramToolbarProps, type DiagramType, type DropPosition, Dropdown, type DropdownContextValue, type DropdownItemProps, type DropdownItemsProps, type DropdownProps, type DropdownSeparatorProps, type DropdownTriggerProps, EMOJI_CATEGORY_ORDER, EMOJI_DATA, EMOJI_ENTRIES, type EdgeAnchor, Editor, type EditorAction, type EditorContentProps, type EditorContextValue, type EditorProps, type EditorToolbarProps, Emoji, type EmojiCategory, type EmojiCategoryKey, type EmojiEntry, type EmojiFlatEntry, type EmojiProps, EmojiSelect, type EmojiSelectProps, type ExportFormat, Field, type FieldProps, FileUpload, type FileUploadContextValue, type FileUploadDropzoneProps, type FileUploadListProps, type FileUploadProps, Heading, type HeadingProps, Icon, type IconProps, type IconSet, Input, type InputAffixProps, type InputBaseProps, type InputOption, type InputOptionGroup, type InputProps, Kanban, type KanbanCardProps, type KanbanColumnProps, type KanbanContextValue, type KanbanProps, Menu, type MenuContextValue, type MenuGroupProps, type MenuItemProps, type MenuOrientation, type MenuProps, type MenuSubmenuProps, MobileMenu, type MobileMenuBottomBarProps, type MobileMenuContextValue, type MobileMenuFlyoutProps, type MobileMenuItemProps, type MobileMenuSide, type MobileMenuVariant, Modal, type ModalBodyProps, type ModalContextValue, type ModalFooterProps, type ModalHeaderProps, type ModalProps, MultiSwitch, type MultiSwitchProps, Navbar, type NavbarBrandProps, type NavbarContextValue, type NavbarItemProps, type NavbarItemsProps, type NavbarProps, type NavbarToggleProps, type NodeRect, OtpInput, type OtpInputProps, Pagination, type PaginationProps, Pillbox, type PillboxProps, type Placement, Popover, type PopoverContentProps, type PopoverContextValue, type PopoverProps, type PopoverTriggerProps, Portal, type PortalProps, Profile, type ProfileProps, Progress, type ProgressProps, RadioGroup, type RadioGroupProps, type RelationType, type RenderExtension, type RenderExtensionProps, SKIN_TONES, Select, type SelectProps, Separator, type SeparatorProps, Sidebar, type SidebarCollapseMode, type SidebarContextValue, type SidebarGroupProps, type SidebarItemProps, type SidebarProps, type SidebarSubmenuProps, type SidebarToggleProps, type Size, Skeleton, type SkeletonProps, type SkinTone, Slider, type SliderProps, Switch, type SwitchProps, Table, type TableBodyProps, type TableCellProps, type TableColumnProps, type TableHeadProps, type TablePaginationProps, type TableProps, type TableRowProps, type TableRowTrayProps, type TableSearchProps, type TableTrayProps, Tabs, type TabsContextValue, type TabsListProps, type TabsPanelProps, type TabsPanelsProps, type TabsProps, type TabsTabProps, type TabsVariant, Text, type TextProps, Textarea, type TextareaProps, TimePicker, type TimePickerProps, Timeline, type TimelineBlockProps, type TimelineEvent, type TimelineItemProps, type TimelineOrientation, type TimelineProps, type TimelineVariant, Toast, type ToastContextValue, type ToastData, type ToastPosition, type ToastProviderProps, type ToastVariant, Tooltip, type TooltipProps, TreeNav, type TreeNavContextValue, type TreeNavProps, type TreeNodeData, type TreeNodeProps, type Variant, type ViewportState, applyTone, cn, configureIcons, find, hasSkinTones, registerExtension, registerExtensions, registerIconSet, registerIcons, resolve, search, skinTones, useAccordion, useAnimation, useCanvas, useCarousel, useCommand, useContextMenu, useControllableState, useDiagram, useDropdown, useEditor, useEscapeKey, useFileUpload, useFloatingPosition, useFocusTrap, useId, useKanban, useMenu, useMobileMenu, useModal, useNavbar, useNodeRegistry, useOutsideClick, usePanZoom, usePopover, useSidebar, useTabs, useToast, useTreeNav };
2325
+ export { Accordion, type AccordionContentProps, type AccordionContextValue, type AccordionItemProps, type AccordionProps, type AccordionTriggerProps, Action, type ActionColor, type ActionProps, type AffixPosition, Autocomplete, type AutocompleteOption, type AutocompleteProps, Avatar, type AvatarProps, Badge, type BadgeProps, Brand, type BrandProps, Breadcrumbs, type BreadcrumbsItemProps, type BreadcrumbsProps, Calendar, type CalendarMode, type CalendarProps, Callout, type CalloutProps, Canvas, type CanvasContextValue, type CanvasControlsProps, type CanvasEdgeProps, type CanvasMinimapProps, type CanvasNodeProps, type CanvasProps, Card, type CardBodyProps, type CardFooterProps, type CardHeaderProps, type CardProps, Carousel, type CarouselContextValue, type CarouselControlsProps, type CarouselPanelsProps, type CarouselProps, type CarouselSlideProps, type CarouselStepsProps, type CarouselVariant, Chart, type ChartAreaProps, type ChartBarData, type ChartBarProps, type ChartCommonProps, type ChartDonutData, type ChartDonutProps, type ChartHorizontalBarProps, type ChartLineProps, type ChartPieData, type ChartPieProps, type ChartSeries, type ChartSparklineProps, type ChartStackedBarProps, Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps, type Color, ColorPicker, type ColorPickerProps, Command, type CommandContextValue, type CommandEmptyProps, type CommandGroupProps, type CommandInputProps, type CommandItemProps, type CommandListProps, type CommandProps, Composer, type ComposerProps, ContentRenderer, type ContentRendererProps, ContextMenu, type ContextMenuContentProps, type ContextMenuContextValue, type ContextMenuItemProps, type ContextMenuProps, type ContextMenuSeparatorProps, type ContextMenuTriggerProps, DatePicker, type DatePickerProps, type DateRange, Diagram, type DiagramContextValue, type DiagramEntityData, type DiagramEntityProps, type DiagramFieldData, type DiagramFieldProps, type DiagramProps, type DiagramRelationData, type DiagramRelationProps, type DiagramSchema, type DiagramToolbarProps, type DiagramType, type DropPosition, Dropdown, type DropdownContextValue, type DropdownItemProps, type DropdownItemsProps, type DropdownProps, type DropdownSeparatorProps, type DropdownTriggerProps, EMOJI_CATEGORY_ORDER, EMOJI_DATA, EMOJI_ENTRIES, type EdgeAnchor, Editor, type EditorAction, type EditorContentProps, type EditorContextValue, type EditorProps, type EditorToolbarProps, Emoji, type EmojiCategory, type EmojiCategoryKey, type EmojiEntry, type EmojiFlatEntry, type EmojiProps, EmojiSelect, type EmojiSelectProps, type ExportFormat, Field, type FieldProps, FileUpload, type FileUploadContextValue, type FileUploadDropzoneProps, type FileUploadListProps, type FileUploadProps, Heading, type HeadingProps, Icon, type IconProps, type IconSet, Input, type InputAffixProps, type InputBaseProps, type InputOption, type InputOptionGroup, type InputProps, Kanban, type KanbanCardProps, type KanbanColumnProps, type KanbanContextValue, type KanbanProps, Menu, type MenuContextValue, type MenuGroupProps, type MenuItemProps, type MenuOrientation, type MenuProps, type MenuSubmenuProps, MobileMenu, type MobileMenuBottomBarProps, type MobileMenuContextValue, type MobileMenuFlyoutProps, type MobileMenuItemProps, type MobileMenuSide, type MobileMenuVariant, Modal, type ModalBodyProps, type ModalContextValue, type ModalFooterProps, type ModalHeaderProps, type ModalProps, MultiSwitch, type MultiSwitchProps, Navbar, type NavbarBrandProps, type NavbarContextValue, type NavbarItemProps, type NavbarItemsProps, type NavbarProps, type NavbarToggleProps, type NodeRect, OtpInput, type OtpInputProps, Pagination, type PaginationProps, Pillbox, type PillboxProps, type Placement, Popover, type PopoverContentProps, type PopoverContextValue, type PopoverProps, type PopoverTriggerProps, Portal, type PortalProps, Profile, type ProfileProps, Progress, type ProgressProps, RadioGroup, type RadioGroupProps, type RelationType, type RenderExtension, type RenderExtensionProps, SKIN_TONES, Select, type SelectProps, Separator, type SeparatorProps, Sidebar, type SidebarCollapseMode, type SidebarContextValue, type SidebarGroupProps, type SidebarItemProps, type SidebarProps, type SidebarSubmenuProps, type SidebarToggleProps, type Size, Skeleton, type SkeletonProps, type SkinTone, Slider, type SliderProps, Switch, type SwitchProps, Table, type TableBodyProps, type TableCellProps, type TableColumnProps, type TableHeadProps, type TablePaginationProps, type TableProps, type TableRowProps, type TableRowTrayProps, type TableSearchProps, type TableTrayProps, Tabs, type TabsContextValue, type TabsListProps, type TabsPanelProps, type TabsPanelsProps, type TabsProps, type TabsTabProps, type TabsVariant, Text, type TextProps, Textarea, type TextareaProps, TimePicker, type TimePickerProps, Timeline, type TimelineBlockProps, type TimelineEvent, type TimelineItemProps, type TimelineOrientation, type TimelineProps, type TimelineVariant, Toast, type ToastContextValue, type ToastData, type ToastPosition, type ToastProviderProps, type ToastVariant, Tooltip, type TooltipProps, TreeNav, type TreeNavContextValue, type TreeNavProps, type TreeNodeData, type TreeNodeProps, type Variant, type ViewportState, applyTone, cn, configureIcons, find, hasSkinTones, registerExtension, registerExtensions, registerIconSet, registerIcons, resolve, sanitizeHref, sanitizeHtml, search, skinTones, useAccordion, useAnimation, useCanvas, useCarousel, useCommand, useContextMenu, useControllableState, useDiagram, useDropdown, useEditor, useEscapeKey, useFileUpload, useFloatingPosition, useFocusTrap, useId, useKanban, useMenu, useMobileMenu, useModal, useNavbar, useNodeRegistry, useOutsideClick, usePanZoom, usePopover, useSidebar, useTabs, useToast, useTreeNav };
package/dist/index.d.ts CHANGED
@@ -1615,6 +1615,14 @@ interface EditorProps {
1615
1615
  placeholder?: string;
1616
1616
  /** Per-instance render extensions. Merged with any globally-registered extensions. */
1617
1617
  extensions?: RenderExtension[];
1618
+ /**
1619
+ * Skip HTML sanitization of the initial value. By default the initial markdown/HTML
1620
+ * is sanitized to remove `<script>`, `<iframe>`, event handlers, and `javascript:`
1621
+ * URIs before being placed into contentEditable. Pass `unsafe` only when the
1622
+ * initial value is fully trusted.
1623
+ * @default false
1624
+ */
1625
+ unsafe?: boolean;
1618
1626
  }
1619
1627
 
1620
1628
  declare function EditorToolbar({ actions, onAction, children, className, }: EditorToolbarProps): react_jsx_runtime.JSX.Element;
@@ -1632,7 +1640,7 @@ declare namespace EditorContent {
1632
1640
  var displayName: string;
1633
1641
  }
1634
1642
 
1635
- declare function EditorRoot({ children, className, value: controlledValue, defaultValue, onChange, outputFormat, lineSpacing, placeholder, extensions: instanceExtensions, }: EditorProps): react_jsx_runtime.JSX.Element;
1643
+ declare function EditorRoot({ children, className, value: controlledValue, defaultValue, onChange, outputFormat, lineSpacing, placeholder, extensions: instanceExtensions, unsafe, }: EditorProps): react_jsx_runtime.JSX.Element;
1636
1644
  declare const Editor: typeof EditorRoot & {
1637
1645
  Toolbar: typeof EditorToolbar & {
1638
1646
  Separator: typeof EditorToolbarSeparator;
@@ -1664,9 +1672,17 @@ interface ContentRendererProps {
1664
1672
  className?: string;
1665
1673
  /** Per-instance render extensions. Merged with any globally-registered extensions. */
1666
1674
  extensions?: RenderExtension[];
1675
+ /**
1676
+ * Skip HTML sanitization. By default, rendered output is sanitized to remove
1677
+ * `<script>`, `<iframe>`, event handlers, and `javascript:` URIs. Pass
1678
+ * `unsafe` only when the input is fully trusted (e.g. server-rendered
1679
+ * markdown from your own CMS).
1680
+ * @default false
1681
+ */
1682
+ unsafe?: boolean;
1667
1683
  }
1668
1684
 
1669
- declare function ContentRenderer({ value, format, lineSpacing, className, extensions: instanceExtensions, }: ContentRendererProps): react_jsx_runtime.JSX.Element;
1685
+ declare function ContentRenderer({ value, format, lineSpacing, className, extensions: instanceExtensions, unsafe, }: ContentRendererProps): react_jsx_runtime.JSX.Element;
1670
1686
  declare namespace ContentRenderer {
1671
1687
  var displayName: string;
1672
1688
  }
@@ -2243,6 +2259,35 @@ declare function useTreeNav(): TreeNavContextValue;
2243
2259
 
2244
2260
  declare function cn(...inputs: ClassValue[]): string;
2245
2261
 
2262
+ /**
2263
+ * HTML and URL sanitization utilities.
2264
+ *
2265
+ * Hand-rolled (no third-party deps) using browser-native `DOMParser`. Designed
2266
+ * for the trust model "consumer passes user-generated markdown/HTML to a
2267
+ * react-fancy component" — strips script tags, event handlers, and dangerous
2268
+ * URI schemes from `href`/`src` attributes.
2269
+ *
2270
+ * For server-side rendering (no `window`), `sanitizeHtml` returns the input
2271
+ * unchanged. Consumers SSR-rendering untrusted content should sanitize on the
2272
+ * server with their own pipeline.
2273
+ */
2274
+ /**
2275
+ * Validate a URL/href against an allow-list of safe protocols. Returns the
2276
+ * input if safe, or `undefined` if it begins with a dangerous scheme like
2277
+ * `javascript:`, `data:`, or `vbscript:`. Relative URLs and fragment links
2278
+ * are allowed.
2279
+ */
2280
+ declare function sanitizeHref(href: string | undefined | null): string | undefined;
2281
+ /**
2282
+ * Sanitize an HTML string by removing dangerous tags (script, iframe, etc.),
2283
+ * event-handler attributes (`onclick`, `onerror`, ...), and dangerous URI
2284
+ * schemes in `href`/`src` attributes.
2285
+ *
2286
+ * Uses the browser's `DOMParser`. In non-browser environments returns the
2287
+ * input unchanged — sanitize on the server in those cases.
2288
+ */
2289
+ declare function sanitizeHtml(html: string): string;
2290
+
2246
2291
  declare function useControllableState<T>(controlledValue: T | undefined, defaultValue: T, onChange?: (value: T) => void): [T, (value: T | ((prev: T) => T)) => void];
2247
2292
 
2248
2293
  declare function useOutsideClick(ref: RefObject<HTMLElement | null>, handler: (event: MouseEvent | TouchEvent) => void, enabled?: boolean, ignoreRef?: RefObject<HTMLElement | null>): void;
@@ -2277,4 +2322,4 @@ declare function useAnimation({ open, enterClass, exitClass, }: UseAnimationOpti
2277
2322
 
2278
2323
  declare function useId(prefix?: string): string;
2279
2324
 
2280
- export { Accordion, type AccordionContentProps, type AccordionContextValue, type AccordionItemProps, type AccordionProps, type AccordionTriggerProps, Action, type ActionColor, type ActionProps, type AffixPosition, Autocomplete, type AutocompleteOption, type AutocompleteProps, Avatar, type AvatarProps, Badge, type BadgeProps, Brand, type BrandProps, Breadcrumbs, type BreadcrumbsItemProps, type BreadcrumbsProps, Calendar, type CalendarMode, type CalendarProps, Callout, type CalloutProps, Canvas, type CanvasContextValue, type CanvasControlsProps, type CanvasEdgeProps, type CanvasMinimapProps, type CanvasNodeProps, type CanvasProps, Card, type CardBodyProps, type CardFooterProps, type CardHeaderProps, type CardProps, Carousel, type CarouselContextValue, type CarouselControlsProps, type CarouselPanelsProps, type CarouselProps, type CarouselSlideProps, type CarouselStepsProps, type CarouselVariant, Chart, type ChartAreaProps, type ChartBarData, type ChartBarProps, type ChartCommonProps, type ChartDonutData, type ChartDonutProps, type ChartHorizontalBarProps, type ChartLineProps, type ChartPieData, type ChartPieProps, type ChartSeries, type ChartSparklineProps, type ChartStackedBarProps, Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps, type Color, ColorPicker, type ColorPickerProps, Command, type CommandContextValue, type CommandEmptyProps, type CommandGroupProps, type CommandInputProps, type CommandItemProps, type CommandListProps, type CommandProps, Composer, type ComposerProps, ContentRenderer, type ContentRendererProps, ContextMenu, type ContextMenuContentProps, type ContextMenuContextValue, type ContextMenuItemProps, type ContextMenuProps, type ContextMenuSeparatorProps, type ContextMenuTriggerProps, DatePicker, type DatePickerProps, type DateRange, Diagram, type DiagramContextValue, type DiagramEntityData, type DiagramEntityProps, type DiagramFieldData, type DiagramFieldProps, type DiagramProps, type DiagramRelationData, type DiagramRelationProps, type DiagramSchema, type DiagramToolbarProps, type DiagramType, type DropPosition, Dropdown, type DropdownContextValue, type DropdownItemProps, type DropdownItemsProps, type DropdownProps, type DropdownSeparatorProps, type DropdownTriggerProps, EMOJI_CATEGORY_ORDER, EMOJI_DATA, EMOJI_ENTRIES, type EdgeAnchor, Editor, type EditorAction, type EditorContentProps, type EditorContextValue, type EditorProps, type EditorToolbarProps, Emoji, type EmojiCategory, type EmojiCategoryKey, type EmojiEntry, type EmojiFlatEntry, type EmojiProps, EmojiSelect, type EmojiSelectProps, type ExportFormat, Field, type FieldProps, FileUpload, type FileUploadContextValue, type FileUploadDropzoneProps, type FileUploadListProps, type FileUploadProps, Heading, type HeadingProps, Icon, type IconProps, type IconSet, Input, type InputAffixProps, type InputBaseProps, type InputOption, type InputOptionGroup, type InputProps, Kanban, type KanbanCardProps, type KanbanColumnProps, type KanbanContextValue, type KanbanProps, Menu, type MenuContextValue, type MenuGroupProps, type MenuItemProps, type MenuOrientation, type MenuProps, type MenuSubmenuProps, MobileMenu, type MobileMenuBottomBarProps, type MobileMenuContextValue, type MobileMenuFlyoutProps, type MobileMenuItemProps, type MobileMenuSide, type MobileMenuVariant, Modal, type ModalBodyProps, type ModalContextValue, type ModalFooterProps, type ModalHeaderProps, type ModalProps, MultiSwitch, type MultiSwitchProps, Navbar, type NavbarBrandProps, type NavbarContextValue, type NavbarItemProps, type NavbarItemsProps, type NavbarProps, type NavbarToggleProps, type NodeRect, OtpInput, type OtpInputProps, Pagination, type PaginationProps, Pillbox, type PillboxProps, type Placement, Popover, type PopoverContentProps, type PopoverContextValue, type PopoverProps, type PopoverTriggerProps, Portal, type PortalProps, Profile, type ProfileProps, Progress, type ProgressProps, RadioGroup, type RadioGroupProps, type RelationType, type RenderExtension, type RenderExtensionProps, SKIN_TONES, Select, type SelectProps, Separator, type SeparatorProps, Sidebar, type SidebarCollapseMode, type SidebarContextValue, type SidebarGroupProps, type SidebarItemProps, type SidebarProps, type SidebarSubmenuProps, type SidebarToggleProps, type Size, Skeleton, type SkeletonProps, type SkinTone, Slider, type SliderProps, Switch, type SwitchProps, Table, type TableBodyProps, type TableCellProps, type TableColumnProps, type TableHeadProps, type TablePaginationProps, type TableProps, type TableRowProps, type TableRowTrayProps, type TableSearchProps, type TableTrayProps, Tabs, type TabsContextValue, type TabsListProps, type TabsPanelProps, type TabsPanelsProps, type TabsProps, type TabsTabProps, type TabsVariant, Text, type TextProps, Textarea, type TextareaProps, TimePicker, type TimePickerProps, Timeline, type TimelineBlockProps, type TimelineEvent, type TimelineItemProps, type TimelineOrientation, type TimelineProps, type TimelineVariant, Toast, type ToastContextValue, type ToastData, type ToastPosition, type ToastProviderProps, type ToastVariant, Tooltip, type TooltipProps, TreeNav, type TreeNavContextValue, type TreeNavProps, type TreeNodeData, type TreeNodeProps, type Variant, type ViewportState, applyTone, cn, configureIcons, find, hasSkinTones, registerExtension, registerExtensions, registerIconSet, registerIcons, resolve, search, skinTones, useAccordion, useAnimation, useCanvas, useCarousel, useCommand, useContextMenu, useControllableState, useDiagram, useDropdown, useEditor, useEscapeKey, useFileUpload, useFloatingPosition, useFocusTrap, useId, useKanban, useMenu, useMobileMenu, useModal, useNavbar, useNodeRegistry, useOutsideClick, usePanZoom, usePopover, useSidebar, useTabs, useToast, useTreeNav };
2325
+ export { Accordion, type AccordionContentProps, type AccordionContextValue, type AccordionItemProps, type AccordionProps, type AccordionTriggerProps, Action, type ActionColor, type ActionProps, type AffixPosition, Autocomplete, type AutocompleteOption, type AutocompleteProps, Avatar, type AvatarProps, Badge, type BadgeProps, Brand, type BrandProps, Breadcrumbs, type BreadcrumbsItemProps, type BreadcrumbsProps, Calendar, type CalendarMode, type CalendarProps, Callout, type CalloutProps, Canvas, type CanvasContextValue, type CanvasControlsProps, type CanvasEdgeProps, type CanvasMinimapProps, type CanvasNodeProps, type CanvasProps, Card, type CardBodyProps, type CardFooterProps, type CardHeaderProps, type CardProps, Carousel, type CarouselContextValue, type CarouselControlsProps, type CarouselPanelsProps, type CarouselProps, type CarouselSlideProps, type CarouselStepsProps, type CarouselVariant, Chart, type ChartAreaProps, type ChartBarData, type ChartBarProps, type ChartCommonProps, type ChartDonutData, type ChartDonutProps, type ChartHorizontalBarProps, type ChartLineProps, type ChartPieData, type ChartPieProps, type ChartSeries, type ChartSparklineProps, type ChartStackedBarProps, Checkbox, CheckboxGroup, type CheckboxGroupProps, type CheckboxProps, type Color, ColorPicker, type ColorPickerProps, Command, type CommandContextValue, type CommandEmptyProps, type CommandGroupProps, type CommandInputProps, type CommandItemProps, type CommandListProps, type CommandProps, Composer, type ComposerProps, ContentRenderer, type ContentRendererProps, ContextMenu, type ContextMenuContentProps, type ContextMenuContextValue, type ContextMenuItemProps, type ContextMenuProps, type ContextMenuSeparatorProps, type ContextMenuTriggerProps, DatePicker, type DatePickerProps, type DateRange, Diagram, type DiagramContextValue, type DiagramEntityData, type DiagramEntityProps, type DiagramFieldData, type DiagramFieldProps, type DiagramProps, type DiagramRelationData, type DiagramRelationProps, type DiagramSchema, type DiagramToolbarProps, type DiagramType, type DropPosition, Dropdown, type DropdownContextValue, type DropdownItemProps, type DropdownItemsProps, type DropdownProps, type DropdownSeparatorProps, type DropdownTriggerProps, EMOJI_CATEGORY_ORDER, EMOJI_DATA, EMOJI_ENTRIES, type EdgeAnchor, Editor, type EditorAction, type EditorContentProps, type EditorContextValue, type EditorProps, type EditorToolbarProps, Emoji, type EmojiCategory, type EmojiCategoryKey, type EmojiEntry, type EmojiFlatEntry, type EmojiProps, EmojiSelect, type EmojiSelectProps, type ExportFormat, Field, type FieldProps, FileUpload, type FileUploadContextValue, type FileUploadDropzoneProps, type FileUploadListProps, type FileUploadProps, Heading, type HeadingProps, Icon, type IconProps, type IconSet, Input, type InputAffixProps, type InputBaseProps, type InputOption, type InputOptionGroup, type InputProps, Kanban, type KanbanCardProps, type KanbanColumnProps, type KanbanContextValue, type KanbanProps, Menu, type MenuContextValue, type MenuGroupProps, type MenuItemProps, type MenuOrientation, type MenuProps, type MenuSubmenuProps, MobileMenu, type MobileMenuBottomBarProps, type MobileMenuContextValue, type MobileMenuFlyoutProps, type MobileMenuItemProps, type MobileMenuSide, type MobileMenuVariant, Modal, type ModalBodyProps, type ModalContextValue, type ModalFooterProps, type ModalHeaderProps, type ModalProps, MultiSwitch, type MultiSwitchProps, Navbar, type NavbarBrandProps, type NavbarContextValue, type NavbarItemProps, type NavbarItemsProps, type NavbarProps, type NavbarToggleProps, type NodeRect, OtpInput, type OtpInputProps, Pagination, type PaginationProps, Pillbox, type PillboxProps, type Placement, Popover, type PopoverContentProps, type PopoverContextValue, type PopoverProps, type PopoverTriggerProps, Portal, type PortalProps, Profile, type ProfileProps, Progress, type ProgressProps, RadioGroup, type RadioGroupProps, type RelationType, type RenderExtension, type RenderExtensionProps, SKIN_TONES, Select, type SelectProps, Separator, type SeparatorProps, Sidebar, type SidebarCollapseMode, type SidebarContextValue, type SidebarGroupProps, type SidebarItemProps, type SidebarProps, type SidebarSubmenuProps, type SidebarToggleProps, type Size, Skeleton, type SkeletonProps, type SkinTone, Slider, type SliderProps, Switch, type SwitchProps, Table, type TableBodyProps, type TableCellProps, type TableColumnProps, type TableHeadProps, type TablePaginationProps, type TableProps, type TableRowProps, type TableRowTrayProps, type TableSearchProps, type TableTrayProps, Tabs, type TabsContextValue, type TabsListProps, type TabsPanelProps, type TabsPanelsProps, type TabsProps, type TabsTabProps, type TabsVariant, Text, type TextProps, Textarea, type TextareaProps, TimePicker, type TimePickerProps, Timeline, type TimelineBlockProps, type TimelineEvent, type TimelineItemProps, type TimelineOrientation, type TimelineProps, type TimelineVariant, Toast, type ToastContextValue, type ToastData, type ToastPosition, type ToastProviderProps, type ToastVariant, Tooltip, type TooltipProps, TreeNav, type TreeNavContextValue, type TreeNavProps, type TreeNodeData, type TreeNodeProps, type Variant, type ViewportState, applyTone, cn, configureIcons, find, hasSkinTones, registerExtension, registerExtensions, registerIconSet, registerIcons, resolve, sanitizeHref, sanitizeHtml, search, skinTones, useAccordion, useAnimation, useCanvas, useCarousel, useCommand, useContextMenu, useControllableState, useDiagram, useDropdown, useEditor, useEscapeKey, useFileUpload, useFloatingPosition, useFocusTrap, useId, useKanban, useMenu, useMobileMenu, useModal, useNavbar, useNodeRegistry, useOutsideClick, usePanZoom, usePopover, useSidebar, useTabs, useToast, useTreeNav };
package/dist/index.js CHANGED
@@ -12,6 +12,80 @@ function cn(...inputs) {
12
12
  return twMerge(clsx(inputs));
13
13
  }
14
14
 
15
+ // src/utils/sanitize.ts
16
+ var DANGEROUS_TAGS = /* @__PURE__ */ new Set([
17
+ "script",
18
+ "style",
19
+ "iframe",
20
+ "object",
21
+ "embed",
22
+ "link",
23
+ "meta",
24
+ "base",
25
+ "form"
26
+ ]);
27
+ var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "xlink:href"]);
28
+ var SAFE_PROTOCOL = /^(?:https?:|mailto:|tel:|sms:|ftp:|#|\/|\.\/|\.\.\/|[^:]*$)/i;
29
+ function sanitizeHref(href) {
30
+ if (href == null) return void 0;
31
+ const trimmed = href.trim();
32
+ if (!trimmed) return void 0;
33
+ return SAFE_PROTOCOL.test(trimmed) ? trimmed : void 0;
34
+ }
35
+ function stripDangerousAttrs(el) {
36
+ const names = [];
37
+ for (let i = 0; i < el.attributes.length; i++) {
38
+ names.push(el.attributes[i].name);
39
+ }
40
+ for (const name of names) {
41
+ const lower = name.toLowerCase();
42
+ if (lower.startsWith("on")) {
43
+ el.removeAttribute(name);
44
+ continue;
45
+ }
46
+ if (URL_ATTRS.has(lower)) {
47
+ const sanitized = sanitizeHref(el.getAttribute(name));
48
+ if (sanitized === void 0) {
49
+ el.removeAttribute(name);
50
+ } else {
51
+ el.setAttribute(name, sanitized);
52
+ }
53
+ continue;
54
+ }
55
+ if (lower === "srcdoc") {
56
+ el.removeAttribute(name);
57
+ }
58
+ }
59
+ }
60
+ function walk(el, removeQueue) {
61
+ const tag = el.tagName.toLowerCase();
62
+ if (DANGEROUS_TAGS.has(tag)) {
63
+ removeQueue.push(el);
64
+ return;
65
+ }
66
+ stripDangerousAttrs(el);
67
+ const children = Array.from(el.children);
68
+ for (const child of children) {
69
+ walk(child, removeQueue);
70
+ }
71
+ }
72
+ function sanitizeHtml(html) {
73
+ if (typeof window === "undefined" || typeof DOMParser === "undefined") {
74
+ return html;
75
+ }
76
+ const doc = new DOMParser().parseFromString(`<body>${html}</body>`, "text/html");
77
+ const body = doc.body;
78
+ if (!body) return html;
79
+ const removeQueue = [];
80
+ for (const child of Array.from(body.children)) {
81
+ walk(child, removeQueue);
82
+ }
83
+ for (const el of removeQueue) {
84
+ el.parentNode?.removeChild(el);
85
+ }
86
+ return body.innerHTML;
87
+ }
88
+
15
89
  // src/data/emoji-data.ts
16
90
  var EMOJI_CATEGORY_ORDER = [
17
91
  "smileys",
@@ -2411,7 +2485,8 @@ var Action = forwardRef(
2411
2485
  children != null && /* @__PURE__ */ jsx("span", { children }),
2412
2486
  trailingElements
2413
2487
  ] });
2414
- const buttonEl = href && !disabled ? /* @__PURE__ */ jsx("a", { href, className: classes, "data-react-fancy-action": "", children: content }) : /* @__PURE__ */ jsx(
2488
+ const safeHref = sanitizeHref(href);
2489
+ const buttonEl = safeHref && !disabled ? /* @__PURE__ */ jsx("a", { href: safeHref, className: classes, "data-react-fancy-action": "", children: content }) : /* @__PURE__ */ jsx(
2415
2490
  "button",
2416
2491
  {
2417
2492
  ref,
@@ -10077,13 +10152,15 @@ function mergeExtensions(instanceExtensions) {
10077
10152
  }
10078
10153
  return merged;
10079
10154
  }
10080
- function toHtml(value, outputFormat) {
10155
+ function toHtml(value, outputFormat, unsafe) {
10081
10156
  if (!value) return "";
10082
- if (outputFormat === "html") return value;
10083
- const format = detectFormat(value);
10084
- if (format === "html") return value;
10085
- const result = marked.parse(value, { async: false });
10086
- return result.trim();
10157
+ const raw = (() => {
10158
+ if (outputFormat === "html") return value;
10159
+ const format = detectFormat(value);
10160
+ if (format === "html") return value;
10161
+ return marked.parse(value, { async: false }).trim();
10162
+ })();
10163
+ return unsafe ? raw : sanitizeHtml(raw);
10087
10164
  }
10088
10165
  function EditorRoot({
10089
10166
  children,
@@ -10094,12 +10171,13 @@ function EditorRoot({
10094
10171
  outputFormat = "html",
10095
10172
  lineSpacing = 1.6,
10096
10173
  placeholder,
10097
- extensions: instanceExtensions
10174
+ extensions: instanceExtensions,
10175
+ unsafe = false
10098
10176
  }) {
10099
10177
  const contentRef = useRef(null);
10100
10178
  const [, setValue] = useControllableState(controlledValue, defaultValue, onChange);
10101
10179
  const initialHtml = useMemo(
10102
- () => toHtml(controlledValue ?? defaultValue, outputFormat),
10180
+ () => toHtml(controlledValue ?? defaultValue, outputFormat, unsafe),
10103
10181
  // Only compute once on mount — don't re-run when value changes from user input
10104
10182
  // eslint-disable-next-line react-hooks/exhaustive-deps
10105
10183
  []
@@ -10184,7 +10262,11 @@ var Editor = Object.assign(EditorRoot, {
10184
10262
  Toolbar: ToolbarWithSeparator,
10185
10263
  Content: EditorContent
10186
10264
  });
10187
- function RenderedContent({ html, extensions: instanceExtensions }) {
10265
+ function RenderedContent({
10266
+ html,
10267
+ extensions: instanceExtensions,
10268
+ unsafe = false
10269
+ }) {
10188
10270
  const extensions = useMemo(
10189
10271
  () => mergeExtensions(instanceExtensions),
10190
10272
  [instanceExtensions]
@@ -10193,15 +10275,16 @@ function RenderedContent({ html, extensions: instanceExtensions }) {
10193
10275
  () => parseSegments(html, extensions),
10194
10276
  [html, extensions]
10195
10277
  );
10278
+ const renderHtml = (content) => unsafe ? content : sanitizeHtml(content);
10196
10279
  if (segments.length === 1 && segments[0].type === "html") {
10197
- return /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: segments[0].content } });
10280
+ return /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: renderHtml(segments[0].content) } });
10198
10281
  }
10199
10282
  if (segments.length === 0) {
10200
10283
  return null;
10201
10284
  }
10202
10285
  return /* @__PURE__ */ jsx(Fragment, { children: segments.map((segment, i) => {
10203
10286
  if (segment.type === "html") {
10204
- return segment.content ? /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: segment.content } }, i) : null;
10287
+ return segment.content ? /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: renderHtml(segment.content) } }, i) : null;
10205
10288
  }
10206
10289
  const ext = extensions.find(
10207
10290
  (e) => e.tag.toLowerCase() === segment.tag
@@ -10219,7 +10302,8 @@ function ContentRenderer({
10219
10302
  format = "auto",
10220
10303
  lineSpacing = 1.6,
10221
10304
  className,
10222
- extensions: instanceExtensions
10305
+ extensions: instanceExtensions,
10306
+ unsafe = false
10223
10307
  }) {
10224
10308
  const extensions = useMemo(
10225
10309
  () => mergeExtensions(instanceExtensions),
@@ -10227,11 +10311,9 @@ function ContentRenderer({
10227
10311
  );
10228
10312
  const html = useMemo(() => {
10229
10313
  const resolvedFormat = format === "auto" ? detectFormat(value) : format;
10230
- if (resolvedFormat === "markdown") {
10231
- return marked.parse(value, { async: false });
10232
- }
10233
- return value;
10234
- }, [value, format]);
10314
+ const raw = resolvedFormat === "markdown" ? marked.parse(value, { async: false }) : value;
10315
+ return unsafe ? raw : sanitizeHtml(raw);
10316
+ }, [value, format, unsafe]);
10235
10317
  const hasExtensions = extensions.length > 0;
10236
10318
  return /* @__PURE__ */ jsx(
10237
10319
  "div",
@@ -10239,7 +10321,7 @@ function ContentRenderer({
10239
10321
  "data-react-fancy-content-renderer": "",
10240
10322
  style: { lineHeight: lineSpacing },
10241
10323
  className: cn("text-sm", proseClasses, className),
10242
- children: hasExtensions ? /* @__PURE__ */ jsx(RenderedContent, { html, extensions }) : /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: html } })
10324
+ children: hasExtensions ? /* @__PURE__ */ jsx(RenderedContent, { html, extensions, unsafe }) : /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: html } })
10243
10325
  }
10244
10326
  );
10245
10327
  }
@@ -12181,6 +12263,6 @@ var TreeNav = Object.assign(TreeNavRoot, {
12181
12263
  Node: TreeNode
12182
12264
  });
12183
12265
 
12184
- export { Accordion, Action, Autocomplete, Avatar, Badge, Brand, Breadcrumbs, Calendar, Callout, Canvas, Card, Carousel, Chart, Checkbox, CheckboxGroup, ColorPicker, Command, Composer, ContentRenderer, ContextMenu, DatePicker, Diagram, Dropdown, EMOJI_CATEGORY_ORDER, EMOJI_DATA, EMOJI_ENTRIES, Editor, Emoji, EmojiSelect, Field, FileUpload, Heading, Icon, Input, Kanban, Menu2 as Menu, MobileMenu, Modal, MultiSwitch, Navbar, OtpInput, Pagination, Pillbox, Popover, Portal, Profile, Progress, RadioGroup, SKIN_TONES, Select, Separator, Sidebar, Skeleton, Slider, Switch, Table, Tabs, Text, Textarea, TimePicker, Timeline, Toast, Tooltip, TreeNav, applyTone, cn, configureIcons, find, hasSkinTones, registerExtension, registerExtensions, registerIconSet, registerIcons, resolve, search, skinTones, useAccordion, useAnimation, useCanvas, useCarousel, useCommand, useContextMenu, useControllableState, useDiagram, useDropdown, useEditor, useEscapeKey, useFileUpload, useFloatingPosition, useFocusTrap, useId12 as useId, useKanban, useMenu, useMobileMenu, useModal, useNavbar, useNodeRegistry, useOutsideClick, usePanZoom, usePopover, useSidebar, useTabs, useToast, useTreeNav };
12266
+ export { Accordion, Action, Autocomplete, Avatar, Badge, Brand, Breadcrumbs, Calendar, Callout, Canvas, Card, Carousel, Chart, Checkbox, CheckboxGroup, ColorPicker, Command, Composer, ContentRenderer, ContextMenu, DatePicker, Diagram, Dropdown, EMOJI_CATEGORY_ORDER, EMOJI_DATA, EMOJI_ENTRIES, Editor, Emoji, EmojiSelect, Field, FileUpload, Heading, Icon, Input, Kanban, Menu2 as Menu, MobileMenu, Modal, MultiSwitch, Navbar, OtpInput, Pagination, Pillbox, Popover, Portal, Profile, Progress, RadioGroup, SKIN_TONES, Select, Separator, Sidebar, Skeleton, Slider, Switch, Table, Tabs, Text, Textarea, TimePicker, Timeline, Toast, Tooltip, TreeNav, applyTone, cn, configureIcons, find, hasSkinTones, registerExtension, registerExtensions, registerIconSet, registerIcons, resolve, sanitizeHref, sanitizeHtml, search, skinTones, useAccordion, useAnimation, useCanvas, useCarousel, useCommand, useContextMenu, useControllableState, useDiagram, useDropdown, useEditor, useEscapeKey, useFileUpload, useFloatingPosition, useFocusTrap, useId12 as useId, useKanban, useMenu, useMobileMenu, useModal, useNavbar, useNodeRegistry, useOutsideClick, usePanZoom, usePopover, useSidebar, useTabs, useToast, useTreeNav };
12185
12267
  //# sourceMappingURL=index.js.map
12186
12268
  //# sourceMappingURL=index.js.map