@rspress/core 2.0.0-beta.34 → 2.0.0-beta.35

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.
@@ -542,21 +542,6 @@ export const __webpack_modules__ = {
542
542
  };
543
543
  const node_modules_onetime = onetime_onetime;
544
544
  var external_node_os_ = __webpack_require__("node:os");
545
- const getRealtimeSignals = ()=>{
546
- const length = SIGRTMAX - SIGRTMIN + 1;
547
- return Array.from({
548
- length
549
- }, getRealtimeSignal);
550
- };
551
- const getRealtimeSignal = (value, index)=>({
552
- name: `SIGRT${index + 1}`,
553
- number: SIGRTMIN + index,
554
- action: "terminate",
555
- description: "Application-specific signal (realtime)",
556
- standard: "posix"
557
- });
558
- const SIGRTMIN = 34;
559
- const SIGRTMAX = 64;
560
545
  const SIGNALS = [
561
546
  {
562
547
  name: "SIGHUP",
@@ -828,6 +813,21 @@ export const __webpack_modules__ = {
828
813
  standard: "other"
829
814
  }
830
815
  ];
816
+ const getRealtimeSignals = ()=>{
817
+ const length = SIGRTMAX - SIGRTMIN + 1;
818
+ return Array.from({
819
+ length
820
+ }, getRealtimeSignal);
821
+ };
822
+ const getRealtimeSignal = (value, index)=>({
823
+ name: `SIGRT${index + 1}`,
824
+ number: SIGRTMIN + index,
825
+ action: "terminate",
826
+ description: "Application-specific signal (realtime)",
827
+ standard: "posix"
828
+ });
829
+ const SIGRTMIN = 34;
830
+ const SIGRTMAX = 64;
831
831
  const getSignals = ()=>{
832
832
  const realtimeSignals = getRealtimeSignals();
833
833
  const signals = [
@@ -869,7 +869,7 @@ export const __webpack_modules__ = {
869
869
  const signalsByName = getSignalsByName();
870
870
  const getSignalsByNumber = ()=>{
871
871
  const signals = getSignals();
872
- const length = SIGRTMAX + 1;
872
+ const length = 65;
873
873
  const signalsA = Array.from({
874
874
  length
875
875
  }, (value, number)=>getSignalByNumber(number, signals));
@@ -0,0 +1,2 @@
1
+ import { renderToMarkdownString } from "./render.js";
2
+ export { renderToMarkdownString };
@@ -0,0 +1,169 @@
1
+ import { createContext } from "react";
2
+ import react_reconciler from "react-reconciler";
3
+ import { DefaultEventPriority, NoEventPriority } from "react-reconciler/constants.js";
4
+ class TextNode {
5
+ text;
6
+ parent;
7
+ constructor(text){
8
+ this.text = text;
9
+ }
10
+ setText(text) {
11
+ this.text = text;
12
+ }
13
+ }
14
+ class MarkdownNode {
15
+ type;
16
+ props;
17
+ children;
18
+ parent;
19
+ constructor(type, props = {}){
20
+ this.type = type;
21
+ this.props = props;
22
+ this.children = [];
23
+ }
24
+ appendChild(child) {
25
+ this.children.push(child);
26
+ if ('parent' in child) child.parent = this;
27
+ }
28
+ removeChild(child) {
29
+ const index = this.children.indexOf(child);
30
+ if (-1 !== index) this.children.splice(index, 1);
31
+ }
32
+ insertBefore(child, beforeChild) {
33
+ const index = this.children.indexOf(beforeChild);
34
+ if (-1 !== index) this.children.splice(index, 0, child);
35
+ else this.appendChild(child);
36
+ if ('parent' in child) child.parent = this;
37
+ }
38
+ }
39
+ let currentUpdatePriority = NoEventPriority;
40
+ const hostConfig = {
41
+ supportsMutation: true,
42
+ supportsPersistence: false,
43
+ supportsHydration: false,
44
+ isPrimaryRenderer: false,
45
+ getRootHostContext () {
46
+ return {
47
+ isInsideText: false
48
+ };
49
+ },
50
+ getChildHostContext (parentHostContext, type) {
51
+ const previousIsInsideText = parentHostContext.isInsideText;
52
+ const isInsideText = 'text' === type || 'span' === type || previousIsInsideText;
53
+ if (previousIsInsideText === isInsideText) return parentHostContext;
54
+ return {
55
+ isInsideText
56
+ };
57
+ },
58
+ createInstance (type, props) {
59
+ return new MarkdownNode(type, props);
60
+ },
61
+ createTextInstance (text) {
62
+ return new TextNode(text);
63
+ },
64
+ shouldSetTextContent (_type, _props) {
65
+ return false;
66
+ },
67
+ appendChild (parent, child) {
68
+ parent.appendChild(child);
69
+ },
70
+ insertBefore (parent, child, beforeChild) {
71
+ parent.insertBefore(child, beforeChild);
72
+ },
73
+ removeChild (parent, child) {
74
+ parent.removeChild(child);
75
+ },
76
+ commitTextUpdate (textInstance, _oldText, newText) {
77
+ textInstance.setText(newText);
78
+ },
79
+ commitUpdate (instance, _type, _oldProps, newProps, _internalHandle) {
80
+ instance.props = newProps;
81
+ },
82
+ finalizeInitialChildren () {
83
+ return false;
84
+ },
85
+ commitMount () {},
86
+ clearContainer (container) {
87
+ container.children = [];
88
+ },
89
+ setCurrentUpdatePriority (newPriority) {
90
+ currentUpdatePriority = newPriority;
91
+ },
92
+ getCurrentUpdatePriority () {
93
+ return currentUpdatePriority;
94
+ },
95
+ resolveUpdatePriority () {
96
+ if (currentUpdatePriority !== NoEventPriority) return currentUpdatePriority;
97
+ return DefaultEventPriority;
98
+ },
99
+ appendInitialChild (parent, child) {
100
+ parent.appendChild(child);
101
+ },
102
+ preparePortalMount () {},
103
+ resetTextContent () {},
104
+ getPublicInstance (instance) {
105
+ return instance;
106
+ },
107
+ prepareForCommit (_containerInfo) {
108
+ return null;
109
+ },
110
+ resetAfterCommit (_containerInfo) {},
111
+ scheduleTimeout: setTimeout,
112
+ cancelTimeout: clearTimeout,
113
+ noTimeout: -1,
114
+ scheduleMicrotask: 'function' == typeof queueMicrotask ? queueMicrotask : (fn)=>Promise.resolve().then(fn),
115
+ getInstanceFromNode () {
116
+ return null;
117
+ },
118
+ beforeActiveInstanceBlur () {},
119
+ afterActiveInstanceBlur () {},
120
+ prepareScopeUpdate () {},
121
+ getInstanceFromScope () {
122
+ return null;
123
+ },
124
+ detachDeletedInstance () {},
125
+ appendChildToContainer (container, child) {
126
+ container.appendChild(child);
127
+ },
128
+ insertInContainerBefore (container, child, beforeChild) {
129
+ container.insertBefore(child, beforeChild);
130
+ },
131
+ removeChildFromContainer (container, child) {
132
+ container.removeChild(child);
133
+ },
134
+ hideInstance (_instance) {},
135
+ hideTextInstance (textInstance) {
136
+ textInstance.setText('');
137
+ },
138
+ unhideInstance (_instance) {},
139
+ unhideTextInstance (textInstance, text) {
140
+ textInstance.setText(text);
141
+ },
142
+ maySuspendCommit () {
143
+ return false;
144
+ },
145
+ preloadInstance () {
146
+ return true;
147
+ },
148
+ startSuspendingCommit () {},
149
+ suspendInstance () {},
150
+ waitForCommitToBeReady () {
151
+ return null;
152
+ },
153
+ NotPendingTransition: null,
154
+ HostTransitionContext: createContext(null),
155
+ resetFormInstance () {},
156
+ requestPostPaintCallback () {},
157
+ shouldAttemptEagerTransition () {
158
+ return false;
159
+ },
160
+ trackSchedulerEvent () {},
161
+ resolveEventType () {
162
+ return null;
163
+ },
164
+ resolveEventTimeStamp () {
165
+ return -1.1;
166
+ }
167
+ };
168
+ const reconciler = react_reconciler(hostConfig);
169
+ export { MarkdownNode, TextNode, reconciler };
@@ -0,0 +1,105 @@
1
+ import { MarkdownNode, TextNode, reconciler } from "./reconciler.js";
2
+ function toMarkdown(root) {
3
+ const { type, props, children } = root;
4
+ const childrenMd = children.map((child)=>{
5
+ if (child instanceof TextNode) return child.text;
6
+ return toMarkdown(child);
7
+ }).join('');
8
+ switch(type){
9
+ case 'root':
10
+ return childrenMd;
11
+ case 'h1':
12
+ return `# ${childrenMd}\n\n`;
13
+ case 'h2':
14
+ return `## ${childrenMd}\n\n`;
15
+ case 'h3':
16
+ return `### ${childrenMd}\n\n`;
17
+ case 'h4':
18
+ return `#### ${childrenMd}\n\n`;
19
+ case 'h5':
20
+ return `##### ${childrenMd}\n\n`;
21
+ case 'h6':
22
+ return `###### ${childrenMd}\n\n`;
23
+ case 'p':
24
+ return `${childrenMd}\n\n`;
25
+ case 'strong':
26
+ case 'b':
27
+ return `**${childrenMd}**`;
28
+ case 'em':
29
+ case 'i':
30
+ return `*${childrenMd}*`;
31
+ case 'code':
32
+ return `\`${childrenMd}\``;
33
+ case 'pre':
34
+ {
35
+ const language = props.lang || props.language || '';
36
+ return `\`\`\`${language}\n${childrenMd}\n\`\`\`\n\n`;
37
+ }
38
+ case 'a':
39
+ return `[${childrenMd}](${props.href || '#'})`;
40
+ case 'img':
41
+ return `![${props.alt || ''}](${props.src || ''})`;
42
+ case 'ul':
43
+ return `${childrenMd}\n`;
44
+ case 'ol':
45
+ return `${childrenMd}\n`;
46
+ case 'li':
47
+ {
48
+ const isOrdered = root.parent && 'ol' === root.parent.type;
49
+ const prefix = isOrdered ? '1. ' : '- ';
50
+ return `${prefix}${childrenMd}\n`;
51
+ }
52
+ case 'blockquote':
53
+ return `> ${childrenMd.split('\n').join('\n> ')}\n\n`;
54
+ case 'br':
55
+ return '\n';
56
+ case 'hr':
57
+ return '---\n\n';
58
+ case 'table':
59
+ return `${childrenMd}\n`;
60
+ case 'thead':
61
+ return childrenMd;
62
+ case 'tbody':
63
+ return childrenMd;
64
+ case 'tr':
65
+ {
66
+ const cells = children.filter((child)=>child instanceof MarkdownNode).map((cell)=>toMarkdown(cell).trim());
67
+ if (root.parent && 'thead' === root.parent.type) {
68
+ const separator = `|${cells.map(()=>' --- ').join('|')}|\n`;
69
+ return `| ${cells.join(' | ')} |\n${separator}`;
70
+ }
71
+ return `| ${cells.join(' | ')} |\n`;
72
+ }
73
+ case 'th':
74
+ case 'td':
75
+ return childrenMd;
76
+ case 'div':
77
+ case 'span':
78
+ case 'section':
79
+ case 'article':
80
+ case 'main':
81
+ case 'aside':
82
+ case 'header':
83
+ case 'footer':
84
+ case 'nav':
85
+ default:
86
+ return childrenMd;
87
+ }
88
+ }
89
+ async function renderToMarkdownString(element) {
90
+ const container = new MarkdownNode('root');
91
+ const root = reconciler.createContainer(container, 1, null, false, false, '', (...args)=>{
92
+ if (process.env.DEBUG) console.log('Reconciler Error:', ...args);
93
+ }, ()=>{}, (...args)=>{
94
+ if (process.env.DEBUG) console.log('Reconciler onRecoverable Error:', ...args);
95
+ }, ()=>{}, null);
96
+ let resolveCommit = null;
97
+ const commitPromise = new Promise((resolve)=>{
98
+ resolveCommit = resolve;
99
+ });
100
+ reconciler.updateContainer(element, root, null, ()=>{
101
+ if (resolveCommit) resolveCommit(toMarkdown(container));
102
+ });
103
+ return commitPromise;
104
+ }
105
+ export { renderToMarkdownString };
package/dist/cli.js CHANGED
@@ -6,7 +6,7 @@ import picocolors from "picocolors";
6
6
  import { build, dev, serve } from "./index.js";
7
7
  import node_fs from "node:fs";
8
8
  import { DEFAULT_CONFIG_EXTENSIONS, DEFAULT_CONFIG_NAME } from "@rspress/shared/constants";
9
- var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.34"}');
9
+ var package_namespaceObject = JSON.parse('{"rE":"2.0.0-beta.35"}');
10
10
  const findConfig = (basePath)=>DEFAULT_CONFIG_EXTENSIONS.map((ext)=>basePath + ext).find(node_fs.existsSync);
11
11
  async function loadConfigFile(customConfigFile) {
12
12
  const baseDir = process.cwd();
package/dist/index.d.ts CHANGED
@@ -9,6 +9,7 @@ import { MarkdownOptions } from '@rspress/shared';
9
9
  import { matchPath } from '@rspress/runtime/server';
10
10
  import { mergeDocConfig } from '@rspress/shared/node-utils';
11
11
  import { Nav } from '@rspress/shared';
12
+ import type { NavItem } from '@rspress/shared';
12
13
  import { NavItemWithLink } from '@rspress/shared';
13
14
  import type { Node as Node_3 } from 'unist';
14
15
  import { normalizeHref } from '@rspress/shared';
@@ -47,6 +48,44 @@ declare interface BuildOptions {
47
48
  */
48
49
  declare type Compatible = Options | URL | VFile | Value
49
50
 
51
+ export declare type CustomLinkMeta = {
52
+ type: 'custom-link';
53
+ label: string;
54
+ tag?: string;
55
+ overviewHeaders?: number[];
56
+ context?: string;
57
+ link: string;
58
+ } | {
59
+ type: 'custom-link';
60
+ label: string;
61
+ tag?: string;
62
+ overviewHeaders?: number[];
63
+ context?: string;
64
+ link?: string;
65
+ collapsible?: boolean;
66
+ collapsed?: boolean;
67
+ items: _CustomLinkMetaWithoutTypeField[];
68
+ };
69
+
70
+ declare type _CustomLinkMetaWithoutTypeField = {
71
+ type?: 'custom-link';
72
+ label: string;
73
+ tag?: string;
74
+ overviewHeaders?: number[];
75
+ context?: string;
76
+ link: string;
77
+ } | {
78
+ type?: 'custom-link';
79
+ label: string;
80
+ tag?: string;
81
+ overviewHeaders?: number[];
82
+ context?: string;
83
+ link?: string;
84
+ collapsible?: boolean;
85
+ collapsed?: boolean;
86
+ items: _CustomLinkMetaWithoutTypeField[];
87
+ };
88
+
50
89
  /**
51
90
  * Info associated with mdast nodes by the ecosystem.
52
91
  *
@@ -103,8 +142,37 @@ declare interface DevOptions {
103
142
  extraBuilderConfig?: RsbuildConfig;
104
143
  }
105
144
 
145
+ export declare type DirSectionHeaderSideMeta = Omit<DirSideMeta, 'type'> & Omit<SectionHeaderMeta, 'type'> & {
146
+ type: 'dir-section-header';
147
+ };
148
+
149
+ export declare type DirSideMeta = {
150
+ type: 'dir';
151
+ name: string;
152
+ label?: string;
153
+ tag?: string;
154
+ overviewHeaders?: number[];
155
+ context?: string;
156
+ collapsible?: boolean;
157
+ collapsed?: boolean;
158
+ };
159
+
160
+ export declare type DividerSideMeta = {
161
+ type: 'divider';
162
+ dashed?: boolean;
163
+ };
164
+
106
165
  declare const emptyObjectSymbol: unique symbol;
107
166
 
167
+ export declare type FileSideMeta = {
168
+ type: 'file';
169
+ name: string;
170
+ label?: string;
171
+ tag?: string;
172
+ overviewHeaders?: number[];
173
+ context?: string;
174
+ };
175
+
108
176
  export { getIconUrlPath }
109
177
 
110
178
  export { getNodeAttribute }
@@ -160,10 +228,14 @@ export { matchPath }
160
228
 
161
229
  export { mergeDocConfig }
162
230
 
231
+ export declare type MetaJson = SideMeta;
232
+
163
233
  export { Nav }
164
234
 
165
235
  export { NavItemWithLink }
166
236
 
237
+ export declare type NavJson = NavItem[];
238
+
167
239
  /**
168
240
  * Abstract mdast node.
169
241
  *
@@ -266,6 +338,7 @@ export declare class PluginDriver {
266
338
  getPlugins(): RspressPlugin[];
267
339
  clearPlugins(): void;
268
340
  removePlugin(pluginName: string): void;
341
+ private normalizeConfig;
269
342
  modifyConfig(): Promise<UserConfig<DefaultThemeConfig>>;
270
343
  beforeBuild(): Promise<void[]>;
271
344
  afterBuild(): Promise<void[]>;
@@ -370,6 +443,9 @@ export declare class RouteService {
370
443
  isInDocsDir(absolutePath: string): boolean;
371
444
  absolutePathToRelativePath(absolutePath: string): string;
372
445
  getRoutePageByRoutePath(routePath: string): RoutePage | undefined;
446
+ getDocsDir(): string;
447
+ getLangs(): string[];
448
+ getDefaultLang(): string;
373
449
  }
374
450
 
375
451
  export { RSPRESS_TEMP_DIR }
@@ -378,6 +454,12 @@ export { RspressPlugin }
378
454
 
379
455
  declare type RspressPluginHookKeys = 'beforeBuild' | 'config' | 'afterBuild' | 'addPages' | 'addRuntimeModules' | 'routeGenerated' | 'routeServiceGenerated' | 'extendPageData' | 'modifySearchIndexData';
380
456
 
457
+ export declare type SectionHeaderMeta = {
458
+ type: 'section-header';
459
+ label: string;
460
+ tag?: string;
461
+ };
462
+
381
463
  export declare function serve(options: ServeOptions): Promise<ReturnType<RsbuildInstance['preview']>>;
382
464
 
383
465
  declare interface ServeOptions {
@@ -401,6 +483,10 @@ export { SidebarItem }
401
483
 
402
484
  export { SidebarSectionHeader }
403
485
 
486
+ export declare type SideMeta = SideMetaItem[];
487
+
488
+ export declare type SideMetaItem = FileSideMeta | DirSideMeta | DirSectionHeaderSideMeta | DividerSideMeta | SectionHeaderMeta | CustomLinkMeta | string;
489
+
404
490
  export { UserConfig }
405
491
 
406
492
  /**