@xyd-js/atlas 0.1.0-xyd.1

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.
Files changed (52) hide show
  1. package/.babelrc +6 -0
  2. package/.storybook/index.css +32 -0
  3. package/.storybook/main.ts +19 -0
  4. package/.storybook/preview.ts +18 -0
  5. package/.storybook/public/fonts/fustat-ext-500.woff2 +0 -0
  6. package/.storybook/public/fonts/fustat-ext-600.woff2 +0 -0
  7. package/.storybook/public/fonts/fustat-ext-700.woff2 +0 -0
  8. package/.storybook/public/fonts/fustat-regular.woff2 +0 -0
  9. package/README.md +3 -0
  10. package/declarations.d.ts +4 -0
  11. package/dist/index.css +58 -0
  12. package/dist/index.d.ts +18 -0
  13. package/dist/index.js +1 -0
  14. package/index.ts +3 -0
  15. package/package.json +61 -0
  16. package/postcss.config.cjs +5 -0
  17. package/rollup.config.js +75 -0
  18. package/src/components/ApiRef/ApiRefItem/ApiRefItem.styles.tsx +70 -0
  19. package/src/components/ApiRef/ApiRefItem/ApiRefItem.tsx +97 -0
  20. package/src/components/ApiRef/ApiRefItem/index.ts +7 -0
  21. package/src/components/ApiRef/ApiRefProperties/ApiRefProperties.styles.tsx +154 -0
  22. package/src/components/ApiRef/ApiRefProperties/ApiRefProperties.tsx +134 -0
  23. package/src/components/ApiRef/ApiRefProperties/index.ts +7 -0
  24. package/src/components/ApiRef/ApiRefSamples/ApiRefSamples.styles.tsx +28 -0
  25. package/src/components/ApiRef/ApiRefSamples/ApiRefSamples.tsx +48 -0
  26. package/src/components/ApiRef/ApiRefSamples/index.ts +7 -0
  27. package/src/components/ApiRef/index.ts +5 -0
  28. package/src/components/Atlas/Atlas.styles.tsx +7 -0
  29. package/src/components/Atlas/Atlas.tsx +25 -0
  30. package/src/components/Atlas/AtlasLazy/AtlasLazy.styles.tsx +10 -0
  31. package/src/components/Atlas/AtlasLazy/AtlasLazy.tsx +45 -0
  32. package/src/components/Atlas/AtlasLazy/hooks.ts +29 -0
  33. package/src/components/Atlas/AtlasLazy/index.ts +7 -0
  34. package/src/components/Atlas/index.ts +3 -0
  35. package/src/components/Code/CodeCopy/CodeCopy.style.tsx +21 -0
  36. package/src/components/Code/CodeCopy/CodeCopy.tsx +32 -0
  37. package/src/components/Code/CodeCopy/index.ts +7 -0
  38. package/src/components/Code/CodeSample/CodeSample.styles.tsx +134 -0
  39. package/src/components/Code/CodeSample/CodeSample.tsx +149 -0
  40. package/src/components/Code/CodeSample/index.ts +8 -0
  41. package/src/components/Code/CodeSample/withLocalStored.tsx +52 -0
  42. package/src/components/Code/CodeSampleButtons/CodeSampleButtons.styles.tsx +67 -0
  43. package/src/components/Code/CodeSampleButtons/CodeSampleButtons.tsx +106 -0
  44. package/src/components/Code/CodeSampleButtons/index.ts +7 -0
  45. package/src/components/Code/default-theme.ts +266 -0
  46. package/src/components/Code/index.ts +6 -0
  47. package/src/docs/AtlasExample/AtlasExample.stories.tsx +47 -0
  48. package/src/docs/AtlasExample/todo-app.uniform.json +625 -0
  49. package/src/docs/AtlasExample/uniform-to-references.ts +101 -0
  50. package/src/utils/mdx.ts +31 -0
  51. package/tsconfig.json +44 -0
  52. package/vite.config.ts +25 -0
