@sijanbhattarai/veda-preview 1.0.35

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,6 @@
1
+ interface MDXPreviewProps {
2
+ source: string;
3
+ }
4
+ export declare function SimpleMDXPreview({ source }: MDXPreviewProps): import("react/jsx-runtime").JSX.Element;
5
+ export {};
6
+ //# sourceMappingURL=MDXPreview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MDXPreview.d.ts","sourceRoot":"","sources":["../src/MDXPreview.tsx"],"names":[],"mappings":"AA+GA,UAAU,eAAe;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB;AAwED,wBAAgB,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAAE,eAAe,2CAoB3D"}
@@ -0,0 +1,6 @@
1
+ export declare const PreviewPlaceholder: () => null;
2
+ export interface PreviewProps {
3
+ content?: string;
4
+ components?: Record<string, any>;
5
+ }
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,kBAAkB,YAE9B,CAAC;AAEF,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAClC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ const e = () => null;
2
+ export {
3
+ e as PreviewPlaceholder
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["// Export preview components\n\n// If you have a main preview component, export it\n// export { default as MDXPreview } from './MDXPreview';\n\n// Placeholder exports for now - add your actual components later\nexport const PreviewPlaceholder = () => {\n return null;\n};\n\nexport interface PreviewProps {\n content?: string;\n components?: Record<string, any>;\n}"],"names":["PreviewPlaceholder"],"mappings":"AAMO,MAAMA,IAAqB,MACzB;"}
@@ -0,0 +1,2 @@
1
+ (function(e,i){typeof exports=="object"&&typeof module<"u"?i(exports):typeof define=="function"&&define.amd?define(["exports"],i):(e=typeof globalThis<"u"?globalThis:e||self,i(e.MDXEditorPreview={}))})(this,function(e){"use strict";const i=()=>null;e.PreviewPlaceholder=i,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
2
+ //# sourceMappingURL=index.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.umd.js","sources":["../src/index.ts"],"sourcesContent":["// Export preview components\n\n// If you have a main preview component, export it\n// export { default as MDXPreview } from './MDXPreview';\n\n// Placeholder exports for now - add your actual components later\nexport const PreviewPlaceholder = () => {\n return null;\n};\n\nexport interface PreviewProps {\n content?: string;\n components?: Record<string, any>;\n}"],"names":["PreviewPlaceholder"],"mappings":"wOAMO,MAAMA,EAAqB,IACzB"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@sijanbhattarai/veda-preview",
3
+ "version": "1.0.35",
4
+ "description": "MDX Preview components",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "module": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "scripts": {
10
+ "build": "vite build",
11
+ "dev": "vite build --watch",
12
+ "type-check": "tsc --noEmit"
13
+ },
14
+ "peerDependencies": {
15
+ "react": "^18.0.0",
16
+ "react-dom": "^18.0.0",
17
+ "next": "^13.0.0 || ^14.0.0 || ^15.0.0",
18
+ "next-mdx-remote": "^5.0.0",
19
+ "@sijanbhattarai/veda-datasets": "^1.0.6"
20
+ },
21
+ "dependencies": {
22
+ "@sijanbhattarai/veda-core": "^0.1.6",
23
+ "@sijanbhattarai/veda-ui": "^0.1.6",
24
+ "@sijanbhattarai/veda-maps": "^1.0.6",
25
+ "sugar-high": "^0.7.5"
26
+ },
27
+ "devDependencies": {
28
+ "@types/react": "^18.0.0",
29
+ "@types/react-dom": "^18.0.0",
30
+ "typescript": "^5.0.0",
31
+ "vite": "^5.0.0",
32
+ "@vitejs/plugin-react": "^4.0.0"
33
+ },
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/NASA-IMPACT/mdx-editor-components.git"
37
+ },
38
+ "keywords": [
39
+ "mdx",
40
+ "editor",
41
+ "preview"
42
+ ],
43
+ "author": "NASA IMPACT",
44
+ "license": "MIT"
45
+ }
@@ -0,0 +1,206 @@
1
+ 'use client';
2
+
3
+ import React, { Suspense } from 'react';
4
+ import dynamic from 'next/dynamic';
5
+ import { MDXRemote } from 'next-mdx-remote/rsc';
6
+ import { customComponents } from '@sijanbhattarai/mdx-editor-core';
7
+ import { ChartWrapper } from './ChartPreview';
8
+ import { DEFAULT_MAP_PROPS } from '@sijanbhattarai/mdx-editor-ui';
9
+ import { highlight } from 'sugar-high';
10
+ import Link from 'next/link';
11
+
12
+ import { allAvailableDatasets } from '@sijanbhattarai/mdx-editor-datasets';
13
+
14
+ import {
15
+ Block,
16
+ Prose,
17
+ Caption,
18
+ Chapter,
19
+ Figure,
20
+ Image,
21
+ LegacyGlobalStyles,
22
+ } from './lib';
23
+ // import { mockDatasets } from './MapPreview';
24
+ import Providers from '@sijanbhattarai/mdx-editor-datasets';
25
+ // Correctly import the default export from mdx-preview-map with error handling
26
+
27
+ const ClientMapBlock = dynamic(() => import('@sijanbhattarai/mdx-editor-maps').then(mod => ({ default: mod.ClientMapBlock })), {
28
+ ssr: false,
29
+ loading: () => (
30
+ <div className=' flex items-center justify-center bg-blue-50'>
31
+ <div className='text-blue-500'>Loading map preview...</div>
32
+ </div>
33
+ ),
34
+ });
35
+
36
+ const MapWrapper = (props) => {
37
+ try {
38
+ // Handle center prop safely
39
+ let center;
40
+ try {
41
+ center =
42
+ typeof props.center === 'string' && props.center.startsWith('[')
43
+ ? JSON.parse(props.center)
44
+ : props.center || DEFAULT_MAP_PROPS.center;
45
+ } catch (error) {
46
+ console.warn('Error parsing center coordinates, using default:', error);
47
+ center = DEFAULT_MAP_PROPS.center;
48
+ }
49
+
50
+ // Handle zoom prop safely
51
+ let zoom;
52
+ try {
53
+ zoom =
54
+ typeof props.zoom === 'string'
55
+ ? parseFloat(props.zoom) || DEFAULT_MAP_PROPS.zoom
56
+ : props.zoom || DEFAULT_MAP_PROPS.zoom;
57
+ } catch (error) {
58
+ console.warn('Error parsing zoom level, using default:', error);
59
+ zoom = DEFAULT_MAP_PROPS.zoom;
60
+ }
61
+
62
+ return (
63
+ <ClientMapBlock
64
+ {...props}
65
+ center={center}
66
+ zoom={zoom}
67
+ datasetId={props.datasetId}
68
+ layerId={props.layerId}
69
+ dateTime={props.dateTime}
70
+ compareDateTime={props.compareDateTime}
71
+ compareLabel={props.compareLabel}
72
+ allAvailableDatasets={allAvailableDatasets}
73
+ />
74
+ );
75
+ } catch (error) {
76
+ console.error('Error rendering map:', error);
77
+ return (
78
+ <div className='h-[400px] flex items-center justify-center bg-red-50 border border-red-300 rounded'>
79
+ <div className='text-red-500'>Error rendering map component</div>
80
+ </div>
81
+ );
82
+ }
83
+ };
84
+
85
+ function Table({ data }: { data: any }) {
86
+ const headers = data.headers.map((header, index) => (
87
+ <th key={index}>{header}</th>
88
+ ));
89
+ const rows = data.rows.map((row, index) => (
90
+ <tr key={index}>
91
+ {row.map((cell, cellIndex) => (
92
+ <td key={cellIndex}>{cell}</td>
93
+ ))}
94
+ </tr>
95
+ ));
96
+
97
+ return (
98
+ <table>
99
+ <thead>
100
+ <tr>{headers}</tr>
101
+ </thead>
102
+ <tbody>{rows}</tbody>
103
+ </table>
104
+ );
105
+ }
106
+
107
+ function Code({ children, ...props }: { children: any }) {
108
+ const codeHTML = highlight(children);
109
+ return <code dangerouslySetInnerHTML={{ __html: codeHTML }} {...props} />;
110
+ }
111
+
112
+ interface MDXPreviewProps {
113
+ source: string;
114
+ }
115
+
116
+ function slugify(str) {
117
+ if (str != null || str != undefined) {
118
+ return str
119
+ .toString()
120
+ .toLowerCase()
121
+ .trim() // Remove whitespace from both ends of a string
122
+ .replace(/\s+/g, '-') // Replace spaces with -
123
+ .replace(/&/g, '-and-') // Replace & with 'and'
124
+ .replace(/[^\w\-]+/g, '') // Remove all non-word characters except for -
125
+ .replace(/\-\-+/g, '-'); // Replace multiple - with single -
126
+ }
127
+ }
128
+ function createHeading(level) {
129
+ const Heading = ({ children }: { children: JSX.Element }) => {
130
+ const slug = slugify(children);
131
+ return React.createElement(
132
+ `h${level}`,
133
+ { id: slug },
134
+ [
135
+ React.createElement('a', {
136
+ href: `#${slug}`,
137
+ key: `link-${slug}`,
138
+ className: 'anchor',
139
+ }),
140
+ ],
141
+ children,
142
+ );
143
+ };
144
+
145
+ Heading.displayName = `Heading${level}`;
146
+
147
+ return Heading;
148
+ }
149
+ // Define all components used in MDX
150
+ const components = {
151
+ ...customComponents,
152
+ // Basic markdown components
153
+ h1: createHeading(1),
154
+ h2: createHeading(2),
155
+ h3: createHeading(3),
156
+ h4: createHeading(4),
157
+ h5: createHeading(5),
158
+ h6: createHeading(6),
159
+ code: Code,
160
+ Table,
161
+ Block: Block,
162
+ Prose: Prose,
163
+ Caption: Caption,
164
+ Figure: Figure,
165
+ Image: Image,
166
+ Link: Link,
167
+ Chapter: Chapter,
168
+ TwoColumn: (props) => {
169
+ return (
170
+ <div className='grid-container maxw-full'>
171
+ <div className='grid-row grid-gap-lg'>{props.children}</div>
172
+ </div>
173
+ );
174
+ },
175
+ LeftColumn: (props) => {
176
+ return <div className='grid-col-6 '>{props.children}</div>;
177
+ },
178
+ RightColumn: (props) => {
179
+ return <div className='grid-col-6 '>{props.children}</div>;
180
+ },
181
+
182
+ Map: MapWrapper,
183
+ Chart: ChartWrapper,
184
+ };
185
+
186
+ export function SimpleMDXPreview({ source }: MDXPreviewProps) {
187
+ // Use an empty string as a default if source is undefined
188
+ // const datasets = getDatasetsMetadata();
189
+ const safeSource = source || '';
190
+
191
+ return (
192
+ <section>
193
+ <article className='prose'>
194
+ <Providers datasets={allAvailableDatasets}>
195
+ <LegacyGlobalStyles />
196
+
197
+ <Suspense
198
+ fallback={<div className='p-4'>Loading MDX preview...</div>}
199
+ >
200
+ <MDXRemote source={safeSource} components={components} />
201
+ </Suspense>
202
+ </Providers>
203
+ </article>
204
+ </section>
205
+ );
206
+ }
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ // Export preview components
2
+
3
+ // If you have a main preview component, export it
4
+ // export { default as MDXPreview } from './MDXPreview';
5
+
6
+ // Placeholder exports for now - add your actual components later
7
+ export const PreviewPlaceholder = () => {
8
+ return null;
9
+ };
10
+
11
+ export interface PreviewProps {
12
+ content?: string;
13
+ components?: Record<string, any>;
14
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
5
+ "module": "ESNext",
6
+ "skipLibCheck": true,
7
+ "moduleResolution": "node",
8
+ "allowImportingTsExtensions": false,
9
+ "resolveJsonModule": true,
10
+ "isolatedModules": true,
11
+ "noEmit": false,
12
+ "declaration": true,
13
+ "declarationMap": true,
14
+ "outDir": "./dist",
15
+ "jsx": "react-jsx",
16
+ "strict": true,
17
+ "esModuleInterop": true,
18
+ "allowSyntheticDefaultImports": true
19
+ },
20
+ "include": ["src"],
21
+ "exclude": ["dist", "node_modules", "**/*.test.*"]
22
+ }
package/vite.config.js ADDED
@@ -0,0 +1,42 @@
1
+ import { defineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+ import dts from 'vite-plugin-dts';
4
+ import { resolve } from 'path';
5
+
6
+ export default defineConfig({
7
+ plugins: [
8
+ react(),
9
+ dts({
10
+ insertTypesEntry: true,
11
+ })
12
+ ],
13
+ build: {
14
+ lib: {
15
+ entry: resolve(__dirname, 'src/index.ts'),
16
+ name: 'MDXEditorPreview',
17
+ formats: ['es', 'umd'],
18
+ fileName: (format) => `index.${format === 'es' ? 'js' : 'umd.js'}`
19
+ },
20
+ rollupOptions: {
21
+ external: [
22
+ 'react',
23
+ 'react-dom',
24
+ 'react/jsx-runtime',
25
+ 'next',
26
+ 'next/dynamic',
27
+ 'next-mdx-remote',
28
+ '@sijanbhattarai/veda-charts',
29
+ '@sijanbhattarai/veda-maps'
30
+ ],
31
+ output: {
32
+ globals: {
33
+ react: 'React',
34
+ 'react-dom': 'ReactDOM',
35
+ 'react/jsx-runtime': 'ReactJSXRuntime'
36
+ }
37
+ }
38
+ },
39
+ target: 'esnext',
40
+ sourcemap: true
41
+ }
42
+ });