@xyd-js/plugin-docs 0.1.0-xyd.3 → 0.1.0-xyd.44

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/package.json CHANGED
@@ -1,38 +1,49 @@
1
1
  {
2
2
  "name": "@xyd-js/plugin-docs",
3
- "version": "0.1.0-xyd.3",
3
+ "version": "0.1.0-xyd.44",
4
4
  "description": "",
5
5
  "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ "./package.json": "./package.json",
10
+ ".": "./dist/index.js"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "src",
15
+ "package.json"
16
+ ],
6
17
  "dependencies": {
7
18
  "codehike": "^1.0.3",
8
19
  "@code-hike/lighter": "^1.0.3",
9
- "@xyd-js/uniform": "0.1.0-xyd.17",
10
- "@xyd-js/sources": "0.1.1-xyd.5",
11
- "@xyd-js/gql": "0.1.0-xyd.15",
12
- "@xyd-js/openapi": "0.1.0-xyd.13"
20
+ "@xyd-js/openapi": "0.1.0-xyd.52",
21
+ "@xyd-js/gql": "0.1.0-xyd.54",
22
+ "@xyd-js/uniform": "0.1.0-xyd.56",
23
+ "@xyd-js/sources": "0.1.1-xyd.44"
13
24
  },
14
25
  "peerDependencies": {
15
- "@react-router/dev": "^7.5.0",
16
- "@react-router/node": "^7.5.0",
17
- "@react-router/serve": "^7.5.0",
18
- "react": "^19.0.0",
19
- "react-dom": "^19.0.0",
20
- "react-router": "^7.5.0",
21
- "@xyd-js/framework": "0.1.0-xyd.34",
22
- "@xyd-js/composer": "0.1.0-xyd.2",
23
- "@xyd-js/themes": "0.1.1-xyd.5",
24
- "@xyd-js/components": "0.1.0-xyd.13",
25
- "@xyd-js/content": "0.1.0-xyd.16",
26
- "@xyd-js/core": "0.1.0-xyd.15"
26
+ "@react-router/dev": "^7.6.2",
27
+ "@react-router/node": "^7.6.2",
28
+ "@react-router/serve": "^7.6.2",
29
+ "react": "^19.1.0",
30
+ "react-dom": "^19.1.0",
31
+ "react-router": "^7.6.2",
32
+ "@xyd-js/framework": "0.1.0-xyd.73",
33
+ "@xyd-js/composer": "0.1.0-xyd.41",
34
+ "@xyd-js/themes": "0.1.1-xyd.44",
35
+ "@xyd-js/content": "0.1.0-xyd.55",
36
+ "@xyd-js/components": "0.1.0-xyd.52",
37
+ "@xyd-js/core": "0.1.0-xyd.54"
27
38
  },
28
39
  "devDependencies": {
29
- "@types/react-dom": "^19.0.0",
30
- "@types/react": "^19.0.0",
40
+ "@types/react-dom": "^19.1.0",
41
+ "@types/react": "^19.1.0",
31
42
  "@vitejs/plugin-react": "^4.3.2",
32
43
  "tsup": "^8.3.0",
33
44
  "typescript": "^5.6.2",
34
- "vite": "^6.1.0",
35
- "vite-tsconfig-paths": "^5.0.1",
45
+ "vite": "^7.0.0",
46
+ "vite-tsconfig-paths": "^5.1.4",
36
47
  "rimraf": "^3.0.2"
37
48
  },