@@ -0,0 +1,101 @@
1
+ // TODO: move to utils or somewhere else
2
+ import React from "react";
3
+ import {parse} from "codehike";
4
+ import {visit} from "unist-util-visit";
5
+ import {recmaCodeHike, remarkCodeHike} from "codehike/mdx";
6
+ import {compile as mdxCompile} from "@mdx-js/mdx";
7
+
8
+ import {Reference} from "@xyd-js/uniform";
9
+ import {
10
+ compile as compileMarkdown,
11
+ referenceAST
12
+ } from "@xyd-js/uniform/markdown";
13
+
14
+ import {MDXReference} from "@/utils/mdx";
15
+ import todoAppUniform from "./todo-app.uniform.json";
16
+
17
+ // since unist does not support heading level > 6, we need to normalize them
18
+ function normalizeCustomHeadings() {
19
+ return (tree: any) => {
20
+ visit(tree, 'paragraph', (node, index, parent) => {
21
+ const match = node.children[0] && node.children[0].value.match(/^(#+)\s+(.*)/);
22
+ if (match) {
23
+ const level = match[1].length;
24
+ const text = match[2];
25
+ if (level > 6) {
26
+ // Create a new heading node with depth 6
27
+ const headingNode = {
28
+ type: 'heading',
29
+ depth: level,
30
+ children: [{type: 'text', value: text}]
31
+ };
32
+ // Replace the paragraph node with the new heading node
33
+ //@ts-ignore
34
+ parent.children[index] = headingNode;
35
+ }
36
+ }
37
+ });
38
+ };
39
+ }
40
+
41
+ const codeHikeOptions = {
42
+ lineNumbers: true,
43
+ showCopyButton: true,
44
+ autoImport: true,
45
+ components: {code: "Code"},
46
+ // syntaxHighlighting: { // TODO: !!! FROM SETTINGS !!! wait for rr7 rsc ??
47
+ // theme: "github-dark",
48
+ // },
49
+ };
50
+
51
+ async function compile(content: string): Promise<string> {
52
+ const compiled = await mdxCompile(content, {
53
+ remarkPlugins: [normalizeCustomHeadings, [remarkCodeHike, codeHikeOptions]],
54
+ recmaPlugins: [
55
+ [recmaCodeHike, codeHikeOptions]
56
+ ],
57
+ outputFormat: 'function-body',
58
+ development: false,
59
+ });
60
+
61
+ return String(compiled)
62
+ }
63
+
64
+ // TODO: move below to content?
65
+ function getMDXComponent(code: string) {
66
+ const mdxExport = getMDXExport(code)
67
+ return mdxExport.default
68
+ }
69
+
70
+ function getMDXExport(code: string) {
71
+ const scope = {
72
+ Fragment: React.Fragment,
73
+ jsxs: React.createElement,
74
+ jsx: React.createElement,
75
+ jsxDEV: React.createElement,
76
+ }
77
+ const fn = new Function(...Object.keys(scope), code)
78
+ return fn(scope)
79
+ }
80
+
81
+ export async function uniformToReferences(): Promise<MDXReference<Reference[]> | []> {
82
+ let content: string = ""
83
+
84
+ for (const ref of todoAppUniform as Reference[]) {
85
+ const ast = referenceAST(ref)
86
+ const md = compileMarkdown(ast)
87
+
88
+ content += md + "\n"
89
+ }
90
+
91
+ const compiled = await compile(content)
92
+ const contentCode = getMDXComponent(compiled)
93
+
94
+ const parsedContent = contentCode ? parse(contentCode) : null
95
+
96
+ if (parsedContent) {
97
+ return parsedContent.references
98
+ }
99
+
100
+ return []
101
+ }
@@ -0,0 +1,31 @@
1
+ import React from "react";
2
+
3
+ export type MDXReferenceWrapper<T> = {
4
+ children: React.ReactNode;
5
+ title: string;
6
+ };
7
+
8
+ export type MDXReference<T> = T extends object
9
+ ? MDXReferenceWrapper<T> & {
10
+ [K in keyof T]: MDXReference<T[K]>;
11
+ }
12
+ : MDXReferenceWrapper<T>;
13
+
14
+ // TODO: unify xyd reference props with react
15
+ export function mdxValue<T>(val: MDXReferenceWrapper<T> | null): string {
16
+ if (!val) {
17
+ return ""
18
+ }
19
+
20
+ if (val.title) {
21
+ return val.title
22
+ }
23
+
24
+ // if we have case like below
25
+ /*
26
+ #### !!<key> <name>
27
+
28
+ !<key> string
29
+ */
30
+ return val as unknown as string
31
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "compilerOptions": {
3
+ "baseUrl": ".",
4
+ "paths": {
5
+ "@/atlas/*": [
6
+ "src/atlas/*"
7
+ ],
8
+ "@/components/*": [
9
+ "src/components/*"
10
+ ],
11
+ "@/utils/*": [
12
+ "src/utils/*"
13
+ ]
14
+ },
15
+ "module": "esnext",
16
+ "esModuleInterop": true,
17
+ "moduleResolution": "node",
18
+ "target": "ES6",
19
+ "lib": [
20
+ "dom",
21
+ "dom.iterable",
22
+ "esnext"
23
+ ],
24
+ "allowJs": true,
25
+ "skipLibCheck": true,
26
+ "strict": false,
27
+ "noEmit": true,
28
+ "incremental": false,
29
+ "resolveJsonModule": true,
30
+ "isolatedModules": true,
31
+ "jsx": "preserve",
32
+ "strictNullChecks": true
33
+ },
34
+ "include": [
35
+ "src/**/*.ts",
36
+ "src/**/*.tsx",
37
+ "src/**/*.json",
38
+ ".storybook/**/*.ts",
39
+ ".storybook/**/*.tsx",
40
+ ],
41
+ "exclude": [
42
+ "node_modules"
43
+ ]
44
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,25 @@
1
+ import {resolve} from 'path';
2
+
3
+ import {defineConfig} from 'vite';
4
+ import react from '@vitejs/plugin-react';
5
+ import wyw from '@wyw-in-js/vite';
6
+
7
+ // https://vitejs.dev/config/
8
+
9
+ // eslint-disable-next-line import/no-default-export
10
+ export default defineConfig({
11
+ plugins: [
12
+ wyw({
13
+ include: ['**/*.{ts,tsx}'],
14
+ babelOptions: {
15
+ presets: ['@babel/preset-typescript', '@babel/preset-react'],
16
+ },
17
+ }),
18
+ react(),
19
+ ],
20
+ resolve: {
21
+ alias: {
22
+ '@': resolve(__dirname, 'src'),
23
+ },
24
+ },
25
+ });