@sijanbhattarai/veda-utils 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.
- package/dist/ChartContext.d.ts +13 -0
- package/dist/CreateInterface.d.ts +25 -0
- package/dist/MapContext.d.ts +13 -0
- package/dist/content.d.ts +15 -0
- package/dist/data.d.ts +6 -0
- package/dist/extractImports.d.ts +1 -0
- package/dist/groupElements.d.ts +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1625 -0
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +32 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/inputValidation.d.ts +6 -0
- package/dist/lib/index.d.ts +9 -0
- package/dist/parseTwoColumn.d.ts +1 -0
- package/dist/reserializeMDast.d.ts +1 -0
- package/dist/wrapComponent.d.ts +6 -0
- package/package.json +59 -0
- package/src/ChartContext.tsx +29 -0
- package/src/CreateInterface.tsx +300 -0
- package/src/MapContext.tsx +29 -0
- package/src/content.tsx +18 -0
- package/src/data.tsx +36 -0
- package/src/extractImports.tsx +45 -0
- package/src/groupElements.tsx +90 -0
- package/src/index.ts +13 -0
- package/src/inputValidation.tsx +148 -0
- package/src/lib/index.ts +89 -0
- package/src/parseTwoColumn.tsx +26 -0
- package/src/reserializeMDast.tsx +107 -0
- package/src/wrapComponent.tsx +25 -0
- package/tsconfig.json +25 -0
- package/vite.config.ts +50 -0
package/src/lib/index.ts
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2
|
+
// @ts-nocheck : until veda-ui fixes its types
|
3
|
+
'use client';
|
4
|
+
|
5
|
+
import {
|
6
|
+
CatalogContent,
|
7
|
+
PageHero,
|
8
|
+
useFiltersWithQS,
|
9
|
+
ReactQueryProvider,
|
10
|
+
DevseedUiThemeProvider,
|
11
|
+
VedaUIProvider,
|
12
|
+
Block,
|
13
|
+
Prose,
|
14
|
+
Figure,
|
15
|
+
Caption,
|
16
|
+
Image,
|
17
|
+
MapBlock,
|
18
|
+
CompareImage,
|
19
|
+
PageHeader,
|
20
|
+
PageFooter,
|
21
|
+
NavItem,
|
22
|
+
NavItemType,
|
23
|
+
InternalNavLink,
|
24
|
+
ExplorationAndAnalysis,
|
25
|
+
DatasetSelectorModal,
|
26
|
+
timelineDatasetsAtom,
|
27
|
+
useTimelineDatasetAtom,
|
28
|
+
StoriesHubContent,
|
29
|
+
externalDatasetsAtom,
|
30
|
+
ScrollytellingBlock,
|
31
|
+
Chapter,
|
32
|
+
Chart,
|
33
|
+
DatasetData,
|
34
|
+
StoryData,
|
35
|
+
VedaData,
|
36
|
+
LegacyGlobalStyles,
|
37
|
+
} from '@teamimpact/veda-ui';
|
38
|
+
|
39
|
+
/**
|
40
|
+
* This file is to...
|
41
|
+
* Quickly identify client specific library components being used throughout this application
|
42
|
+
* And to mark these with the client side directive so other parts of the page are still Server Components and can stay as-is
|
43
|
+
*/
|
44
|
+
|
45
|
+
export {
|
46
|
+
// Providers
|
47
|
+
DevseedUiThemeProvider,
|
48
|
+
ReactQueryProvider,
|
49
|
+
VedaUIProvider,
|
50
|
+
|
51
|
+
// Components
|
52
|
+
CatalogContent,
|
53
|
+
PageHero,
|
54
|
+
PageHeader,
|
55
|
+
PageFooter,
|
56
|
+
ExplorationAndAnalysis,
|
57
|
+
DatasetSelectorModal,
|
58
|
+
StoriesHubContent,
|
59
|
+
|
60
|
+
// MDX Components
|
61
|
+
Block,
|
62
|
+
Prose,
|
63
|
+
Figure,
|
64
|
+
Caption,
|
65
|
+
Image,
|
66
|
+
MapBlock,
|
67
|
+
CompareImage,
|
68
|
+
ScrollytellingBlock,
|
69
|
+
Chapter,
|
70
|
+
Chart,
|
71
|
+
|
72
|
+
// Hooks
|
73
|
+
useFiltersWithQS,
|
74
|
+
|
75
|
+
// State
|
76
|
+
timelineDatasetsAtom,
|
77
|
+
useTimelineDatasetAtom,
|
78
|
+
externalDatasetsAtom,
|
79
|
+
LegacyGlobalStyles,
|
80
|
+
};
|
81
|
+
|
82
|
+
export type {
|
83
|
+
DatasetData,
|
84
|
+
NavItem,
|
85
|
+
NavItemType,
|
86
|
+
InternalNavLink,
|
87
|
+
StoryData,
|
88
|
+
VedaData,
|
89
|
+
};
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { wrapComponent } from './wrapComponent';
|
2
|
+
|
3
|
+
export const handleTwoColumn = (MDAST) => {
|
4
|
+
const newTwoColumn: any = [];
|
5
|
+
for (const twoColumnChildren of MDAST.children) {
|
6
|
+
if (
|
7
|
+
twoColumnChildren.children.some(
|
8
|
+
(e) => e.name === 'Chart' || e.name === 'Map',
|
9
|
+
)
|
10
|
+
) {
|
11
|
+
for (const columnChild of twoColumnChildren.children) {
|
12
|
+
if (columnChild.name === 'Chart' || columnChild.name === 'Map') {
|
13
|
+
newTwoColumn.push(wrapComponent(columnChild));
|
14
|
+
}
|
15
|
+
}
|
16
|
+
} else {
|
17
|
+
newTwoColumn.push({
|
18
|
+
type: 'mdxJsxFlowElement',
|
19
|
+
name: 'Prose',
|
20
|
+
attributes: [],
|
21
|
+
children: [...twoColumnChildren.children],
|
22
|
+
});
|
23
|
+
}
|
24
|
+
}
|
25
|
+
return newTwoColumn;
|
26
|
+
};
|
@@ -0,0 +1,107 @@
|
|
1
|
+
import { toMarkdown } from 'mdast-util-to-markdown';
|
2
|
+
import { mdxToMarkdown } from 'mdast-util-mdx';
|
3
|
+
import { gfmToMarkdown } from 'mdast-util-gfm';
|
4
|
+
import { mdxJsxToMarkdown } from 'mdast-util-mdx-jsx';
|
5
|
+
import { extractImports } from './extractImports';
|
6
|
+
|
7
|
+
import { groupByBreakIntoBlocks } from './groupElements';
|
8
|
+
|
9
|
+
const blockItem = {
|
10
|
+
type: 'mdxJsxFlowElement',
|
11
|
+
name: 'Block',
|
12
|
+
children: [],
|
13
|
+
};
|
14
|
+
|
15
|
+
const proseItem = {
|
16
|
+
type: 'mdxJsxFlowElement',
|
17
|
+
name: 'Prose',
|
18
|
+
children: [],
|
19
|
+
};
|
20
|
+
|
21
|
+
//TO DO: Create seperate block prose containers
|
22
|
+
|
23
|
+
const transformMdast = (node) => {
|
24
|
+
// if (!node || typeof node !== 'object') return node;
|
25
|
+
if (!node || node.type !== 'root' || !Array.isArray(node.children)) {
|
26
|
+
return node;
|
27
|
+
}
|
28
|
+
// if (node.type === 'root') {
|
29
|
+
// const newChildren: any = [];
|
30
|
+
const newChildren: any[] = [];
|
31
|
+
for (const child of node.children) {
|
32
|
+
// Unwrap paragraphs that only contain a single JSX flow element.
|
33
|
+
// This is a common pattern to avoid unwanted <p> tags around components.
|
34
|
+
if (
|
35
|
+
child.type === 'paragraph' &&
|
36
|
+
child.children.length === 1 &&
|
37
|
+
child.children[0].type === 'mdxJsxFlowElement'
|
38
|
+
) {
|
39
|
+
newChildren.push(child.children[0]);
|
40
|
+
} else {
|
41
|
+
newChildren.push(child);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
// for (const child of node.children) {
|
46
|
+
// if (child.type === 'paragraph') {
|
47
|
+
// // Elevate each text/html child to the root
|
48
|
+
// for (const sub of child.children) {
|
49
|
+
// switch (sub.type) {
|
50
|
+
// case 'text':
|
51
|
+
// newChildren.push({
|
52
|
+
// type: 'paragraph',
|
53
|
+
// children: [sub],
|
54
|
+
// });
|
55
|
+
// break;
|
56
|
+
// case 'html':
|
57
|
+
// newChildren.push(sub);
|
58
|
+
// break;
|
59
|
+
// case 'mdxJsxTextElement':
|
60
|
+
// newChildren.push(sub);
|
61
|
+
// break;
|
62
|
+
// case 'mdxJsxFlowElement':
|
63
|
+
// newChildren.push(sub);
|
64
|
+
// break;
|
65
|
+
// default:
|
66
|
+
// newChildren.push(sub);
|
67
|
+
// break;
|
68
|
+
// }
|
69
|
+
// }
|
70
|
+
// } else {
|
71
|
+
// // Recurse into child
|
72
|
+
// const transformed = transformMdast(child);
|
73
|
+
// newChildren.push(transformed);
|
74
|
+
// }
|
75
|
+
// }
|
76
|
+
|
77
|
+
// return { ...node, children: newChildren };
|
78
|
+
// }
|
79
|
+
|
80
|
+
// // Handle recursion for non-root nodes with children
|
81
|
+
// if (Array.isArray(node.children)) {
|
82
|
+
// return {
|
83
|
+
// ...node,
|
84
|
+
// children: node.children.map(transformMdast),
|
85
|
+
// };
|
86
|
+
// }
|
87
|
+
|
88
|
+
// return node;
|
89
|
+
return { ...node, children: newChildren };
|
90
|
+
};
|
91
|
+
|
92
|
+
export const reserializedMdxContent = (MDAST) => {
|
93
|
+
|
94
|
+
const seperatedMDAST = transformMdast(MDAST);
|
95
|
+
|
96
|
+
const groupedMDSAT = groupByBreakIntoBlocks(seperatedMDAST);
|
97
|
+
extractImports(seperatedMDAST);
|
98
|
+
|
99
|
+
const newMDast = { ...seperatedMDAST, children: groupedMDSAT };
|
100
|
+
const mdastToMdx = (mdast) => {
|
101
|
+
return toMarkdown(mdast, {
|
102
|
+
extensions: [mdxToMarkdown(), gfmToMarkdown(), mdxJsxToMarkdown()],
|
103
|
+
});
|
104
|
+
};
|
105
|
+
|
106
|
+
return mdastToMdx(newMDast);
|
107
|
+
};
|
@@ -0,0 +1,25 @@
|
|
1
|
+
export const wrapComponent = (mdastChild) => {
|
2
|
+
const generatedProps = mdastChild.attributes.reduce((acc, item) => {
|
3
|
+
acc[item.name] = item.value;
|
4
|
+
return acc;
|
5
|
+
}, {});
|
6
|
+
|
7
|
+
const wrappedComponent = {
|
8
|
+
type: 'mdxJsxFlowElement',
|
9
|
+
name: 'Figure',
|
10
|
+
attributes: [],
|
11
|
+
children: [
|
12
|
+
{ ...mdastChild },
|
13
|
+
{
|
14
|
+
type: 'mdxJsxFlowElement',
|
15
|
+
name: 'Caption',
|
16
|
+
attributes: [
|
17
|
+
{ name: 'attrAuthor', value: generatedProps.attrAuthor },
|
18
|
+
{ name: 'attrUrl', value: generatedProps.attrUrl },
|
19
|
+
],
|
20
|
+
children: [{ type: 'text', value: generatedProps.caption }],
|
21
|
+
},
|
22
|
+
],
|
23
|
+
};
|
24
|
+
return wrappedComponent;
|
25
|
+
};
|
package/tsconfig.json
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"target": "ES2020",
|
4
|
+
"module": "ESNext",
|
5
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
6
|
+
"jsx": "react-jsx",
|
7
|
+
"strict": false,
|
8
|
+
"skipLibCheck": true,
|
9
|
+
"esModuleInterop": true,
|
10
|
+
"allowSyntheticDefaultImports": true,
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
12
|
+
"moduleResolution": "node",
|
13
|
+
"resolveJsonModule": true,
|
14
|
+
"isolatedModules": true,
|
15
|
+
"declaration": true,
|
16
|
+
"declarationDir": "./dist",
|
17
|
+
"outDir": "./dist",
|
18
|
+
"baseUrl": ".",
|
19
|
+
"paths": {
|
20
|
+
"@/*": ["src/*"]
|
21
|
+
}
|
22
|
+
},
|
23
|
+
"include": ["src/**/*"],
|
24
|
+
"exclude": ["node_modules", "dist"]
|
25
|
+
}
|
package/vite.config.ts
ADDED
@@ -0,0 +1,50 @@
|
|
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: 'MDXEditorUtils',
|
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
|
+
'@mdxeditor/editor',
|
26
|
+
'@teamimpact/veda-ui',
|
27
|
+
'@trussworks/react-uswds',
|
28
|
+
'focus-trap-react',
|
29
|
+
'@uswds/uswds',
|
30
|
+
'unified',
|
31
|
+
'remark-parse',
|
32
|
+
'remark-stringify',
|
33
|
+
'mdast-util-from-markdown',
|
34
|
+
'mdast-util-mdx-jsx',
|
35
|
+
'mdast-util-gfm',
|
36
|
+
'micromark-extension-mdx-jsx',
|
37
|
+
'unist-util-visit'
|
38
|
+
],
|
39
|
+
output: {
|
40
|
+
globals: {
|
41
|
+
react: 'React',
|
42
|
+
'react-dom': 'ReactDOM',
|
43
|
+
'react/jsx-runtime': 'ReactJSXRuntime'
|
44
|
+
}
|
45
|
+
}
|
46
|
+
},
|
47
|
+
target: 'esnext',
|
48
|
+
sourcemap: true
|
49
|
+
}
|
50
|
+
});
|