38
49
  "scripts": {
@@ -20,4 +20,10 @@ declare module 'virtual:xyd-theme' {
20
20
  constructor();
21
21
  }
22
22
  export default ConcreteTheme;
23
- }
23
+ }
24
+ declare module 'virtual:xyd-user-components' {
25
+ const components: any
26
+ export {
27
+ components
28
+ }
29
+ }
@@ -1,4 +1,4 @@
1
- import { useMemo } from "react";
1
+ import {useMemo} from "react";
2
2
  import {
3
3
  Outlet,
4
4
  useLoaderData,
@@ -8,41 +8,50 @@ import {
8
8
  useMatches
9
9
  } from "react-router";
10
10
 
11
- import { mapSettingsToProps } from "@xyd-js/framework/hydration";
11
+ import {mapSettingsToProps} from "@xyd-js/framework/hydration";
12
12
 
13
- import type { Metadata, MetadataMap, Theme as ThemeSettings } from "@xyd-js/core";
14
- import type { INavLinks, IBreadcrumb } from "@xyd-js/ui";
15
- import { Framework, FwLink, useSettings, type FwSidebarGroupProps } from "@xyd-js/framework/react";
16
- import { ReactContent } from "@xyd-js/components/content";
17
- import { Atlas, AtlasContext, type VariantToggleConfig } from "@xyd-js/atlas";
13
+ import type {Metadata, MetadataMap, Theme as ThemeSettings} from "@xyd-js/core";
14
+ import type {INavLinks, IBreadcrumb} from "@xyd-js/ui";
15
+ import {Framework, FwLink, useSettings, type FwSidebarGroupProps} from "@xyd-js/framework/react";
16
+ import {ReactContent} from "@xyd-js/components/content";
17
+ import {Atlas, AtlasContext, type VariantToggleConfig} from "@xyd-js/atlas";
18
18
  import AtlasXydPlugin from "@xyd-js/atlas/xydPlugin";
19
19
 
20
- import { Surfaces } from "@xyd-js/framework/react";
21
- import { Composer } from "@xyd-js/composer";
20
+ import {Surfaces} from "@xyd-js/framework";
21
+ import {Composer} from "@xyd-js/composer";
22
+ import {XYDAnalytics} from "@xyd-js/analytics";
22
23
  // @ts-ignore
23
- import { iconSet } from 'virtual:xyd-icon-set';
24
+ import {iconSet} from 'virtual:xyd-icon-set';
24
25
 
25
26
  // @ts-ignore
26
27
  import virtualSettings from "virtual:xyd-settings";
27
- // @ts-ignore
28
- const { settings: getSettings } = virtualSettings
28
+ // @ts-ignores
29
+ const {settings: getSettings} = virtualSettings
29
30
  // const settings = globalThis.__xydSettings
30
31
  import Theme from "virtual:xyd-theme";
32
+ // @ts-ignore
33
+ import {loadProvider} from 'virtual:xyd-analytics-providers'
31
34
 
32
35
  // @ts-ignore
33
36
  import "virtual:xyd-theme/index.css"
34
37
  import "virtual:xyd-theme-override/index.css"
35
38
 
36
- import { PageContext } from "./context";
39
+ // @ts-ignore
40
+ import {components as userComponents} from 'virtual:xyd-user-components';
41
+
42
+ import {PageContext} from "./context";
37
43
  import React from "react";
38
- import { markdownPlugins } from "@xyd-js/content/md";
39
- import { ContentFS } from "@xyd-js/content";
40
- import { IconProvider } from "@xyd-js/components/writer";
41
- import { CoderProvider } from "@xyd-js/components/coder";
44
+
45
+ import {markdownPlugins} from "@xyd-js/content/md";
46
+ import {ContentFS} from "@xyd-js/content";
47
+ import {IconProvider} from "@xyd-js/components/writer";
48
+ import {CoderProvider} from "@xyd-js/components/coder";
49
+ import {SearchButton} from "@xyd-js/components/system"
42
50
 
43
51
  globalThis.__xydSettings = getSettings
52
+ globalThis.__xydUserComponents = userComponents // Add user components to global scope TODO: problematic
44
53
 
45
- new Composer() // TODO: better API
54
+ new Composer() // TODO: better API TODO: problematic
46
55
  const settings = globalThis.__xydSettings
47
56
 
48
57
  const surfaces = new Surfaces()
@@ -71,7 +80,8 @@ globalThis.__xydSurfaces = surfaces
71
80
 
72
81
  const theme = new Theme()
73
82
 
74
- const { Layout: BaseThemeLayout } = theme
83
+ const {Layout: BaseThemeLayout} = theme
84
+
75
85
 
76
86
  interface LoaderData {
77
87
  sidebarGroups: FwSidebarGroupProps[]
@@ -83,7 +93,7 @@ interface LoaderData {
83
93
  bannerContentCode?: string
84
94
  }
85
95
 
86
- export async function loader({ request }: { request: any }) {
96
+ export async function loader({request}: { request: any }) {
87
97
  const slug = getPathname(request.url || "index") || "index"
88
98
 
89
99
  const {
@@ -131,12 +141,12 @@ export default function Layout() {
131
141
  // TODO: BETTER HANDLE THAT
132
142
  if (loaderData.metadata?.openapi) {
133
143
  atlasVariantToggles = [
134
- { key: "status", defaultValue: "200" },
135
- { key: "contentType", defaultValue: "application/json" }
144
+ {key: "status", defaultValue: "200"},
145
+ {key: "contentType", defaultValue: "application/json"}
136
146
  ];
137
147
  } else {
138
148
  atlasVariantToggles = [
139
- { key: "symbolName", defaultValue: "" }
149
+ {key: "symbolName", defaultValue: ""}
140
150
  ];
141
151
  }
142
152
 
@@ -147,38 +157,49 @@ export default function Layout() {
147
157
  const BannerContent = MemoMDXComponent(content.component)
148
158
 
149
159
  bannerContent = function () {
150
- return <BannerContent components={theme.reactContentComponents()} />
160
+ return <BannerContent components={theme.reactContentComponents()}/>
151
161
  }
152
162
  }
153
163
 
164
+ const userComponents = (globalThis.__xydUserComponents || []).reduce((acc, component) => {
165
+ acc[component.name] = component.component;
166
+ return acc;
167
+ }, {});
168
+
154
169
  return <>
155
- <IconProvider value={{
156
- iconSet: iconSet
157
- }}>
158
- <Framework
159
- settings={settings || globalThis.__xydSettings}
160
- sidebarGroups={loaderData.sidebarGroups || []}
161
- metadata={loaderData.metadata || {}}
162
- surfaces={surfaces}
163
- BannerContent={bannerContent}
164
- >
165
- <AtlasContext
166
- value={{
167
- syntaxHighlight: settings?.theme?.coder?.syntaxHighlight || null,
168
- baseMatch: lastMatchId || "",
169
- variantToggles: atlasVariantToggles
170
+ <XYDAnalytics settings={settings} loader={loadProvider}>
171
+ <IconProvider value={{
172
+ iconSet: iconSet
173
+ }}>
174
+ <Framework
175
+ settings={settings || globalThis.__xydSettings}
176
+ sidebarGroups={loaderData.sidebarGroups || []}
177
+ metadata={loaderData.metadata || {}}
178
+ surfaces={surfaces}
179
+ BannerContent={bannerContent}
180
+ components={{
181
+ Search: SearchButton,
182
+ ...userComponents
170
183
  }}
171
184
  >
172
- <CoderProvider lines={settings?.theme?.coder?.lines} scroll={settings?.theme?.coder?.scroll}>
173
- <BaseThemeLayout>
174
- <PageContext value={{ theme }}>
175
- <Outlet />
176
- </PageContext>
177
- </BaseThemeLayout>
178
- </CoderProvider>
179
- </AtlasContext>
180
- </Framework>
181
- </IconProvider>
185
+ <AtlasContext
186
+ value={{
187
+ syntaxHighlight: settings?.theme?.coder?.syntaxHighlight || null,
188
+ baseMatch: lastMatchId || "",
189
+ variantToggles: atlasVariantToggles
190
+ }}
191
+ >
192
+ <CoderProvider lines={settings?.theme?.coder?.lines} scroll={settings?.theme?.coder?.scroll}>
193
+ <BaseThemeLayout>
194
+ <PageContext value={{theme}}>
195
+ <Outlet/>
196
+ </PageContext>
197
+ </BaseThemeLayout>
198
+ </CoderProvider>
199
+ </AtlasContext>
200
+ </Framework>
201
+ </IconProvider>
202
+ </XYDAnalytics>
182
203
  </>
183
204
  }
184
205
 
@@ -221,7 +242,7 @@ const createElementWithKeys = (type: any, props: any) => {
221
242
  return childrenArray.map((child, index) => {
222
243
  // If the child is a React element and doesn't have a key, add one
223
244
  if (React.isValidElement(child) && !child.key) {
224
- return React.cloneElement(child, { key: `mdx-${index}` });
245
+ return React.cloneElement(child, {key: `mdx-${index}`});
225
246
  }
226
247
  // If the child is an array, process it recursively
227
248
  if (Array.isArray(child)) {
@@ -239,7 +260,7 @@ const createElementWithKeys = (type: any, props: any) => {
239
260
  processedChildren = processChildren(props.children);
240
261
  } else if (React.isValidElement(props.children) && !props.children.key) {
241
262
  // Single child without key
242
- processedChildren = React.cloneElement(props.children, { key: 'mdx-child' });
263
+ processedChildren = React.cloneElement(props.children, {key: 'mdx-child'});
243
264
  } else {
244
265
  // Single child with key or non-React element
245
266
  processedChildren = props.children;
@@ -360,4 +360,3 @@ export default function DocsPage({ loaderData }: { loaderData: loaderData }) {
360
360
  </FrameworkPage>
361
361
  }
362
362
 
363
-
@@ -43,7 +43,7 @@ function preinstall() {
43
43
  name: DEFAULT_THEME
44
44
  }
45
45
  }
46
-
46
+
47
47
  let themeRoutesExists = false
48
48
  try {
49
49
  await fs.access(path.join(root, THEME_CONFIG_FOLDER, "./routes.ts"))
@@ -68,30 +68,85 @@ function preinstall() {
68
68
  }
69
69
 
70
70
  // TODO: maybe later as a separate plugin?
71
+ // function vitePluginSettings() {
72
+ // return async function ({ preinstall }): Promise<VitePlugin> {
73
+ // return {
74
+ // name: 'virtual:xyd-settings',
75
+ // resolveId(id) {
76
+ // if (id === 'virtual:xyd-settings') {
77
+ // return id + '.jsx'; // Return the module with .jsx extension
78
+ // }
79
+ // return null;
80
+ // },
81
+ // async load(id) { // TODO: better cuz we probably dont neeed `get settings()`
82
+ // if (id === 'virtual:xyd-settings.jsx') {
83
+ // return `
84
+ // export default {
85
+ // get settings() {
86
+ // return globalThis.__xydSettings || ${typeof preinstall.settings === "string" ? preinstall.settings : JSON.stringify(preinstall.settings)}
87
+ // }
88
+ // }
89
+ // `
90
+ // }
91
+ // return null;
92
+ // },
93
+ // };
94
+ // }
95
+ // }
96
+
97
+
71
98
  function vitePluginSettings() {
72
99
  return async function ({ preinstall }): Promise<VitePlugin> {
100
+ const virtualId = 'virtual:xyd-settings';
101
+ const resolvedId = virtualId + '.jsx';
102
+
103
+ let currentSettings = globalThis.__xydSettings
104
+ if (!currentSettings && preinstall?.settings) {
105
+ currentSettings = typeof preinstall?.settings === "string" ? preinstall?.settings : JSON.stringify(preinstall?.settings || {})
106
+ }
107
+
73
108
  return {
74
- name: 'virtual:xyd-settings',
109
+ name: 'xyd:virtual-settings',
110
+
75
111
  resolveId(id) {
76
- if (id === 'virtual:xyd-settings') {
77
- return id + '.jsx'; // Return the module with .jsx extension
112
+ if (id === virtualId) {
113
+ return resolvedId;
78
114
  }
79
115
  return null;
80
116
  },
117
+
118
+
81
119
  async load(id) { // TODO: better cuz we probably dont neeed `get settings()`
82
120
  if (id === 'virtual:xyd-settings.jsx') {
83
121
  return `
84
- export default {
85
- get settings() {
86
- return globalThis.__xydSettings || ${typeof preinstall.settings === "string" ? preinstall.settings : JSON.stringify(preinstall.settings)}
122
+ export default {
123
+ get settings() {
124
+ return globalThis.__xydSettings || ${typeof preinstall.settings === "string" ? preinstall.settings : JSON.stringify(preinstall.settings)}
87
125
  }
88
126
  }
89
127
  `
90
128
  }
91
129
  return null;
92
130
  },
131
+
132
+ async hotUpdate(ctx) {
133
+ const isPageFileChanged = ctx.file.includes('xyd-plugin-docs/src/pages/layout.tsx')
134
+ || ctx.file.includes('xyd-plugin-docs/src/pages/page.tsx')
135
+
136
+ if (!isPageFileChanged) {
137
+ return
138
+ }
139
+
140
+ const newSettings = await readSettings();
141
+ if (!newSettings) {
142
+ return
143
+ }
144
+
145
+ globalThis.__xydSettings = newSettings;
146
+ },
93
147
  };
94
148
  }
149
+
95
150
  }
96
151
 
97
152
 
@@ -67,7 +67,7 @@ export async function readSettings() {
67
67
 
68
68
  return json
69
69
  } catch (e) {
70
- console.error(e)
70
+ console.error("⚠️ Error parsing settings file")
71
71
 
72
72
  return null
73
73
  }
package/CHANGELOG.md DELETED
@@ -1,41 +0,0 @@
1
- # @xyd-js/plugin-docs
2
-
3
- ## 0.1.0-xyd.3
4
-
5
- ### Patch Changes
6
-
7
- - documan + plugin-docs
8
-
9
- ## 0.1.0-xyd.2
10
-
11
- ### Patch Changes
12
-
13
- - test
14
- - Updated dependencies
15
- - @xyd-js/components@0.1.0-xyd.13
16
- - @xyd-js/composer@0.1.0-xyd.2
17
- - @xyd-js/content@0.1.0-xyd.16
18
- - @xyd-js/core@0.1.0-xyd.15
19
- - @xyd-js/framework@0.1.0-xyd.34
20
- - @xyd-js/gql@0.1.0-xyd.15
21
- - @xyd-js/openapi@0.1.0-xyd.13
22
- - @xyd-js/sources@0.1.1-xyd.5
23
- - @xyd-js/themes@0.1.1-xyd.5
24
- - @xyd-js/uniform@0.1.0-xyd.17
25
-
26
- ## 0.1.0-xyd.1
27
-
28
- ### Patch Changes
29
-
30
- - update packages
31
- - Updated dependencies
32
- - @xyd-js/components@0.1.0-xyd.12
33
- - @xyd-js/composer@0.1.0-xyd.1
34
- - @xyd-js/content@0.1.0-xyd.15
35
- - @xyd-js/core@0.1.0-xyd.14
36
- - @xyd-js/framework@0.1.0-xyd.33
37
- - @xyd-js/gql@0.1.0-xyd.14
38
- - @xyd-js/openapi@0.1.0-xyd.12
39
- - @xyd-js/sources@0.1.1-xyd.4
40
- - @xyd-js/themes@0.1.1-xyd.4
41
- - @xyd-js/uniform@0.1.0-xyd.16
package/TODO.md DELETED
@@ -1 +0,0 @@
1
- 1. better API
package/tsconfig.json DELETED
@@ -1,51 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "paths": {
4
- "@xyd-js/atlas": [
5
- "../xyd-atlas"
6
- ],
7
- "@xyd-js/core": [
8
- "../xyd-core/index.ts"
9
- ],
10
- "@xyd-js/themes": [
11
- "../xyd-themes/src/index.ts"
12
- ],
13
- "@xyd-js/components/content": [
14
- "../xyd-components/content.ts"
15
- ],
16
- "@xyd-js/framework/react": [
17
- "../xyd-framework/packages/react/index.ts"
18
- ]
19
- },
20
- "types": [
21
- "unplugin-icons/types/react"
22
- ],
23
- "module": "esnext",
24
- "esModuleInterop": true,
25
- "moduleResolution": "bundler",
26
- "target": "esnext",
27
- "baseUrl": ".",
28
- "lib": [
29
- "dom",
30
- "dom.iterable",
31
- "esnext"
32
- ],
33
- "allowJs": true,
34
- "skipLibCheck": true,
35
- "strict": false,
36
- "noEmit": true,
37
- "incremental": false,
38
- "resolveJsonModule": true,
39
- "isolatedModules": true,
40
- "jsx": "preserve",
41
- "plugins": [],
42
- "strictNullChecks": true
43
- },
44
- "include": [
45
- "src/**/*.ts",
46
- "src/**/*.tsx"
47
- ],
48
- "exclude": [
49
- "node_modules"
50
- ]
51
- }
package/tsup.config.ts DELETED
@@ -1,74 +0,0 @@
1
- import {defineConfig, Options} from 'tsup';
2
-
3
- import pkg from './package.json';
4
-
5
- const deps = [
6
- ...Object.keys(pkg.dependencies || {}),
7
- ...Object.keys(pkg.devDependencies || {}),
8
- ].filter((dep) => [
9
-
10
- ].indexOf(dep) === -1)
11
-
12
- const config: Options = {
13
- entry: {
14
- index: 'src/index.ts',
15
- },
16
- dts: {
17
- entry: {
18
- index: 'src/index.ts',
19
- },
20
- resolve: true, // Resolve external types
21
- },
22
- format: ['esm'],
23
- platform: 'node',
24
- shims: false,
25
- splitting: false,
26
- sourcemap: true,
27
- clean: true,
28
- external: [
29
- ...deps,
30
-
31
- // "@graphql-markdown/core": "^1.12.0",
32
- // "@graphql-markdown/graphql": "^1.1.4",
33
- // "@graphql-markdown/types": "^1.4.0",
34
- // "graphql-config": "^5.1.2",
35
- // "gray-matter": "^4.0.3",
36
- // "json-to-graphql-query": "^2.3.0"
37
-
38
- // Externalize gql modules
39
- // '@graphql-markdown/core',
40
- // '@graphql-markdown/graphql',
41
- // '@graphql-markdown/types',
42
- // 'graphql-config',
43
- // 'gray-matter',
44
- // 'json-to-graphql-query',
45
-
46
- // Externalize Node.js built-in modules
47
- /^node:.*/,
48
- 'fs',
49
- 'path',
50
- 'url',
51
- 'os',
52
- 'http',
53
- 'https',
54
- 'stream',
55
- 'zlib',
56
- 'util',
57
- 'crypto',
58
- 'tty',
59
- // Add other built-in modules as needed
60
- ],
61
- esbuildPlugins: [
62
- {
63
- name: 'external-node-builtins',
64
- setup(build) {
65
- const filter = /^node:/;
66
- build.onResolve({filter}, args => {
67
- return {path: args.path, external: true};
68
- });
69
- },
70
- },
71
- ],
72
- }
73
-
74
- export default defineConfig(config);