@amritanshu3011/mdx-renderer 1.0.7 → 1.0.9

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.
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const DynamicVisuals: React.FC;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useVisualizations } from './context/VisualizationContext';
3
+ import { visualizationRegistry } from './index';
4
+ export const DynamicVisuals = () => {
5
+ const { visualizations } = useVisualizations();
6
+ if (!visualizations || visualizations.length === 0) {
7
+ return _jsx("div", { className: "p-4 text-slate-400 italic", children: "Waiting for data..." });
8
+ }
9
+ return (_jsx("div", { className: "flex flex-col gap-8 my-8", children: visualizations.map((viz, index) => {
10
+ const Component = visualizationRegistry[viz.type];
11
+ if (!Component)
12
+ return null;
13
+ return _jsx(Component, { ...viz.data }, index);
14
+ }) }));
15
+ };
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ interface IntentProviderProps {
3
+ children: React.ReactNode;
4
+ data?: any[];
5
+ theme?: any;
6
+ }
7
+ export declare const IntentProvider: React.FC<IntentProviderProps>;
8
+ export {};
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ThemeProvider } from './theme/ThemeContext';
3
+ import { VisualizationProvider } from './context/VisualizationContext';
4
+ export const IntentProvider = ({ children, data = [], theme }) => {
5
+ return (_jsx(ThemeProvider, { initialTheme: theme, children: _jsx(VisualizationProvider, { initialVisualizations: data, children: children }) }));
6
+ };
@@ -1,7 +1,4 @@
1
1
  import React from 'react';
2
- interface MDXRendererProps {
2
+ export declare const MDXRenderer: React.FC<{
3
3
  children: React.ReactNode;
4
- className?: string;
5
- }
6
- export declare const MDXRenderer: React.FC<MDXRendererProps>;
7
- export {};
4
+ }>;
@@ -1,79 +1,10 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { MDXProvider } from '@mdx-js/react';
3
- // 👇 CHANGE 1: Use the Context Hook (so updates happen live)
4
- // import { useThemeWithFallback } from './utils/useThemeWithFallback';
5
- import { useTheme } from './theme/ThemeContext';
6
- // Text components
7
- import { Heading } from './components/text/Heading';
8
- import { Paragraph } from './components/text/Paragraph';
9
- import { Blockquote } from './components/text/Blockquote';
10
- import { List } from './components/text/List';
11
- // Layout components
12
- import { Card } from './components/layout/Card';
13
- // Data components
14
- import { SimpleChart } from './components/data/SimpleChart';
15
- import { LineChart } from './components/data/LineChart';
16
- import { BarChart } from './components/data/BarChart';
17
- // Interactive components
18
- import { Accordion } from './components/interactive/Accordion';
19
- import { Tabs } from './components/interactive/Tabs';
20
- // Composite components
21
- import { Dashboard } from './components/composite/Dashboard';
22
- import { DataExplorer } from './components/composite/DataExplorer';
23
- import { WeatherWidget } from './components/WeatherWidget';
24
- import { ProcessFlow } from './components/text/ProcessFlow';
25
- import { ComparisonGrid } from './components/text/ComparisonGrid';
26
- import { DynamicVisualizations } from './components/DynamicVisualizations';
3
+ import { DynamicVisuals } from './DynamicVisuals'; // Import the bridge
27
4
  const components = {
28
- // Text
29
- h1: (props) => _jsx(Heading, { level: 1, ...props }),
30
- h2: (props) => _jsx(Heading, { level: 2, ...props }),
31
- p: (props) => _jsx(Paragraph, { ...props }),
32
- blockquote: (props) => _jsx(Blockquote, { ...props }),
33
- ul: (props) => _jsx(List, { ordered: false, ...props }),
34
- ol: (props) => _jsx(List, { ordered: true, ...props }),
35
- // Layout
36
- Card,
37
- // Data
38
- SimpleChart,
39
- LineChart,
40
- BarChart,
41
- // Interactive
42
- Accordion,
43
- Tabs,
44
- // Composite
45
- Dashboard,
46
- DataExplorer,
47
- // Widgets
48
- WeatherWidget,
49
- //LLM
50
- DynamicVisualizations,
51
- //Text
52
- ProcessFlow,
53
- ComparisonGrid,
5
+ // Inject it globally so users just write <DynamicVisuals />
6
+ DynamicVisuals: DynamicVisuals,
54
7
  };
