@xyd-js/plugin-docs 0.1.0-xyd.5 → 0.1.0-xyd.86

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyd-js/plugin-docs",
3
- "version": "0.1.0-xyd.5",
3
+ "version": "0.1.0-xyd.86",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -17,33 +17,33 @@
17
17
  "dependencies": {
18
18
  "codehike": "^1.0.3",
19
19
  "@code-hike/lighter": "^1.0.3",
20
- "@xyd-js/openapi": "0.1.0-xyd.13",
21
- "@xyd-js/gql": "0.1.0-xyd.15",
22
- "@xyd-js/sources": "0.1.1-xyd.5",
23
- "@xyd-js/uniform": "0.1.0-xyd.17"
20
+ "@xyd-js/openapi": "0.1.0-xyd.94",
21
+ "@xyd-js/sources": "0.1.1-xyd.86",
22
+ "@xyd-js/gql": "0.1.0-xyd.96",
23
+ "@xyd-js/uniform": "0.1.0-xyd.98"
24
24
  },
25
25
  "peerDependencies": {
26
- "@react-router/dev": "^7.5.0",
27
- "@react-router/node": "^7.5.0",
28
- "@react-router/serve": "^7.5.0",
29
- "react": "^19.0.0",
30
- "react-dom": "^19.0.0",
31
- "react-router": "^7.5.0",
32
- "@xyd-js/framework": "0.1.0-xyd.34",
33
- "@xyd-js/components": "0.1.0-xyd.13",
34
- "@xyd-js/composer": "0.1.0-xyd.2",
35
- "@xyd-js/themes": "0.1.1-xyd.5",
36
- "@xyd-js/content": "0.1.0-xyd.16",
37
- "@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.115",
33
+ "@xyd-js/composer": "0.1.0-xyd.83",
34
+ "@xyd-js/content": "0.1.0-xyd.97",
35
+ "@xyd-js/components": "0.1.0-xyd.94",
36
+ "@xyd-js/themes": "0.1.1-xyd.86",
37
+ "@xyd-js/core": "0.1.0-xyd.96"
38
38
  },
39
39
  "devDependencies": {
40
- "@types/react-dom": "^19.0.0",
41
- "@types/react": "^19.0.0",
40
+ "@types/react-dom": "^19.1.0",
41
+ "@types/react": "^19.1.0",
42
42
  "@vitejs/plugin-react": "^4.3.2",
43
43
  "tsup": "^8.3.0",
44
44
  "typescript": "^5.6.2",
45
- "vite": "^6.1.0",
46
- "vite-tsconfig-paths": "^5.0.1",
45
+ "vite": "^7.0.0",
46
+ "vite-tsconfig-paths": "^5.1.4",
47
47
  "rimraf": "^3.0.2"
48
48
  },
49
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,49 @@ 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
46
54
  const settings = globalThis.__xydSettings
47
55
 
48
56
  const surfaces = new Surfaces()
@@ -71,7 +79,8 @@ globalThis.__xydSurfaces = surfaces
71
79
 
72
80
  const theme = new Theme()
73
81
 
74
- const { Layout: BaseThemeLayout } = theme
82
+ const {Layout: BaseThemeLayout} = theme
83
+
75
84
 
76
85
  interface LoaderData {
77
86
  sidebarGroups: FwSidebarGroupProps[]
@@ -83,7 +92,9 @@ interface LoaderData {
83
92
  bannerContentCode?: string
84
93
  }
85
94
 
86
- export async function loader({ request }: { request: any }) {
95
+ export async function loader({request}: { request: any }) {
96
+ new Composer() // TODO: better API
97
+
87
98
  const slug = getPathname(request.url || "index") || "index"
88
99
 
89
100
  const {
@@ -131,12 +142,12 @@ export default function Layout() {
131
142
  // TODO: BETTER HANDLE THAT
132
143
  if (loaderData.metadata?.openapi) {
133
144
  atlasVariantToggles = [
134
- { key: "status", defaultValue: "200" },
135
- { key: "contentType", defaultValue: "application/json" }
145
+ {key: "status", defaultValue: "200"},
146
+ {key: "contentType", defaultValue: "application/json"}
136
147
  ];
137
148
  } else {
138
149
  atlasVariantToggles = [
139
- { key: "symbolName", defaultValue: "" }
150
+ {key: "symbolName", defaultValue: ""}
140
151
  ];
141
152
  }
142
153
 
@@ -147,38 +158,49 @@ export default function Layout() {
147
158
  const BannerContent = MemoMDXComponent(content.component)
148
159
 
149
160
  bannerContent = function () {
150
- return <BannerContent components={theme.reactContentComponents()} />
161
+ return <BannerContent components={theme.reactContentComponents()}/>
151
162
  }
152
163
  }
153
164
 
165
+ const userComponents = (globalThis.__xydUserComponents || []).reduce((acc, component) => {
166
+ acc[component.name] = component.component;
167
+ return acc;
168
+ }, {});
169
+
154
170
  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
171
+ <XYDAnalytics settings={settings} loader={loadProvider}>
172
+ <IconProvider value={{
173
+ iconSet: iconSet
174
+ }}>
175
+ <Framework
176
+ settings={settings || globalThis.__xydSettings}
177
+ sidebarGroups={loaderData.sidebarGroups || []}
178
+ metadata={loaderData.metadata || {}}
179
+ surfaces={surfaces}
180
+ BannerContent={bannerContent}
181
+ components={{
182
+ Search: SearchButton,
183
+ ...userComponents
170
184
  }}
171
185
  >
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>
186
+ <AtlasContext
187
+ value={{
188
+ syntaxHighlight: settings?.theme?.coder?.syntaxHighlight || null,
189
+ baseMatch: lastMatchId || "",
190
+ variantToggles: atlasVariantToggles
191
+ }}
192
+ >
193
+ <CoderProvider lines={settings?.theme?.coder?.lines} scroll={settings?.theme?.coder?.scroll}>
194
+ <BaseThemeLayout>
195
+ <PageContext value={{theme}}>
196
+ <Outlet/>
197
+ </PageContext>
198
+ </BaseThemeLayout>
199
+ </CoderProvider>
200
+ </AtlasContext>
201
+ </Framework>
202
+ </IconProvider>
203
+ </XYDAnalytics>
182
204
  </>
183
205
  }
184
206
 
@@ -221,7 +243,7 @@ const createElementWithKeys = (type: any, props: any) => {
221
243
  return childrenArray.map((child, index) => {
222
244
  // If the child is a React element and doesn't have a key, add one
223
245
  if (React.isValidElement(child) && !child.key) {
224
- return React.cloneElement(child, { key: `mdx-${index}` });
246
+ return React.cloneElement(child, {key: `mdx-${index}`});
225
247
  }
226
248
  // If the child is an array, process it recursively
227
249
  if (Array.isArray(child)) {
@@ -239,7 +261,7 @@ const createElementWithKeys = (type: any, props: any) => {
239
261
  processedChildren = processChildren(props.children);
240
262
  } else if (React.isValidElement(props.children) && !props.children.key) {
241
263
  // Single child without key
242
- processedChildren = React.cloneElement(props.children, { key: 'mdx-child' });
264
+ processedChildren = React.cloneElement(props.children, {key: 'mdx-child'});
243
265
  } else {
244
266
  // Single child with key or non-React element
245
267
  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
  }