@xyd-js/plugin-docs 0.1.0-xyd.5 → 0.1.0-xyd.56
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/index.js +24 -7
- package/dist/index.js.map +1 -1
- package/package.json +21 -21
- package/src/declarations.d.ts +7 -1
- package/src/pages/layout.tsx +72 -51
- package/src/pages/page.tsx +0 -1
- package/src/presets/docs/index.ts +62 -7
- package/src/presets/docs/settings.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyd-js/plugin-docs",
|
|
3
|
-
"version": "0.1.0-xyd.
|
|
3
|
+
"version": "0.1.0-xyd.56",
|
|
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/
|
|
21
|
-
"@xyd-js/
|
|
22
|
-
"@xyd-js/
|
|
23
|
-
"@xyd-js/uniform": "0.1.0-xyd.
|
|
20
|
+
"@xyd-js/gql": "0.1.0-xyd.66",
|
|
21
|
+
"@xyd-js/sources": "0.1.1-xyd.56",
|
|
22
|
+
"@xyd-js/openapi": "0.1.0-xyd.64",
|
|
23
|
+
"@xyd-js/uniform": "0.1.0-xyd.68"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@react-router/dev": "^7.
|
|
27
|
-
"@react-router/node": "^7.
|
|
28
|
-
"@react-router/serve": "^7.
|
|
29
|
-
"react": "^19.
|
|
30
|
-
"react-dom": "^19.
|
|
31
|
-
"react-router": "^7.
|
|
32
|
-
"@xyd-js/
|
|
33
|
-
"@xyd-js/
|
|
34
|
-
"@xyd-js/
|
|
35
|
-
"@xyd-js/
|
|
36
|
-
"@xyd-js/
|
|
37
|
-
"@xyd-js/core": "0.1.0-xyd.
|
|
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/themes": "0.1.1-xyd.56",
|
|
33
|
+
"@xyd-js/composer": "0.1.0-xyd.53",
|
|
34
|
+
"@xyd-js/content": "0.1.0-xyd.67",
|
|
35
|
+
"@xyd-js/framework": "0.1.0-xyd.85",
|
|
36
|
+
"@xyd-js/components": "0.1.0-xyd.64",
|
|
37
|
+
"@xyd-js/core": "0.1.0-xyd.66"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/react-dom": "^19.
|
|
41
|
-
"@types/react": "^19.
|
|
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": "^
|
|
46
|
-
"vite-tsconfig-paths": "^5.
|
|
45
|
+
"vite": "^7.0.0",
|
|
46
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
47
47
|
"rimraf": "^3.0.2"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
package/src/declarations.d.ts
CHANGED
package/src/pages/layout.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
11
|
+
import {mapSettingsToProps} from "@xyd-js/framework/hydration";
|
|
12
12
|
|
|
13
|
-
import type {
|
|
14
|
-
import type {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
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 {
|
|
21
|
-
import {
|
|
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 {
|
|
24
|
+
import {iconSet} from 'virtual:xyd-icon-set';
|
|
24
25
|
|
|
25
26
|
// @ts-ignore
|
|
26
27
|
import virtualSettings from "virtual:xyd-settings";
|
|
27
|
-
// @ts-
|
|
28
|
-
const {
|
|
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
|
-
|
|
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
|
-
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
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 {
|
|
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({
|
|
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
|
-
{
|
|
135
|
-
{
|
|
144
|
+
{key: "status", defaultValue: "200"},
|
|
145
|
+
{key: "contentType", defaultValue: "application/json"}
|
|
136
146
|
];
|
|
137
147
|
} else {
|
|
138
148
|
atlasVariantToggles = [
|
|
139
|
-
{
|
|
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
|
-
<
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
<
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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, {
|
|
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, {
|
|
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;
|
package/src/pages/page.tsx
CHANGED
|
@@ -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
|
|
109
|
+
name: 'xyd:virtual-settings',
|
|
110
|
+
|
|
75
111
|
resolveId(id) {
|
|
76
|
-
if (id ===
|
|
77
|
-
return
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
|