55
- export const MDXRenderer = ({ children, className = 'mdx-content' }) => {
56
- // 👇 CHANGE 3: Get theme from Context
57
- const { theme } = useTheme();
58
- // 👇 CHANGE 4: Create the Bridge (JS -> CSS Variables)
59
- const themeStyles = {
60
- // Colors
61
- '--color-primary': theme.colors.primary,
62
- '--color-secondary': theme.colors.secondary,
63
- '--color-text': theme.colors.text,
64
- '--color-text-secondary': theme.colors.textSecondary,
65
- '--color-background': theme.colors.background,
66
- '--color-card-bg': theme.colors.cardBackground,
67
- '--color-border': theme.colors.border,
68
- // Spacing
69
- '--spacing-small': theme.spacing.small,
70
- '--spacing-medium': theme.spacing.medium,
71
- '--spacing-large': theme.spacing.large,
72
- // Typography
73
- '--font-family': theme.typography.fontFamily,
74
- // Border Radius
75
- '--radius-small': theme.borderRadius.small,
76
- '--radius-medium': theme.borderRadius.medium,
77
- };
78
- return (_jsx("div", { className: className, style: themeStyles, children: _jsx(MDXProvider, { components: components, children: children }) }));
8
+ export const MDXRenderer = ({ children }) => {
9
+ return (_jsx(MDXProvider, { components: components, children: children }));
79
10
  };
@@ -5,9 +5,9 @@ interface VisualizationContextType {
5
5
  addVisualization: (viz: LLMResponse) => void;
6
6
  clearVisualizations: () => void;
7
7
  }
8
- interface VisualizationProviderProps {
8
+ export declare const VisualizationProvider: ({ children, initialVisualizations }: {
9
9
  children: React.ReactNode;
10
- }
11
- export declare const VisualizationProvider: React.FC<VisualizationProviderProps>;
10
+ initialVisualizations?: any[];
11
+ }) => import("react/jsx-runtime").JSX.Element;
12
12
  export declare const useVisualizations: () => VisualizationContextType;
13
13
  export {};
@@ -1,8 +1,13 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createContext, useContext, useState } from 'react';
2
+ import React, { createContext, useContext } from 'react';
3
3
  const VisualizationContext = createContext(undefined);
