@xyd-js/cli 0.1.0-xyd.3 → 0.1.0-xyd.30

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 (84) hide show
  1. package/.cli/bin.js +3 -0
  2. package/.cli/index.js +45705 -0
  3. package/.cli/package.json +38 -0
  4. package/.cli/plugins/xyd-plugin-zero/src/pages/api-reference-source.tsx +312 -0
  5. package/.cli/plugins/xyd-plugin-zero/src/pages/api-reference.tsx +90 -203
  6. package/.cli/plugins/xyd-plugin-zero/src/pages/docs.tsx +55 -25
  7. package/.cli/pnpm-lock.yaml +4425 -0
  8. package/package.json +17 -20
  9. package/postinstall.js +15 -0
  10. package/.cli/dist/index.js +0 -12417
  11. package/.cli/host/.react-router/types/app/+types/root.ts +0 -40
  12. package/.cli/host/node_modules/.vite/deps/@mdx-js_mdx.js +0 -81
  13. package/.cli/host/node_modules/.vite/deps/@mdx-js_mdx.js.map +0 -7
  14. package/.cli/host/node_modules/.vite/deps/@mdx-js_rollup.js +0 -4003
  15. package/.cli/host/node_modules/.vite/deps/@mdx-js_rollup.js.map +0 -7
  16. package/.cli/host/node_modules/.vite/deps/@radix-ui_react-icons.js +0 -7531
  17. package/.cli/host/node_modules/.vite/deps/@radix-ui_react-icons.js.map +0 -7
  18. package/.cli/host/node_modules/.vite/deps/@radix-ui_react-tabs.js +0 -917
  19. package/.cli/host/node_modules/.vite/deps/@radix-ui_react-tabs.js.map +0 -7
  20. package/.cli/host/node_modules/.vite/deps/_metadata.json +0 -157
  21. package/.cli/host/node_modules/.vite/deps/chunk-2TUXWMP5.js +0 -46
  22. package/.cli/host/node_modules/.vite/deps/chunk-2TUXWMP5.js.map +0 -7
  23. package/.cli/host/node_modules/.vite/deps/chunk-DNIFH2K7.js +0 -3461
  24. package/.cli/host/node_modules/.vite/deps/chunk-DNIFH2K7.js.map +0 -7
  25. package/.cli/host/node_modules/.vite/deps/chunk-ERHH4CDL.js +0 -23875
  26. package/.cli/host/node_modules/.vite/deps/chunk-ERHH4CDL.js.map +0 -7
  27. package/.cli/host/node_modules/.vite/deps/chunk-ETJV5QNK.js +0 -27
  28. package/.cli/host/node_modules/.vite/deps/chunk-ETJV5QNK.js.map +0 -7
  29. package/.cli/host/node_modules/.vite/deps/chunk-GPEJJ3KZ.js +0 -1906
  30. package/.cli/host/node_modules/.vite/deps/chunk-GPEJJ3KZ.js.map +0 -7
  31. package/.cli/host/node_modules/.vite/deps/chunk-IVP26VTC.js +0 -21
  32. package/.cli/host/node_modules/.vite/deps/chunk-IVP26VTC.js.map +0 -7
  33. package/.cli/host/node_modules/.vite/deps/chunk-MJUUSK53.js +0 -894
  34. package/.cli/host/node_modules/.vite/deps/chunk-MJUUSK53.js.map +0 -7
  35. package/.cli/host/node_modules/.vite/deps/chunk-NHN7DW4J.js +0 -928
  36. package/.cli/host/node_modules/.vite/deps/chunk-NHN7DW4J.js.map +0 -7
  37. package/.cli/host/node_modules/.vite/deps/chunk-OO6QDGMA.js +0 -10609
  38. package/.cli/host/node_modules/.vite/deps/chunk-OO6QDGMA.js.map +0 -7
  39. package/.cli/host/node_modules/.vite/deps/chunk-OUN4SSIE.js +0 -205
  40. package/.cli/host/node_modules/.vite/deps/chunk-OUN4SSIE.js.map +0 -7
  41. package/.cli/host/node_modules/.vite/deps/chunk-TKNG6GUJ.js +0 -894
  42. package/.cli/host/node_modules/.vite/deps/chunk-TKNG6GUJ.js.map +0 -7
  43. package/.cli/host/node_modules/.vite/deps/chunk-TM4FKLNO.js +0 -21628
  44. package/.cli/host/node_modules/.vite/deps/chunk-TM4FKLNO.js.map +0 -7
  45. package/.cli/host/node_modules/.vite/deps/chunk-V2IF7L2E.js +0 -12
  46. package/.cli/host/node_modules/.vite/deps/chunk-V2IF7L2E.js.map +0 -7
  47. package/.cli/host/node_modules/.vite/deps/gray-matter.js +0 -3492
  48. package/.cli/host/node_modules/.vite/deps/gray-matter.js.map +0 -7
  49. package/.cli/host/node_modules/.vite/deps/lucide-react.js +0 -34742
  50. package/.cli/host/node_modules/.vite/deps/lucide-react.js.map +0 -7
  51. package/.cli/host/node_modules/.vite/deps/package.json +0 -3
  52. package/.cli/host/node_modules/.vite/deps/react-dom.js +0 -7
  53. package/.cli/host/node_modules/.vite/deps/react-dom.js.map +0 -7
  54. package/.cli/host/node_modules/.vite/deps/react-dom_client.js +0 -39
  55. package/.cli/host/node_modules/.vite/deps/react-dom_client.js.map +0 -7
  56. package/.cli/host/node_modules/.vite/deps/react-router.js +0 -243
  57. package/.cli/host/node_modules/.vite/deps/react-router.js.map +0 -7
  58. package/.cli/host/node_modules/.vite/deps/react-router_dom.js +0 -212
  59. package/.cli/host/node_modules/.vite/deps/react-router_dom.js.map +0 -7
  60. package/.cli/host/node_modules/.vite/deps/react.js +0 -6
  61. package/.cli/host/node_modules/.vite/deps/react.js.map +0 -7
  62. package/.cli/host/node_modules/.vite/deps/react_jsx-dev-runtime.js +0 -913
  63. package/.cli/host/node_modules/.vite/deps/react_jsx-dev-runtime.js.map +0 -7
  64. package/.cli/host/node_modules/.vite/deps/react_jsx-runtime.js +0 -7
  65. package/.cli/host/node_modules/.vite/deps/react_jsx-runtime.js.map +0 -7
  66. package/.cli/host/node_modules/.vite/deps/remark-frontmatter.js +0 -428
  67. package/.cli/host/node_modules/.vite/deps/remark-frontmatter.js.map +0 -7
  68. package/.cli/host/node_modules/.vite/deps/remark-gfm.js +0 -3122
  69. package/.cli/host/node_modules/.vite/deps/remark-gfm.js.map +0 -7
  70. package/.cli/host/node_modules/.vite/deps/remark-mdx-frontmatter.js +0 -10482
  71. package/.cli/host/node_modules/.vite/deps/remark-mdx-frontmatter.js.map +0 -7
  72. package/.cli/host/node_modules/.vite/deps/unist-util-visit.js +0 -14
  73. package/.cli/host/node_modules/.vite/deps/unist-util-visit.js.map +0 -7
  74. package/.cli/host/node_modules/.vite/deps/vfile.js +0 -8
  75. package/.cli/host/node_modules/.vite/deps/vfile.js.map +0 -7
  76. package/.cli/host/package.json +0 -43
  77. package/bin.js +0 -3
  78. /package/.cli/{host/app → app}/root.tsx +0 -0
  79. /package/.cli/{host/app → app}/routes.ts +0 -0
  80. /package/.cli/{dist/index.d.ts → index.d.ts} +0 -0
  81. /package/.cli/{host/postcss.config.cjs → postcss.config.cjs} +0 -0
  82. /package/.cli/{host/react-router.config.ts → react-router.config.ts} +0 -0
  83. /package/.cli/{host/tsconfig.json → tsconfig.json} +0 -0
  84. /package/.cli/{host/vite.config.ts → vite.config.ts} +0 -0
