@xyd-js/uniform 0.1.0-xyd.10
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/CHANGELOG.md +39 -0
- package/README.md +3 -0
- package/content.ts +1 -0
- package/dist/content.cjs +133 -0
- package/dist/content.cjs.map +1 -0
- package/dist/content.d.cts +4 -0
- package/dist/content.d.ts +4 -0
- package/dist/content.js +95 -0
- package/dist/content.js.map +1 -0
- package/dist/index.cjs +173 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +134 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown.cjs +295 -0
- package/dist/markdown.cjs.map +1 -0
- package/dist/markdown.d.cts +6 -0
- package/dist/markdown.d.ts +6 -0
- package/dist/markdown.js +257 -0
- package/dist/markdown.js.map +1 -0
- package/dist/types-CbDJSEtC.d.cts +81 -0
- package/dist/types-CbDJSEtC.d.ts +81 -0
- package/index.ts +8 -0
- package/markdown.ts +1 -0
- package/package.json +38 -0
- package/src/content/index.ts +124 -0
- package/src/index.ts +87 -0
- package/src/markdown/index.ts +67 -0
- package/src/markdown/utils.ts +258 -0
- package/src/types.ts +137 -0
- package/src/utils.ts +123 -0
- package/tsconfig.json +18 -0
- package/tsup.config.ts +39 -0
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// src/markdown/index.ts
|
|
2
|
+
import { remark } from "remark";
|
|
3
|
+
import remarkStringify from "remark-stringify";
|
|
4
|
+
|
|
5
|
+
// src/markdown/utils.ts
|
|
6
|
+
import { fromMarkdown } from "mdast-util-from-markdown";
|
|
7
|
+
import { u } from "unist-builder";
|
|
8
|
+
var START_DEPTH_LEVEL = 2;
|
|
9
|
+
function root(ast) {
|
|
10
|
+
return u("root", ast);
|
|
11
|
+
}
|
|
12
|
+
function heading(title, canonical, description, refCategory, refType, refContext) {
|
|
13
|
+
const uTitle = u(
|
|
14
|
+
"heading",
|
|
15
|
+
{ depth: START_DEPTH_LEVEL },
|
|
16
|
+
[u("text", `!!references ${title}`)]
|
|
17
|
+
);
|
|
18
|
+
const uCanonical = u(
|
|
19
|
+
"heading",
|
|
20
|
+
{ depth: uTitle.depth + 1 },
|
|
21
|
+
[u("text", `!canonical ${canonical}`)]
|
|
22
|
+
);
|
|
23
|
+
let uDesc = [
|
|
24
|
+
u(
|
|
25
|
+
"heading",
|
|
26
|
+
{ depth: uTitle.depth + 1 },
|
|
27
|
+
[u("text", `!description`)]
|
|
28
|
+
),
|
|
29
|
+
u("paragraph", [u("text", description)])
|
|
30
|
+
];
|
|
31
|
+
let uRefCategory;
|
|
32
|
+
if (refCategory) {
|
|
33
|
+
uRefCategory = u(
|
|
34
|
+
"heading",
|
|
35
|
+
{ depth: uTitle.depth + 1 },
|
|
36
|
+
[u("text", `!category ${refCategory}`)]
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
let uRefType;
|
|
40
|
+
if (refType) {
|
|
41
|
+
uRefType = u(
|
|
42
|
+
"heading",
|
|
43
|
+
{ depth: uTitle.depth + 1 },
|
|
44
|
+
[u("text", `!type ${refType}`)]
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
let uContext = [];
|
|
48
|
+
if (refContext && Object.keys(refContext)) {
|
|
49
|
+
uContext.push(u(
|
|
50
|
+
"heading",
|
|
51
|
+
{ depth: uTitle.depth + 1 },
|
|
52
|
+
[
|
|
53
|
+
u("text", `!context`)
|
|
54
|
+
]
|
|
55
|
+
));
|
|
56
|
+
for (const [key, value] of Object.entries(refContext)) {
|
|
57
|
+
uContext.push(
|
|
58
|
+
u(
|
|
59
|
+
"heading",
|
|
60
|
+
{ depth: uContext[0].depth + 1 },
|
|
61
|
+
[u("text", `!${key} ${value}`)]
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
title: uTitle,
|
|
68
|
+
canonical: uCanonical,
|
|
69
|
+
description: uDesc,
|
|
70
|
+
category: uRefCategory || null,
|
|
71
|
+
type: uRefType || null,
|
|
72
|
+
context: uContext || null
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function examples(examples2) {
|
|
76
|
+
const md = [];
|
|
77
|
+
const uExampleRoot = u(
|
|
78
|
+
"heading",
|
|
79
|
+
{ depth: START_DEPTH_LEVEL + 1 },
|
|
80
|
+
[u("text", `!examples`)]
|
|
81
|
+
);
|
|
82
|
+
md.push(uExampleRoot);
|
|
83
|
+
examples2.groups.forEach((group) => {
|
|
84
|
+
const uExampleGroups = u(
|
|
85
|
+
"heading",
|
|
86
|
+
{ depth: uExampleRoot.depth + 1 },
|
|
87
|
+
[u("text", `!!groups`)]
|
|
88
|
+
);
|
|
89
|
+
md.push(uExampleGroups);
|
|
90
|
+
const uGroupDescription = u(
|
|
91
|
+
"heading",
|
|
92
|
+
{ depth: uExampleGroups.depth + 1 },
|
|
93
|
+
[u("text", `!description ${group.description}`)]
|
|
94
|
+
);
|
|
95
|
+
md.push(uGroupDescription);
|
|
96
|
+
group.examples.forEach((example) => {
|
|
97
|
+
const uExamples = u(
|
|
98
|
+
"heading",
|
|
99
|
+
{ depth: uExampleGroups.depth + 1 },
|
|
100
|
+
[u("text", `!!examples`)]
|
|
101
|
+
);
|
|
102
|
+
md.push(uExamples);
|
|
103
|
+
const codeBlock = u(
|
|
104
|
+
"heading",
|
|
105
|
+
{ depth: uExamples.depth + 1 },
|
|
106
|
+
[u("text", `!codeblock`)]
|
|
107
|
+
);
|
|
108
|
+
md.push(codeBlock);
|
|
109
|
+
const codeBlockTitle = u(
|
|
110
|
+
"heading",
|
|
111
|
+
{ depth: codeBlock.depth + 1 },
|
|
112
|
+
[u("text", `!title ${example.codeblock.title}`)]
|
|
113
|
+
);
|
|
114
|
+
md.push(codeBlockTitle);
|
|
115
|
+
const tabs = u(
|
|
116
|
+
"heading",
|
|
117
|
+
{ depth: codeBlock.depth + 1 },
|
|
118
|
+
[u("text", `!!tabs`)]
|
|
119
|
+
);
|
|
120
|
+
md.push(tabs);
|
|
121
|
+
example.codeblock.tabs.forEach((tab) => {
|
|
122
|
+
const code = u("code", {
|
|
123
|
+
lang: tab.language,
|
|
124
|
+
meta: `!code ${tab.title}`
|
|
125
|
+
}, tab.code);
|
|
126
|
+
md.push(code);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
return md;
|
|
131
|
+
}
|
|
132
|
+
function definitions(definitions2) {
|
|
133
|
+
const md = [];
|
|
134
|
+
definitions2.forEach((definition) => {
|
|
135
|
+
const uDefinition = u(
|
|
136
|
+
"heading",
|
|
137
|
+
{ depth: START_DEPTH_LEVEL + 1 },
|
|
138
|
+
[u("text", `!!definitions`)]
|
|
139
|
+
);
|
|
140
|
+
md.push(uDefinition);
|
|
141
|
+
md.push(u(
|
|
142
|
+
"heading",
|
|
143
|
+
{ depth: uDefinition.depth + 1 },
|
|
144
|
+
[u("text", `!title ${definition.title}`)]
|
|
145
|
+
));
|
|
146
|
+
definition.properties.forEach((prop) => {
|
|
147
|
+
properties(
|
|
148
|
+
uDefinition.depth + 1,
|
|
149
|
+
{
|
|
150
|
+
name: prop.name,
|
|
151
|
+
type: prop.type,
|
|
152
|
+
description: prop.description,
|
|
153
|
+
context: prop.context,
|
|
154
|
+
properties: prop.properties
|
|
155
|
+
// TODO: fix ts
|
|
156
|
+
},
|
|
157
|
+
md
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
return md;
|
|
162
|
+
}
|
|
163
|
+
function properties(depth, props, output = []) {
|
|
164
|
+
const paramName = props.name;
|
|
165
|
+
const propTitle = `!!properties ${paramName}`;
|
|
166
|
+
const uPropTitle = u("heading", { depth }, [u("text", propTitle)]);
|
|
167
|
+
const uPropName = u("paragraph", { depth }, [u("text", `!name ${paramName}`)]);
|
|
168
|
+
const uPropType = u("paragraph", { depth }, [u("text", `!type ${props.type}`)]);
|
|
169
|
+
const markdownAst = fromMarkdown(props.description || "");
|
|
170
|
+
const uPropDesc = u("paragraph", { depth }, markdownAst.children);
|
|
171
|
+
const uContext = [];
|
|
172
|
+
if (props.context && Object.keys(props.context)) {
|
|
173
|
+
uContext.push(u(
|
|
174
|
+
"heading",
|
|
175
|
+
{ depth: depth + 1 },
|
|
176
|
+
[
|
|
177
|
+
u("text", `!context`)
|
|
178
|
+
]
|
|
179
|
+
));
|
|
180
|
+
for (const [key, value] of Object.entries(props.context)) {
|
|
181
|
+
uContext.push(
|
|
182
|
+
u(
|
|
183
|
+
"heading",
|
|
184
|
+
{ depth: uContext[0].depth + 1 },
|
|
185
|
+
[u("text", `!${key} ${value}`)]
|
|
186
|
+
)
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
output.push(
|
|
191
|
+
uPropTitle,
|
|
192
|
+
uPropName,
|
|
193
|
+
uPropType,
|
|
194
|
+
uPropDesc,
|
|
195
|
+
...uContext
|
|
196
|
+
);
|
|
197
|
+
if (props.properties) {
|
|
198
|
+
const deepDepth = depth + 1;
|
|
199
|
+
for (const prop of props.properties) {
|
|
200
|
+
properties(deepDepth, prop, output);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// src/markdown/index.ts
|
|
206
|
+
function compile(ast) {
|
|
207
|
+
return remark().use(remarkStringify, {
|
|
208
|
+
bullet: "-",
|
|
209
|
+
fences: true,
|
|
210
|
+
listItemIndent: "one",
|
|
211
|
+
incrementListMarker: false,
|
|
212
|
+
handlers: {
|
|
213
|
+
heading(node) {
|
|
214
|
+
return `${"#".repeat(node.depth)} ${node.children[0].value}`;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}).stringify(root(ast));
|
|
218
|
+
}
|
|
219
|
+
function referenceAST(ref) {
|
|
220
|
+
var _a, _b;
|
|
221
|
+
const md = [];
|
|
222
|
+
const mdHeading = heading(
|
|
223
|
+
ref.title,
|
|
224
|
+
ref.canonical,
|
|
225
|
+
ref.description,
|
|
226
|
+
ref.category,
|
|
227
|
+
ref.type,
|
|
228
|
+
ref.context
|
|
229
|
+
);
|
|
230
|
+
md.push(
|
|
231
|
+
mdHeading.title
|
|
232
|
+
);
|
|
233
|
+
if ((_a = mdHeading == null ? void 0 : mdHeading.description) == null ? void 0 : _a.length) {
|
|
234
|
+
md.push(...mdHeading.description);
|
|
235
|
+
}
|
|
236
|
+
md.push(
|
|
237
|
+
mdHeading.canonical
|
|
238
|
+
);
|
|
239
|
+
if (mdHeading.category) {
|
|
240
|
+
md.push(mdHeading.category);
|
|
241
|
+
}
|
|
242
|
+
if (mdHeading.type) {
|
|
243
|
+
md.push(mdHeading.type);
|
|
244
|
+
}
|
|
245
|
+
if ((_b = mdHeading == null ? void 0 : mdHeading.context) == null ? void 0 : _b.length) {
|
|
246
|
+
md.push(...mdHeading.context);
|
|
247
|
+
}
|
|
248
|
+
const mdExamples = examples(ref.examples);
|
|
249
|
+
const mdDefinitions = definitions(ref.definitions);
|
|
250
|
+
md.push(...mdExamples, ...mdDefinitions);
|
|
251
|
+
return md;
|
|
252
|
+
}
|
|
253
|
+
export {
|
|
254
|
+
compile,
|
|
255
|
+
referenceAST
|
|
256
|
+
};
|
|
257
|
+
//# sourceMappingURL=markdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/markdown/index.ts","../src/markdown/utils.ts"],"sourcesContent":["import {remark} from \"remark\";\nimport remarkStringify from \"remark-stringify\";\n\nimport {Reference} from \"../types\";\n\nimport {definitions, examples, heading, root} from \"./utils\";\n\n// TODO: any\nexport function compile(ast: any) {\n return remark()\n // .use(unlimitedHeadings)\n .use(remarkStringify, {\n bullet: '-',\n fences: true,\n listItemIndent: 'one',\n incrementListMarker: false,\n handlers: {\n heading(node) {\n return `${\"#\".repeat(node.depth)} ${node.children[0].value}`;\n },\n },\n })\n .stringify(root(ast));\n}\n\nexport function referenceAST(ref: Reference) {\n const md = []\n\n const mdHeading = heading(\n ref.title,\n ref.canonical,\n ref.description,\n ref.category,\n ref.type,\n ref.context\n )\n\n md.push(\n mdHeading.title,\n )\n\n if (mdHeading?.description?.length) {\n md.push(...mdHeading.description)\n }\n\n md.push(\n mdHeading.canonical,\n )\n\n if (mdHeading.category) {\n md.push(mdHeading.category)\n }\n\n if (mdHeading.type) {\n md.push(mdHeading.type)\n }\n\n if (mdHeading?.context?.length) {\n md.push(...mdHeading.context)\n }\n\n const mdExamples = examples(ref.examples)\n const mdDefinitions = definitions(ref.definitions)\n md.push(...mdExamples, ...mdDefinitions)\n\n return md;\n}\n","import { fromMarkdown } from \"mdast-util-from-markdown\";\nimport {u} from \"unist-builder\";\n\nimport {\n ExampleRoot,\n Definition,\n ReferenceCategory,\n ReferenceContext,\n ReferenceType,\n DefinitionProperty\n} from \"../types\";\n\n// START_DEPTH_LEVEL is the start depth level for the markdown AST\n// starts from 2 because 1 is reserved for the title\nconst START_DEPTH_LEVEL = 2\n\n// TODO: fix any\nexport function root(ast: any) {\n return u('root', ast);\n}\n\nexport function heading(\n title: string,\n canonical: string,\n description: string,\n refCategory?: ReferenceCategory,\n refType?: ReferenceType,\n refContext?: ReferenceContext\n) {\n const uTitle = u(\n 'heading',\n {depth: START_DEPTH_LEVEL},\n [u('text', `!!references ${title}`)]\n )\n\n const uCanonical = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!canonical ${canonical}`)]\n )\n\n let uDesc = [\n u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!description`),]\n ),\n u('paragraph', [u('text', description)])\n ]\n\n let uRefCategory\n if (refCategory) {\n uRefCategory = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!category ${refCategory}`)]\n )\n }\n\n let uRefType\n if (refType) {\n uRefType = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!type ${refType}`)]\n )\n }\n\n let uContext = []\n\n if (refContext && Object.keys(refContext)) {\n uContext.push(u(\n 'heading',\n {depth: uTitle.depth + 1},\n [\n u('text', `!context`),\n ]\n ))\n\n\n for (const [key, value] of Object.entries(refContext)) {\n uContext.push(u(\n 'heading',\n {depth: uContext[0].depth + 1},\n [u('text', `!${key} ${value}`)]\n )\n )\n }\n }\n\n return {\n title: uTitle,\n canonical: uCanonical,\n description: uDesc,\n category: uRefCategory || null,\n type: uRefType || null,\n context: uContext || null\n }\n}\n\nexport function examples(examples: ExampleRoot) {\n const md = []\n\n const uExampleRoot = u(\n 'heading',\n {depth: START_DEPTH_LEVEL + 1},\n [u('text', `!examples`)]\n )\n md.push(uExampleRoot)\n\n examples.groups.forEach(group => {\n const uExampleGroups = u(\n 'heading',\n {depth: uExampleRoot.depth + 1},\n [u('text', `!!groups`)]\n )\n md.push(uExampleGroups)\n\n const uGroupDescription = u(\n 'heading',\n {depth: uExampleGroups.depth + 1},\n [u('text', `!description ${group.description}`)]\n )\n md.push(uGroupDescription)\n\n group.examples.forEach(example => {\n const uExamples = u(\n 'heading',\n {depth: uExampleGroups.depth + 1},\n [u('text', `!!examples`)]\n )\n md.push(uExamples)\n\n const codeBlock = u(\n 'heading',\n {depth: uExamples.depth + 1},\n [u('text', `!codeblock`)]\n )\n md.push(codeBlock)\n\n const codeBlockTitle = u(\n 'heading',\n {depth: codeBlock.depth + 1},\n [u('text', `!title ${example.codeblock.title}`)]\n )\n md.push(codeBlockTitle)\n\n const tabs = u(\n 'heading',\n {depth: codeBlock.depth + 1},\n [u('text', `!!tabs`)]\n )\n md.push(tabs)\n\n example.codeblock.tabs.forEach(tab => {\n const code = u('code', {\n lang: tab.language,\n meta: `!code ${tab.title}`\n }, tab.code);\n\n md.push(code)\n })\n\n })\n })\n\n return md\n}\n\nexport function definitions(definitions: Definition[]) {\n const md: any[] = []\n\n definitions.forEach(definition => {\n const uDefinition = u(\n 'heading',\n {depth: START_DEPTH_LEVEL + 1},\n [u('text', `!!definitions`)]\n )\n md.push(uDefinition)\n\n md.push(u(\n 'heading',\n {depth: uDefinition.depth + 1},\n [u('text', `!title ${definition.title}`)]\n ))\n\n definition.properties.forEach(prop => {\n properties(\n uDefinition.depth + 1,\n {\n name: prop.name,\n type: prop.type,\n description: prop.description,\n context: prop.context,\n properties: prop.properties // TODO: fix ts\n },\n md,\n )\n })\n })\n\n return md\n}\n\n// TODO: any[]\nexport function properties(\n depth: number,\n props: DefinitionProperty,\n output: any[] = []\n) {\n const paramName = props.name;\n\n const propTitle = `!!properties ${paramName}`; // TODO: check if `!!properties is enough`\n const uPropTitle = u('heading', {depth}, [u('text', propTitle)]);\n const uPropName = u('paragraph', {depth}, [u('text', `!name ${paramName}`)]);\n const uPropType = u('paragraph', {depth}, [u('text', `!type ${props.type}`)]);\n const markdownAst = fromMarkdown(props.description || '');\n const uPropDesc = u(\"paragraph\", { depth }, markdownAst.children);\n const uContext = []\n\n if (props.context && Object.keys(props.context)) {\n uContext.push(u(\n 'heading',\n {depth: depth + 1},\n [\n u('text', `!context`),\n ]\n ))\n\n for (const [key, value] of Object.entries(props.context)) {\n uContext.push(u(\n 'heading',\n {depth: uContext[0].depth + 1},\n [u('text', `!${key} ${value}`)]\n )\n )\n }\n }\n\n output.push(\n uPropTitle,\n uPropName,\n uPropType,\n uPropDesc,\n ...uContext\n );\n\n if (props.properties) {\n const deepDepth = depth + 1\n\n for (const prop of props.properties) {\n properties(deepDepth, prop, output)\n }\n }\n}\n\n\n\n"],"mappings":";AAAA,SAAQ,cAAa;AACrB,OAAO,qBAAqB;;;ACD5B,SAAS,oBAAoB;AAC7B,SAAQ,SAAQ;AAahB,IAAM,oBAAoB;AAGnB,SAAS,KAAK,KAAU;AAC3B,SAAO,EAAE,QAAQ,GAAG;AACxB;AAEO,SAAS,QACZ,OACA,WACA,aACA,aACA,SACA,YACF;AACE,QAAM,SAAS;AAAA,IACX;AAAA,IACA,EAAC,OAAO,kBAAiB;AAAA,IACzB,CAAC,EAAE,QAAQ,gBAAgB,KAAK,EAAE,CAAC;AAAA,EACvC;AAEA,QAAM,aAAa;A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AI,KAAK,SAAS,CAAC,EAAE,KAAK;AAAA,MAC9D;AAAA,IACJ;AAAA,EACJ,CAAC,EACA,UAAU,KAAK,GAAG,CAAC;AAC5B;AAEO,SAAS,aAAa,KAAgB;AAzB7C;AA0BI,QAAM,KAAK,CAAC;AAEZ,QAAM,YAAY;AAAA,IACd,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,EACR;AAEA,KAAG;AAAA,IACC,UAAU;AAAA,EACd;AAEA,OAAI,4CAAW,gBAAX,mBAAwB,QAAQ;AAChC,OAAG,KAAK,GAAG,UAAU,WAAW;AAAA,EACpC;AAEA,KAAG;AAAA,IACC,UAAU;AAAA,EACd;AAEA,MAAI,UAAU,UAAU;AACpB,OAAG,KAAK,UAAU,QAAQ;AAAA,EAC9B;AAEA,MAAI,UAAU,MAAM;AAChB,OAAG,KAAK,UAAU,IAAI;AAAA,EAC1B;AAEA,OAAI,4CAAW,YAAX,mBAAoB,QAAQ;AAC5B,OAAG,KAAK,GAAG,UAAU,OAAO;AAAA,EAChC;AAEA,QAAM,aAAa,SAAS,IAAI,QAAQ;AACxC,QAAM,gBAAgB,YAAY,IAAI,WAAW;AACjD,KAAG,KAAK,GAAG,YAAY,GAAG,aAAa;AAEvC,SAAO;AACX;","names":["examples","definitions"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
declare enum ReferenceCategory {
|
|
2
|
+
COMPONENTS = "components",
|
|
3
|
+
HOOKS = "hooks",
|
|
4
|
+
REST = "rest",
|
|
5
|
+
GRAPHQL = "graphql",
|
|
6
|
+
FUNCTIONS = "functions"
|
|
7
|
+
}
|
|
8
|
+
declare enum ReferenceType {
|
|
9
|
+
COMPONENT = "component",
|
|
10
|
+
HOOK = "hook",
|
|
11
|
+
REST_HTTP_GET = "rest_get",
|
|
12
|
+
REST_HTTP_POST = "rest_post",
|
|
13
|
+
REST_HTTP_PUT = "rest_put",
|
|
14
|
+
REST_HTTP_PATCH = "rest_patch",
|
|
15
|
+
REST_HTTP_DELETE = "rest_delete",
|
|
16
|
+
GRAPHQL_QUERY = "graphql_query",
|
|
17
|
+
GRAPHQL_MUTATION = "graphql_mutation",
|
|
18
|
+
FUNCTION_JS = "function_js"
|
|
19
|
+
}
|
|
20
|
+
interface GraphQLReferenceContext {
|
|
21
|
+
}
|
|
22
|
+
interface OpenAPIReferenceContext {
|
|
23
|
+
method: string;
|
|
24
|
+
path: string;
|
|
25
|
+
}
|
|
26
|
+
type ReferenceContext = GraphQLReferenceContext | OpenAPIReferenceContext;
|
|
27
|
+
interface ExampleRoot {
|
|
28
|
+
groups: ExampleGroup[];
|
|
29
|
+
}
|
|
30
|
+
interface ExampleGroup {
|
|
31
|
+
description?: string;
|
|
32
|
+
examples: Example[];
|
|
33
|
+
}
|
|
34
|
+
interface Example {
|
|
35
|
+
description?: string;
|
|
36
|
+
codeblock: CodeBlock;
|
|
37
|
+
}
|
|
38
|
+
interface CodeBlock {
|
|
39
|
+
title?: string;
|
|
40
|
+
tabs: CodeBlockTab[];
|
|
41
|
+
}
|
|
42
|
+
interface GraphQLExampleContext {
|
|
43
|
+
schema?: any;
|
|
44
|
+
}
|
|
45
|
+
interface OpenAPIExampleContext {
|
|
46
|
+
status?: number;
|
|
47
|
+
content?: string;
|
|
48
|
+
}
|
|
49
|
+
type ExampleContext = GraphQLExampleContext | OpenAPIExampleContext;
|
|
50
|
+
interface CodeBlockTab {
|
|
51
|
+
title: string;
|
|
52
|
+
code: string;
|
|
53
|
+
language: string;
|
|
54
|
+
context?: ExampleContext;
|
|
55
|
+
}
|
|
56
|
+
interface Reference {
|
|
57
|
+
title: string;
|
|
58
|
+
description: string;
|
|
59
|
+
canonical: string;
|
|
60
|
+
definitions: Definition[];
|
|
61
|
+
examples: ExampleRoot;
|
|
62
|
+
category?: ReferenceCategory;
|
|
63
|
+
type?: ReferenceType;
|
|
64
|
+
context?: ReferenceContext;
|
|
65
|
+
}
|
|
66
|
+
interface Definition {
|
|
67
|
+
title: string;
|
|
68
|
+
properties: DefinitionProperty[];
|
|
69
|
+
type?: string;
|
|
70
|
+
id?: string;
|
|
71
|
+
description?: string;
|
|
72
|
+
}
|
|
73
|
+
interface DefinitionProperty {
|
|
74
|
+
name: string;
|
|
75
|
+
type: string;
|
|
76
|
+
description: string;
|
|
77
|
+
context?: any;
|
|
78
|
+
properties?: DefinitionProperty[];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { type CodeBlock as C, type Definition as D, type ExampleRoot as E, type GraphQLReferenceContext as G, type OpenAPIReferenceContext as O, type Reference as R, ReferenceCategory as a, ReferenceType as b, type ReferenceContext as c, type ExampleGroup as d, type Example as e, type GraphQLExampleContext as f, type OpenAPIExampleContext as g, type ExampleContext as h, type CodeBlockTab as i, type DefinitionProperty as j };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
declare enum ReferenceCategory {
|
|
2
|
+
COMPONENTS = "components",
|
|
3
|
+
HOOKS = "hooks",
|
|
4
|
+
REST = "rest",
|
|
5
|
+
GRAPHQL = "graphql",
|
|
6
|
+
FUNCTIONS = "functions"
|
|
7
|
+
}
|
|
8
|
+
declare enum ReferenceType {
|
|
9
|
+
COMPONENT = "component",
|
|
10
|
+
HOOK = "hook",
|
|
11
|
+
REST_HTTP_GET = "rest_get",
|
|
12
|
+
REST_HTTP_POST = "rest_post",
|
|
13
|
+
REST_HTTP_PUT = "rest_put",
|
|
14
|
+
REST_HTTP_PATCH = "rest_patch",
|
|
15
|
+
REST_HTTP_DELETE = "rest_delete",
|
|
16
|
+
GRAPHQL_QUERY = "graphql_query",
|
|
17
|
+
GRAPHQL_MUTATION = "graphql_mutation",
|
|
18
|
+
FUNCTION_JS = "function_js"
|
|
19
|
+
}
|
|
20
|
+
interface GraphQLReferenceContext {
|
|
21
|
+
}
|
|
22
|
+
interface OpenAPIReferenceContext {
|
|
23
|
+
method: string;
|
|
24
|
+
path: string;
|
|
25
|
+
}
|
|
26
|
+
type ReferenceContext = GraphQLReferenceContext | OpenAPIReferenceContext;
|
|
27
|
+
interface ExampleRoot {
|
|
28
|
+
groups: ExampleGroup[];
|
|
29
|
+
}
|
|
30
|
+
interface ExampleGroup {
|
|
31
|
+
description?: string;
|
|
32
|
+
examples: Example[];
|
|
33
|
+
}
|
|
34
|
+
interface Example {
|
|
35
|
+
description?: string;
|
|
36
|
+
codeblock: CodeBlock;
|
|
37
|
+
}
|
|
38
|
+
interface CodeBlock {
|
|
39
|
+
title?: string;
|
|
40
|
+
tabs: CodeBlockTab[];
|
|
41
|
+
}
|
|
42
|
+
interface GraphQLExampleContext {
|
|
43
|
+
schema?: any;
|
|
44
|
+
}
|
|
45
|
+
interface OpenAPIExampleContext {
|
|
46
|
+
status?: number;
|
|
47
|
+
content?: string;
|
|
48
|
+
}
|
|
49
|
+
type ExampleContext = GraphQLExampleContext | OpenAPIExampleContext;
|
|
50
|
+
interface CodeBlockTab {
|
|
51
|
+
title: string;
|
|
52
|
+
code: string;
|
|
53
|
+
language: string;
|
|
54
|
+
context?: ExampleContext;
|
|
55
|
+
}
|
|
56
|
+
interface Reference {
|
|
57
|
+
title: string;
|
|
58
|
+
description: string;
|
|
59
|
+
canonical: string;
|
|
60
|
+
definitions: Definition[];
|
|
61
|
+
examples: ExampleRoot;
|
|
62
|
+
category?: ReferenceCategory;
|
|
63
|
+
type?: ReferenceType;
|
|
64
|
+
context?: ReferenceContext;
|
|
65
|
+
}
|
|
66
|
+
interface Definition {
|
|
67
|
+
title: string;
|
|
68
|
+
properties: DefinitionProperty[];
|
|
69
|
+
type?: string;
|
|
70
|
+
id?: string;
|
|
71
|
+
description?: string;
|
|
72
|
+
}
|
|
73
|
+
interface DefinitionProperty {
|
|
74
|
+
name: string;
|
|
75
|
+
type: string;
|
|
76
|
+
description: string;
|
|
77
|
+
context?: any;
|
|
78
|
+
properties?: DefinitionProperty[];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { type CodeBlock as C, type Definition as D, type ExampleRoot as E, type GraphQLReferenceContext as G, type OpenAPIReferenceContext as O, type Reference as R, ReferenceCategory as a, ReferenceType as b, type ReferenceContext as c, type ExampleGroup as d, type Example as e, type GraphQLExampleContext as f, type OpenAPIExampleContext as g, type ExampleContext as h, type CodeBlockTab as i, type DefinitionProperty as j };
|
package/index.ts
ADDED
package/markdown.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/markdown/index";
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xyd-js/uniform",
|
|
3
|
+
"version": "0.1.0-xyd.10",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
"./package.json": "./package.json",
|
|
9
|
+
".": "./dist/index.js",
|
|
10
|
+
"./markdown": "./dist/markdown.js",
|
|
11
|
+
"./content": "./dist/content.js"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"codehike": "^1.0.3",
|
|
15
|
+
"gray-matter": "^4.0.3",
|
|
16
|
+
"mdast-util-from-markdown": "^2.0.2",
|
|
17
|
+
"mdast-util-to-markdown": "^2.1.2",
|
|
18
|
+
"remark": "^15.0.1",
|
|
19
|
+
"remark-stringify": "^11.0.0",
|
|
20
|
+
"unist-builder": "^4.0.0",
|
|
21
|
+
"unist-util-visit": "^5.0.0",
|
|
22
|
+
"@xyd-js/core": "0.1.0-xyd.8"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@mdx-js/mdx": "^3.1.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^22.10.5",
|
|
29
|
+
"rimraf": "^3.0.2",
|
|
30
|
+
"tsup": "^8.3.0",
|
|
31
|
+
"typescript": "^4.5.5"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"clean": "rimraf build",
|
|
35
|
+
"prebuild": "pnpm clean",
|
|
36
|
+
"build": "tsup"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import {promises as fs} from "fs";
|
|
3
|
+
|
|
4
|
+
import React from "react";
|
|
5
|
+
import {parse} from "codehike";
|
|
6
|
+
import {visit} from "unist-util-visit";
|
|
7
|
+
import {recmaCodeHike, remarkCodeHike} from "codehike/mdx";
|
|
8
|
+
import {compile as mdxCompile} from "@mdx-js/mdx";
|
|
9
|
+
|
|
10
|
+
const codeHikeOptions = {
|
|
11
|
+
lineNumbers: true,
|
|
12
|
+
showCopyButton: true,
|
|
13
|
+
autoImport: true,
|
|
14
|
+
components: {code: "Code"},
|
|
15
|
+
// syntaxHighlighting: { // TODO: !!! FROM SETTINGS !!! wait for rr7 rsc ??
|
|
16
|
+
// theme: "github-dark",
|
|
17
|
+
// },
|
|
18
|
+
};
|
|
19
|
+
//
|
|
20
|
+
// // since unist does not support heading level > 6, we need to normalize them
|
|
21
|
+
function normalizeCustomHeadings() {
|
|
22
|
+
return (tree: any) => {
|
|
23
|
+
visit(tree, 'paragraph', (node, index, parent) => {
|
|
24
|
+
const match = node.children[0] && node.children[0].value.match(/^(#+)\s+(.*)/);
|
|
25
|
+
if (match) {
|
|
26
|
+
const level = match[1].length;
|
|
27
|
+
const text = match[2];
|
|
28
|
+
if (level > 6) {
|
|
29
|
+
// Create a new heading node with depth 6
|
|
30
|
+
const headingNode = {
|
|
31
|
+
type: 'heading',
|
|
32
|
+
depth: level,
|
|
33
|
+
children: [{type: 'text', value: text}]
|
|
34
|
+
};
|
|
35
|
+
// Replace the paragraph node with the new heading node
|
|
36
|
+
//@ts-ignore
|
|
37
|
+
parent.children[index] = headingNode;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
//
|
|
45
|
+
async function compile(content: string): Promise<string> {
|
|
46
|
+
const compiled = await mdxCompile(content, {
|
|
47
|
+
remarkPlugins: [normalizeCustomHeadings, [remarkCodeHike, codeHikeOptions]],
|
|
48
|
+
recmaPlugins: [
|
|
49
|
+
[recmaCodeHike, codeHikeOptions]
|
|
50
|
+
],
|
|
51
|
+
outputFormat: 'function-body',
|
|
52
|
+
development: false,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return String(compiled)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function compileBySlug(slug: string) {
|
|
59
|
+
// TODO: cwd ?
|
|
60
|
+
const filePath = path.join(process.cwd(), `${slug}.md`)
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
await fs.access(filePath)
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.error(e)
|
|
66
|
+
return ""
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
70
|
+
|
|
71
|
+
return await compile(content)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function getMDXComponent(code: string) {
|
|
75
|
+
const mdxExport = getMDXExport(code)
|
|
76
|
+
return mdxExport.default
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function getMDXExport(code: string) {
|
|
80
|
+
const scope = {
|
|
81
|
+
Fragment: React.Fragment,
|
|
82
|
+
jsxs: React.createElement,
|
|
83
|
+
jsx: React.createElement,
|
|
84
|
+
jsxDEV: React.createElement,
|
|
85
|
+
}
|
|
86
|
+
const fn = new Function(...Object.keys(scope), code)
|
|
87
|
+
return fn(scope)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//
|
|
91
|
+
// function MDXContent(code: string) {
|
|
92
|
+
// return React.useMemo(
|
|
93
|
+
// () => code ? getMDXComponent(code) : null,
|
|
94
|
+
// [code]
|
|
95
|
+
// )
|
|
96
|
+
// }
|
|
97
|
+
|
|
98
|
+
// TODO: mod ts
|
|
99
|
+
async function lazyReferences(mod: any) {
|
|
100
|
+
const references: any[] = []
|
|
101
|
+
|
|
102
|
+
if (Array.isArray(mod.default)) {
|
|
103
|
+
for (const chunk of mod.default) {
|
|
104
|
+
try {
|
|
105
|
+
const code = await compile(chunk) // TODO: do we need real path?
|
|
106
|
+
const Content = getMDXComponent(code)
|
|
107
|
+
const content = Content ? parse(Content) : null
|
|
108
|
+
|
|
109
|
+
references.push(...content.references as [])
|
|
110
|
+
} catch (e) {
|
|
111
|
+
console.error(e)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
console.warn(`mod.default is not an array, current type is: ${typeof mod.default}`)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return references
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export {
|
|
122
|
+
compileBySlug,
|
|
123
|
+
lazyReferences
|
|
124
|
+
}
|