4
- export const VisualizationProvider = ({ children }) => {
5
- const [visualizations, setVisualizations] = useState([]);
4
+ export const VisualizationProvider = ({ children, initialVisualizations = [] }) => {
5
+ const [visualizations, setVisualizations] = React.useState(initialVisualizations);
6
+ React.useEffect(() => {
7
+ if (initialVisualizations.length > 0) {
8
+ setVisualizations(initialVisualizations);
9
+ }
10
+ }, [initialVisualizations]);
6
11
  const addVisualization = (viz) => {
7
12
  console.log('Storing visualization:', viz);
8
13
  setVisualizations(prev => [...prev, viz]);
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export { defaultTheme } from './theme/defaultTheme';
4
4
  export { useThemeWithFallback } from './utils/useThemeWithFallback';
5
5
  export type { Theme } from './theme/types';
6
6
  export { MDXRenderer } from './MDXRenderer';
7
+ export { IntentProvider } from './IntentProvider';
7
8
  export { ProsConsBlock } from './components/smart/ProsConsBlock';
8
9
  export { ComparisonBlock } from './components/smart/ComparisonBlock';
9
10
  export { FlowBlock } from './components/smart/FlowBlock';
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export { defaultTheme } from './theme/defaultTheme';
5
5
  export { useThemeWithFallback } from './utils/useThemeWithFallback';
6
6
  // Renderer
7
7
  export { MDXRenderer } from './MDXRenderer';
8
+ export { IntentProvider } from './IntentProvider';
8
9
  // Smart Components
9
10
  export { ProsConsBlock } from './components/smart/ProsConsBlock';
10
11
  export { ComparisonBlock } from './components/smart/ComparisonBlock';
@@ -3,11 +3,13 @@ import type { Theme } from './types';
3
3
  interface ThemeContextType {
4
4
  theme: Theme;
5
5
  themeName: 'light' | 'dark';
6
+ isDark: boolean;
6
7
  toggleTheme: () => void;
7
8
  }
8
9
  export declare const ThemeContext: React.Context<ThemeContextType | undefined>;
9
- interface ThemeProviderProps {
10
+ export interface ThemeProviderProps {
10
11
  children: React.ReactNode;
12
+ initialTheme?: 'light' | 'dark' | Theme;
11
13
  }
12
14
  export declare const ThemeProvider: React.FC<ThemeProviderProps>;
13
15
  export declare const useTheme: () => ThemeContextType;
@@ -2,13 +2,32 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createContext, useContext, useState } from 'react';
3
3
  import { lightTheme, darkTheme } from './themes';
4
4
  export const ThemeContext = createContext(undefined);
5
- export const ThemeProvider = ({ children }) => {
6
- const [themeName, setThemeName] = useState('light');
7
- const theme = themeName === 'light' ? lightTheme : darkTheme;
5
+ export const ThemeProvider = ({ children, initialTheme }) => {
6
+ // Determine start state based on initialTheme prop
7
+ const getInitialMode = () => {
8
+ if (initialTheme === 'dark')
9
+ return 'dark';
10
+ if (typeof initialTheme === 'object' && initialTheme !== null) {
11
+ // If a full theme object was passed, we might default to light
12
+ // or check a property, but for simplicity:
13
+ return 'light';
14
+ }
15
+ return 'light';
16
+ };
17
+ const [themeName, setThemeName] = useState(getInitialMode());
18
+ // Logic: Use the passed object if it's a custom theme, otherwise switch between built-ins
19
+ const activeTheme = (typeof initialTheme === 'object' && initialTheme !== null)
20
+ ? initialTheme // Use the custom theme passed via IntentProvider
21
+ : (themeName === 'light' ? lightTheme : darkTheme);
8
22
  const toggleTheme = () => {
9
23
  setThemeName(prev => prev === 'light' ? 'dark' : 'light');
10
24
  };
11
- return (_jsx(ThemeContext.Provider, { value: { theme, themeName, toggleTheme }, children: children }));
25
+ return (_jsx(ThemeContext.Provider, { value: {
26
+ theme: activeTheme,
27
+ themeName,
28
+ isDark: themeName === 'dark', // Calculated boolean
29
+ toggleTheme
30
+ }, children: children }));
12
31
  };
13
32
  export const useTheme = () => {
14
33
  const context = useContext(ThemeContext);
package/package.json CHANGED
@@ -1,12 +1,20 @@
1
1
  {
2
2
  "name": "@amritanshu3011/mdx-renderer",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Reusable MDX visualization library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./styles/base.css": "./styles/base.css"
13
+ },
7
14
  "files": [
8
15
  "dist",
9
- "README.md"
16
+ "README.md",
17
+ "styles"
10
18
  ],
11
19
  "scripts": {
12
20
  "build": "tsc"
@@ -0,0 +1,105 @@
1
+ /* src/mdx-renderer/styles/base.css */
2
+
3
+ .mdx-content {
4
+ font-family: var(--font-family);
5
+ color: var(--color-text);
6
+ line-height: 1.6;
7
+ font-size: 16px;
8
+ }
9
+
10
+ /* --- TYPOGRAPHY --- */
11
+ .mdx-content h1,
12
+ .mdx-content h2,
13
+ .mdx-content h3 {
14
+ color: var(--color-text);
15
+ margin-top: var(--spacing-large);
16
+ margin-bottom: var(--spacing-medium);
17
+ font-weight: 700;
18
+ letter-spacing: -0.02em; /* Makes headings look tighter & modern */
19
+ }
20
+
21
+ .mdx-content h1 { font-size: 2rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.5rem; }
22
+ .mdx-content h2 { font-size: 1.5rem; }
23
+ .mdx-content h3 { font-size: 1.25rem; }
24
+
25
+ .mdx-content p {
26
+ color: var(--color-text-secondary); /* Softer reading color */
27
+ margin-bottom: var(--spacing-medium);
28
+ line-height: 1.7; /* Better readability */
29
+ }
30
+
31
+ /* --- LISTS --- */
32
+ .mdx-content ul,
33
+ .mdx-content ol {
34
+ color: var(--color-text-secondary);
35
+ margin-bottom: var(--spacing-medium);
36
+ padding-left: 1.5rem;
37
+ }
38
+
39
+ .mdx-content li {
40
+ margin-bottom: 6px; /* Spacing between bullets */
41
+ }
42
+
43
+ /* --- BLOCKQUOTES (The "Callout" Look) --- */
44
+ .mdx-content blockquote {
45
+ border-left: 4px solid var(--color-primary); /* Use primary color! */
46
+ background-color: var(--color-card-bg); /* Subtle background */
47
+ padding: 16px 20px;
48
+ margin: 24px 0;
49
+ border-radius: 0 var(--radius-medium) var(--radius-medium) 0;
50
+ font-style: italic;
51
+ color: var(--color-text);
52
+ }
53
+
54
+ /* --- CODE BLOCKS --- */
55
+ .mdx-content code {
56
+ background: var(--color-card-bg);
57
+ border: 1px solid var(--color-border);
58
+ padding: 2px 6px;
59
+ border-radius: 4px;
60
+ font-family: 'Fira Code', monospace; /* Or standard monospace */
61
+ font-size: 0.85em;
62
+ color: var(--color-primary); /* Highlight code in brand color */
63
+ }
64
+
65
+ .mdx-content pre {
66
+ background: #1e1e1e; /* Always dark for code blocks looks Pro */
67
+ color: #f8f8f2;
68
+ padding: 20px;
69
+ border-radius: var(--radius-medium);
70
+ overflow-x: auto;
71
+ margin: 24px 0;
72
+ }
73
+
74
+ .mdx-content pre code {
75
+ color: inherit;
76
+ background: transparent;
77
+ border: none;
78
+ padding: 0;
79
+ }
80
+
81
+ /* --- TABLES (Crucial for BI Data) --- */
82
+ .mdx-content table {
83
+ width: 100%;
84
+ border-collapse: collapse;
85
+ margin: 24px 0;
86
+ font-size: 0.95rem;
87
+ }
88
+
89
+ .mdx-content th {
90
+ text-align: left;
91
+ padding: 12px;
92
+ border-bottom: 2px solid var(--color-border);
93
+ color: var(--color-text);
94
+ font-weight: 600;
95
+ }
96
+
97
+ .mdx-content td {
98
+ padding: 12px;
99
+ border-bottom: 1px solid var(--color-border);
100
+ color: var(--color-text-secondary);
101
+ }
102
+
103
+ .mdx-content tr:last-child td {
104
+ border-bottom: none;
105
+ }