@@ -0,0 +1,38 @@
1
+ {
2
+ "private": true,
3
+ "name": "@xyd-js/documan-host",
4
+ "version": "0.0.0",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "xyd": "bin.js"
9
+ },
10
+ "scripts": {},
11
+ "dependencies": {
12
+ "@xyd-js/theme-poetry": "0.1.0-xyd.22",
13
+ "@xyd-js/react-router-dev": "7.1.1-xyd.4",
14
+ "@readme/oas-to-snippet": "^26.0.1",
15
+ "@react-router/node": "7.1.1",
16
+ "@react-router/serve": "7.1.1",
17
+ "@react-router/dev": "7.1.1",
18
+ "react-router": "7.1.1",
19
+ "isbot": "^5",
20
+ "remark-frontmatter": "^5.0.0",
21
+ "remark-mdx-frontmatter": "^5.0.0",
22
+ "json-to-graphql-query": "^2.3.0",
23
+ "remark": "^15.0.1",
24
+ "unist-builder": "^4.0.0",
25
+ "oas": "^25.0.3",
26
+ "openapi-sampler": "^1.5.1",
27
+ "json-schema-ref-parser": "^9.0.9",
28
+ "typedoc": "^0.28.1"
29
+ },
30
+ "devDependencies": {
31
+ "@mdx-js/rollup": "^3.1.0",
32
+ "vite": "^5.4.9",
33
+ "semver": "^7.6.3",
34
+ "vite-tsconfig-paths": "^5.1.4",
35
+ "autoprefixer": "^10.4.20",
36
+ "postcss": "^8.4.47"
37
+ }
38
+ }
@@ -0,0 +1,312 @@
1
+ import path from "path";
2
+ import {promises as fs} from "fs";
3
+
4
+ import React, {} from "react";
5
+ import {redirect} from "react-router";
6
+ import remarkFrontmatter from "remark-frontmatter";
7
+ import remarkMdxFrontmatter from "remark-mdx-frontmatter";
8
+ import remarkGfm from "remark-gfm";
9
+ import {parse} from "codehike";
10
+ import {visit} from "unist-util-visit";
11
+ import {recmaCodeHike, remarkCodeHike} from "codehike/mdx";
12
+ import {compile as mdxCompile} from "@mdx-js/mdx";
13
+
14
+ import {PageFrontMatter} from "@xyd-js/core";
15
+ import getContentComponents from "@xyd-js/components/content";
16
+ import {mapSettingsToProps} from "@xyd-js/framework/hydration";
17
+ import {Framework, type FwSidebarGroupProps} from "@xyd-js/framework/react";
18
+ import {AtlasIndex} from "@xyd-js/atlas/atlas-index";
19
+ import type {IBreadcrumb, INavLinks} from "@xyd-js/ui";
20
+
21
+ import Theme from "virtual:xyd-theme" // TODO: for some reasons this cannot be hydrated by react-router
22
+ import settings from 'virtual:xyd-settings';
23
+
24
+ import "virtual:xyd-theme/index.css"
25
+ import "virtual:xyd-theme-override/index.css"
26
+
27
+ interface loaderData {
28
+ sidebarGroups: FwSidebarGroupProps[]
29
+ breadcrumbs: IBreadcrumb[],
30
+ navlinks?: INavLinks,
31
+ toc: PageFrontMatter
32
+ slug: string
33
+ code: string
34
+ }
35
+
36
+ const contentComponents = getContentComponents()
37
+
38
+ // since unist does not support heading level > 6, we need to normalize them
39
+ function normalizeCustomHeadings() {
40
+ return (tree: any) => {
41
+ visit(tree, 'paragraph', (node, index, parent) => {
42
+ if (!node.children[0].value) {
43
+ return
44
+ }
45
+ const match = node.children[0] && node.children[0].value.match(/^(#+)\s+(.*)/);
46
+ if (match) {
47
+ const level = match[1].length;
48
+ const text = match[2];
49
+ if (level > 6) {
50
+ // Create a new heading node with depth 6
51
+ const headingNode = {
52
+ type: 'heading',
53
+ depth: level,
54
+ children: [{type: 'text', value: text}]
55
+ };
56
+ // Replace the paragraph node with the new heading node
57
+ //@ts-ignore
58
+ parent.children[index] = headingNode;
59
+ }
60
+ }
61
+ });
62
+ };
63
+ }
64
+
65
+ const codeHikeOptions = {
66
+ lineNumbers: true,
67
+ showCopyButton: true,
68
+ autoImport: true,
69
+ components: {},
70
+ // syntaxHighlighting: { // TODO: !!! FROM SETTINGS !!! wait for rr7 rsc ??
71
+ // theme: "github-dark",
72
+ // },
73
+ };
74
+
75
+ const compiledBySlug = {}
76
+
77
+ // TODO: map every file and merge them or load via client-side ?
78
+ async function compileBySlug(slug: string) {
79
+ if (compiledBySlug[slug]) {
80
+ return compiledBySlug[slug]
81
+ }
82
+ console.time("api-reference compileBySlug")
83
+ // TODO: cwd ?
84
+ let filePath = path.join(process.cwd(), `${slug}.md`)
85
+
86
+ try {
87
+ await fs.access(filePath)
88
+ } catch (_) {
89
+ filePath = path.join(process.cwd(), `${slug}.mdx`)
90
+
91
+ await fs.access(filePath)
92
+ }
93
+
94
+ console.time("api-reference readFile")
95
+ const content = await fs.readFile(filePath, "utf-8");
96
+ console.timeEnd("api-reference readFile")
97
+
98
+ console.time("api-reference compile")
99
+ const resp = await compile(content)
100
+ console.timeEnd("api-reference compile")
101
+
102
+ console.timeEnd("api-reference compileBySlug")
103
+ compiledBySlug[slug] = resp
104
+ return resp
105
+ }
106
+
107
+ async function compile(content: string): Promise<string> {
108
+ const compiled = await mdxCompile(content, {
109
+ remarkPlugins: [
110
+ normalizeCustomHeadings,
111
+ [
112
+ remarkCodeHike,
113
+ codeHikeOptions
114
+ ],
115
+ remarkFrontmatter,
116
+ remarkMdxFrontmatter,
117
+ remarkGfm
118
+ ],
119
+ rehypePlugins: [],
120
+ recmaPlugins: [
121
+ [
122
+ recmaCodeHike,
123
+ codeHikeOptions
124
+ ]
125
+ ],
126
+ outputFormat: 'function-body',
127
+ development: false,
128
+ });
129
+
130
+ return String(compiled)
131
+ }
132
+
133
+ interface loaderData {
134
+ sidebarGroups: FwSidebarGroupProps[]
135
+ toc: PageFrontMatter
136
+ slug: string
137
+ code: string
138
+ }
139
+
140
+ function getPathname(url: string) {
141
+ const parsedUrl = new URL(url);
142
+ return parsedUrl.pathname.replace(/^\//, '');
143
+ }
144
+
145
+ // TODO: fix any
146
+ function findFirstUrl(items: any): string {
147
+ const queue = [...items];
148
+
149
+ while (queue.length > 0) {
150
+ const item = queue.shift();
151
+
152
+ if (item.href) {
153
+ return item.href;
154
+ }
155
+
156
+ if (item.items) {
157
+ queue.push(...item.items);
158
+ }
159
+ }
160
+
161
+ return "";
162
+ }
163
+
164
+ interface data {
165
+ groups: FwSidebarGroupProps[],
166
+ breadcrumbs: IBreadcrumb[]
167
+ navlinks?: INavLinks
168
+ }
169
+
170
+ const mapSettingsToPropsMap: { [key: string]: data } = {}
171
+
172
+ // TODO: fix any
173
+ export async function loader({request}: { request: any }) {
174
+ console.time("api-reference loader")
175
+ const slug = getPathname(request.url);
176
+
177
+ let code = "";
178
+ let error: any;
179
+
180
+ try {
181
+ code = await compileBySlug(slug);
182
+ } catch (e) {
183
+ error = e;
184
+ }
185
+ let data: data
186
+
187
+ if (!mapSettingsToPropsMap[slug]) {
188
+ data = await mapSettingsToProps(
189
+ settings,
190
+ slug
191
+ );
192
+ mapSettingsToPropsMap[slug] = data
193
+ } else {
194
+ data = mapSettingsToPropsMap[slug]
195
+ }
196
+
197
+ const {groups: sidebarGroups, breadcrumbs, navlinks} = data;
198
+
199
+ if (error) {
200
+ if (sidebarGroups && error.code === "ENOENT") {
201
+ const firstItem = findFirstUrl(sidebarGroups?.[0]?.items);
202
+
203
+ if (firstItem) {
204
+ return redirect(firstItem);
205
+ }
206
+ }
207
+
208
+ console.error(error);
209
+ }
210
+
211
+ console.timeEnd("api-reference loader")
212
+ return {
213
+ sidebarGroups,
214
+ breadcrumbs,
215
+ navlinks,
216
+ slug,
217
+ code,
218
+ } as loaderData;
219
+ }
220
+
221
+ function mdxExport(code: string) {
222
+ const scope = {
223
+ Fragment: React.Fragment,
224
+ jsxs: React.createElement,
225
+ jsx: React.createElement,
226
+ jsxDEV: React.createElement,
227
+ }
228
+ const fn = new Function(...Object.keys(scope), code)
229
+ return fn(scope)
230
+ }
231
+
232
+ function MemoMDXComponent(codeComponent: any) {
233
+ return React.useMemo(
234
+ () => codeComponent ? codeComponent : null,
235
+ [codeComponent]
236
+ )
237
+ }
238
+
239
+ // // TODO: move to content?
240
+ function mdxContent(code: string) {
241
+ const content = mdxExport(code) // TODO: fix any
242
+ if (!mdxExport) {
243
+ return {}
244
+ }
245
+
246
+ return {
247
+ component: content?.default,
248
+ }
249
+ }
250
+
251
+ // TODO: below is a concept only
252
+ // class MyThemeSettings extends BaseThemeSettings {
253
+ // private constructor() {
254
+ // super();
255
+ //
256
+ // this.toc.hide(true)
257
+ // this.sidebar.clientSideRouting(true)
258
+ // this.layout.size("large")
259
+ // }
260
+ //
261
+ // override abc() {
262
+ //
263
+ // }
264
+ //
265
+ // static new() {
266
+ // return new MyThemeSettings()
267
+ // }
268
+ // }
269
+
270
+
271
+ // TODO: below is a concept only
272
+ // const themeSettings = new ThemeSettings()
273
+ // .toc.hide()
274
+ // .sidebar({
275
+ // clientSideRouting: true
276
+ // })
277
+ // .layout.size("large")
278
+
279
+ // TODO: in the future more smoother loader - first fast server render then move to ideal position of client and then replace and 3 items at start
280
+ export default function APIReference({loaderData}: { loaderData: loaderData }) {
281
+ const content = mdxContent(loaderData.code)
282
+ const serverComponent = content ? parse(content.component, {
283
+ components: contentComponents
284
+ }) : null
285
+
286
+ const memoizedServerComponent = MemoMDXComponent(serverComponent)
287
+
288
+ console.log("memoizedServerComponent", memoizedServerComponent)
289
+
290
+ return <Framework
291
+ settings={settings}
292
+ sidebarGroups={loaderData.sidebarGroups || []}
293
+ breadcrumbs={loaderData.breadcrumbs || []}
294
+ navlinks={loaderData.navlinks}
295
+ >
296
+ <Theme
297
+ themeSettings={{
298
+ hideToc: true,
299
+ sidebar: {
300
+ clientSideRouting: true
301
+ },
302
+ layout: {
303
+ size: "large"
304
+ }
305
+ }}
306
+ >
307
+ <AtlasIndex
308
+ data={memoizedServerComponent?.references[0]}
309
+ />
310
+ </Theme>
311
+ </Framework>
312
+ }