@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/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 +73 -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.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.
|
|
21
|
-
"@xyd-js/
|
|
22
|
-
"@xyd-js/
|
|
23
|
-
"@xyd-js/uniform": "0.1.0-xyd.
|
|
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.
|
|
27
|
-
"@react-router/node": "^7.
|
|
28
|
-
"@react-router/serve": "^7.
|
|
29
|
-
"react": "^19.
|
|
30
|
-
"react-dom": "^19.
|
|
31
|
-
"react-router": "^7.
|
|
32
|
-
"@xyd-js/framework": "0.1.0-xyd.
|
|
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/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.
|
|
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,49 @@ 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
|
|
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 {
|
|
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({
|
|
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
|
-
{
|
|
135
|
-
{
|
|
145
|
+
{key: "status", defaultValue: "200"},
|
|
146
|
+
{key: "contentType", defaultValue: "application/json"}
|
|
136
147
|
];
|
|
137
148
|
} else {
|
|
138
149
|
atlasVariantToggles = [
|
|
139
|
-
{
|
|
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
|
-
<
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
<
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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, {
|
|
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, {
|
|
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;
|
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
|
|