@xyd-js/uniform 0.1.0-xyd.2 → 0.1.0-xyd.3
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/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 +270 -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 +232 -0
- package/dist/markdown.js.map +1 -0
- package/dist/types-C8Pm_zQH.d.cts +80 -0
- package/dist/types-C8Pm_zQH.d.ts +80 -0
- package/package.json +2 -2
package/dist/content.cjs
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// content.ts
|
|
31
|
+
var content_exports = {};
|
|
32
|
+
__export(content_exports, {
|
|
33
|
+
compileBySlug: () => compileBySlug,
|
|
34
|
+
lazyReferences: () => lazyReferences
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(content_exports);
|
|
37
|
+
|
|
38
|
+
// src/content/index.ts
|
|
39
|
+
var import_path = __toESM(require("path"), 1);
|
|
40
|
+
var import_fs = require("fs");
|
|
41
|
+
var import_react = __toESM(require("react"), 1);
|
|
42
|
+
var import_codehike = require("codehike");
|
|
43
|
+
var import_unist_util_visit = require("unist-util-visit");
|
|
44
|
+
var import_mdx = require("codehike/mdx");
|
|
45
|
+
var import_mdx2 = require("@mdx-js/mdx");
|
|
46
|
+
var codeHikeOptions = {
|
|
47
|
+
lineNumbers: true,
|
|
48
|
+
showCopyButton: true,
|
|
49
|
+
autoImport: true,
|
|
50
|
+
components: { code: "Code" }
|
|
51
|
+
// syntaxHighlighting: { // TODO: !!! FROM SETTINGS !!! wait for rr7 rsc ??
|
|
52
|
+
// theme: "github-dark",
|
|
53
|
+
// },
|
|
54
|
+
};
|
|
55
|
+
function normalizeCustomHeadings() {
|
|
56
|
+
return (tree) => {
|
|
57
|
+
(0, import_unist_util_visit.visit)(tree, "paragraph", (node, index, parent) => {
|
|
58
|
+
const match = node.children[0] && node.children[0].value.match(/^(#+)\s+(.*)/);
|
|
59
|
+
if (match) {
|
|
60
|
+
const level = match[1].length;
|
|
61
|
+
const text = match[2];
|
|
62
|
+
if (level > 6) {
|
|
63
|
+
const headingNode = {
|
|
64
|
+
type: "heading",
|
|
65
|
+
depth: level,
|
|
66
|
+
children: [{ type: "text", value: text }]
|
|
67
|
+
};
|
|
68
|
+
parent.children[index] = headingNode;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async function compile(content) {
|
|
75
|
+
const compiled = await (0, import_mdx2.compile)(content, {
|
|
76
|
+
remarkPlugins: [normalizeCustomHeadings, [import_mdx.remarkCodeHike, codeHikeOptions]],
|
|
77
|
+
recmaPlugins: [
|
|
78
|
+
[import_mdx.recmaCodeHike, codeHikeOptions]
|
|
79
|
+
],
|
|
80
|
+
outputFormat: "function-body",
|
|
81
|
+
development: false
|
|
82
|
+
});
|
|
83
|
+
return String(compiled);
|
|
84
|
+
}
|
|
85
|
+
async function compileBySlug(slug) {
|
|
86
|
+
const filePath = import_path.default.join(process.cwd(), `${slug}.md`);
|
|
87
|
+
try {
|
|
88
|
+
await import_fs.promises.access(filePath);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
console.error(e);
|
|
91
|
+
return "";
|
|
92
|
+
}
|
|
93
|
+
const content = await import_fs.promises.readFile(filePath, "utf-8");
|
|
94
|
+
return await compile(content);
|
|
95
|
+
}
|
|
96
|
+
function getMDXComponent(code) {
|
|
97
|
+
const mdxExport = getMDXExport(code);
|
|
98
|
+
return mdxExport.default;
|
|
99
|
+
}
|
|
100
|
+
function getMDXExport(code) {
|
|
101
|
+
const scope = {
|
|
102
|
+
Fragment: import_react.default.Fragment,
|
|
103
|
+
jsxs: import_react.default.createElement,
|
|
104
|
+
jsx: import_react.default.createElement,
|
|
105
|
+
jsxDEV: import_react.default.createElement
|
|
106
|
+
};
|
|
107
|
+
const fn = new Function(...Object.keys(scope), code);
|
|
108
|
+
return fn(scope);
|
|
109
|
+
}
|
|
110
|
+
async function lazyReferences(mod) {
|
|
111
|
+
const references = [];
|
|
112
|
+
if (Array.isArray(mod.default)) {
|
|
113
|
+
for (const chunk of mod.default) {
|
|
114
|
+
try {
|
|
115
|
+
const code = await compile(chunk);
|
|
116
|
+
const Content = getMDXComponent(code);
|
|
117
|
+
const content = Content ? (0, import_codehike.parse)(Content) : null;
|
|
118
|
+
references.push(...content.references);
|
|
119
|
+
} catch (e) {
|
|
120
|
+
console.error(e);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
console.warn(`mod.default is not an array, current type is: ${typeof mod.default}`);
|
|
125
|
+
}
|
|
126
|
+
return references;
|
|
127
|
+
}
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
compileBySlug,
|
|
131
|
+
lazyReferences
|
|
132
|
+
});
|
|
133
|
+
//# sourceMappingURL=content.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../content.ts","../src/content/index.ts"],"sourcesContent":["export * from \"./src/content\"","import path from \"path\";\nimport {promises as fs} from \"fs\";\n\nimport React from \"react\";\nimport {parse} from \"codehike\";\nimport {visit} from \"unist-util-visit\";\nimport {recmaCodeHike, remarkCodeHike} from \"codehike/mdx\";\nimport {compile as mdxCompile} from \"@mdx-js/mdx\";\n\nconst codeHikeOptions = {\n lineNumbers: true,\n showCopyButton: true,\n autoImport: true,\n components: {code: \"Code\"},\n // syntaxHighlighting: { // TODO: !!! FROM SETTINGS !!! wait for rr7 rsc ??\n // theme: \"github-dark\",\n // },\n};\n//\n// // since unist does not support heading level > 6, we need to normalize them\nfunction normalizeCustomHeadings() {\n return (tree: any) => {\n visit(tree, 'paragraph', (node, index, parent) => {\n const match = node.children[0] && node.children[0].value.match(/^(#+)\\s+(.*)/);\n if (match) {\n const level = match[1].length;\n const text = match[2];\n if (level > 6) {\n // Create a new heading node with depth 6\n const headingNode = {\n type: 'heading',\n depth: level,\n children: [{type: 'text', value: text}]\n };\n // Replace the paragraph node with the new heading node\n //@ts-ignore\n parent.children[index] = headingNode;\n }\n }\n });\n };\n}\n\n//\nasync function compile(content: string): Promise<string> {\n const compiled = await mdxCompile(content, {\n remarkPlugins: [normalizeCustomHeadings, [remarkCodeHike, codeHikeOptions]],\n recmaPlugins: [\n [recmaCodeHike, codeHikeOptions]\n ],\n outputFormat: 'function-body',\n development: false,\n });\n\n return String(compiled)\n}\n\nasync function compileBySlug(slug: string) {\n // TODO: cwd ?\n const filePath = path.join(process.cwd(), `${slug}.md`)\n\n try {\n await fs.access(filePath)\n } catch (e) {\n console.error(e)\n return \"\"\n }\n\n const content = await fs.readFile(filePath, \"utf-8\");\n\n return await compile(content)\n}\n\nfunction getMDXComponent(code: string) {\n const mdxExport = getMDXExport(code)\n return mdxExport.default\n}\n\nfunction getMDXExport(code: string) {\n const scope = {\n Fragment: React.Fragment,\n jsxs: React.createElement,\n jsx: React.createElement,\n jsxDEV: React.createElement,\n }\n const fn = new Function(...Object.keys(scope), code)\n return fn(scope)\n}\n\n//\n// function MDXContent(code: string) {\n// return React.useMemo(\n// () => code ? getMDXComponent(code) : null,\n// [code]\n// )\n// }\n\n// TODO: mod ts\nasync function lazyReferences(mod: any) {\n const references: any[] = []\n\n if (Array.isArray(mod.default)) {\n for (const chunk of mod.default) {\n try {\n const code = await compile(chunk) // TODO: do we need real path?\n const Content = getMDXComponent(code)\n const content = Content ? parse(Content) : null\n\n references.push(...content.references as [])\n } catch (e) {\n console.error(e)\n }\n }\n } else {\n console.warn(`mod.default is not an array, current type is: ${typeof mod.default}`)\n }\n\n return references\n}\n\nexport {\n compileBySlug,\n lazyReferences\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAiB;AACjB,gBAA6B;AAE7B,mBAAkB;AAClB,sBAAoB;AACpB,8BAAoB;AACpB,iBAA4C;AAC5C,IAAAA,cAAoC;AAEpC,IAAM,kBAAkB;AAAA,EACpB,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,YAAY,EAAC,MAAM,OAAM;AAAA;AAAA;AAAA;AAI7B;AAGA,SAAS,0BAA0B;AAC/B,SAAO,CAAC,SAAc;AAClB,uCAAM,MAAM,aAAa,CAAC,MAAM,OAAO,WAAW;AAC9C,YAAM,QAAQ,KAAK,SAAS,CAAC,KAAK,KAAK,SAAS,CAAC,EAAE,MAAM,MAAM,cAAc;AAC7E,UAAI,OAAO;AACP,cAAM,QAAQ,MAAM,CAAC,EAAE;AACvB,cAAM,OAAO,MAAM,CAAC;AACpB,YAAI,QAAQ,GAAG;AAEX,gBAAM,cAAc;AAAA,YAChB,MAAM;AAAA,YACN,OAAO;AAAA,YACP,UAAU,CAAC,EAAC,MAAM,QAAQ,OAAO,KAAI,CAAC;AAAA,UAC1C;AAGA,iBAAO,SAAS,KAAK,IAAI;AAAA,QAC7B;AAAA,MACJ;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;AAGA,eAAe,QAAQ,SAAkC;AACrD,QAAM,WAAW,UAAM,YAAAC,SAAW,SAAS;AAAA,IACvC,eAAe,CAAC,yBAAyB,CAAC,2BAAgB,eAAe,CAAC;AAAA,IAC1E,cAAc;AAAA,MACV,CAAC,0BAAe,eAAe;AAAA,IACnC;AAAA,IACA,cAAc;AAAA,IACd,aAAa;AAAA,EACjB,CAAC;AAED,SAAO,OAAO,QAAQ;AAC1B;AAEA,eAAe,cAAc,MAAc;AAEvC,QAAM,WAAW,YAAAC,QAAK,KAAK,QAAQ,IAAI,GAAG,GAAG,IAAI,KAAK;AAEtD,MAAI;AACA,UAAM,UAAAC,SAAG,OAAO,QAAQ;AAAA,EAC5B,SAAS,GAAG;AACR,YAAQ,MAAM,CAAC;AACf,WAAO;AAAA,EACX;AAEA,QAAM,UAAU,MAAM,UAAAA,SAAG,SAAS,UAAU,OAAO;AAEnD,SAAO,MAAM,QAAQ,OAAO;AAChC;AAEA,SAAS,gBAAgB,MAAc;AACnC,QAAM,YAAY,aAAa,IAAI;AACnC,SAAO,UAAU;AACrB;AAEA,SAAS,aAAa,MAAc;AAChC,QAAM,QAAQ;AAAA,IACV,UAAU,aAAAC,QAAM;AAAA,IAChB,MAAM,aAAAA,QAAM;AAAA,IACZ,KAAK,aAAAA,QAAM;AAAA,IACX,QAAQ,aAAAA,QAAM;AAAA,EAClB;AACA,QAAM,KAAK,IAAI,SAAS,GAAG,OAAO,KAAK,KAAK,GAAG,IAAI;AACnD,SAAO,GAAG,KAAK;AACnB;AAWA,eAAe,eAAe,KAAU;AACpC,QAAM,aAAoB,CAAC;AAE3B,MAAI,MAAM,QAAQ,IAAI,OAAO,GAAG;AAC5B,eAAW,SAAS,IAAI,SAAS;AAC7B,UAAI;AACA,cAAM,OAAO,MAAM,QAAQ,KAAK;AAChC,cAAM,UAAU,gBAAgB,IAAI;AACpC,cAAM,UAAU,cAAU,uBAAM,OAAO,IAAI;AAE3C,mBAAW,KAAK,GAAG,QAAQ,UAAgB;AAAA,MAC/C,SAAS,GAAG;AACR,gBAAQ,MAAM,CAAC;AAAA,MACnB;AAAA,IACJ;AAAA,EACJ,OAAO;AACH,YAAQ,KAAK,iDAAiD,OAAO,IAAI,OAAO,EAAE;AAAA,EACtF;AAEA,SAAO;AACX;","names":["import_mdx","mdxCompile","path","fs","React"]}
|
package/dist/content.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// src/content/index.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { promises as fs } from "fs";
|
|
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
|
+
var codeHikeOptions = {
|
|
10
|
+
lineNumbers: true,
|
|
11
|
+
showCopyButton: true,
|
|
12
|
+
autoImport: true,
|
|
13
|
+
components: { code: "Code" }
|
|
14
|
+
// syntaxHighlighting: { // TODO: !!! FROM SETTINGS !!! wait for rr7 rsc ??
|
|
15
|
+
// theme: "github-dark",
|
|
16
|
+
// },
|
|
17
|
+
};
|
|
18
|
+
function normalizeCustomHeadings() {
|
|
19
|
+
return (tree) => {
|
|
20
|
+
visit(tree, "paragraph", (node, index, parent) => {
|
|
21
|
+
const match = node.children[0] && node.children[0].value.match(/^(#+)\s+(.*)/);
|
|
22
|
+
if (match) {
|
|
23
|
+
const level = match[1].length;
|
|
24
|
+
const text = match[2];
|
|
25
|
+
if (level > 6) {
|
|
26
|
+
const headingNode = {
|
|
27
|
+
type: "heading",
|
|
28
|
+
depth: level,
|
|
29
|
+
children: [{ type: "text", value: text }]
|
|
30
|
+
};
|
|
31
|
+
parent.children[index] = headingNode;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async function compile(content) {
|
|
38
|
+
const compiled = await mdxCompile(content, {
|
|
39
|
+
remarkPlugins: [normalizeCustomHeadings, [remarkCodeHike, codeHikeOptions]],
|
|
40
|
+
recmaPlugins: [
|
|
41
|
+
[recmaCodeHike, codeHikeOptions]
|
|
42
|
+
],
|
|
43
|
+
outputFormat: "function-body",
|
|
44
|
+
development: false
|
|
45
|
+
});
|
|
46
|
+
return String(compiled);
|
|
47
|
+
}
|
|
48
|
+
async function compileBySlug(slug) {
|
|
49
|
+
const filePath = path.join(process.cwd(), `${slug}.md`);
|
|
50
|
+
try {
|
|
51
|
+
await fs.access(filePath);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
console.error(e);
|
|
54
|
+
return "";
|
|
55
|
+
}
|
|
56
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
57
|
+
return await compile(content);
|
|
58
|
+
}
|
|
59
|
+
function getMDXComponent(code) {
|
|
60
|
+
const mdxExport = getMDXExport(code);
|
|
61
|
+
return mdxExport.default;
|
|
62
|
+
}
|
|
63
|
+
function getMDXExport(code) {
|
|
64
|
+
const scope = {
|
|
65
|
+
Fragment: React.Fragment,
|
|
66
|
+
jsxs: React.createElement,
|
|
67
|
+
jsx: React.createElement,
|
|
68
|
+
jsxDEV: React.createElement
|
|
69
|
+
};
|
|
70
|
+
const fn = new Function(...Object.keys(scope), code);
|
|
71
|
+
return fn(scope);
|
|
72
|
+
}
|
|
73
|
+
async function lazyReferences(mod) {
|
|
74
|
+
const references = [];
|
|
75
|
+
if (Array.isArray(mod.default)) {
|
|
76
|
+
for (const chunk of mod.default) {
|
|
77
|
+
try {
|
|
78
|
+
const code = await compile(chunk);
|
|
79
|
+
const Content = getMDXComponent(code);
|
|
80
|
+
const content = Content ? parse(Content) : null;
|
|
81
|
+
references.push(...content.references);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
console.error(e);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
console.warn(`mod.default is not an array, current type is: ${typeof mod.default}`);
|
|
88
|
+
}
|
|
89
|
+
return references;
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
compileBySlug,
|
|
93
|
+
lazyReferences
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/content/index.ts"],"sourcesContent":["import path from \"path\";\nimport {promises as fs} from \"fs\";\n\nimport React from \"react\";\nimport {parse} from \"codehike\";\nimport {visit} from \"unist-util-visit\";\nimport {recmaCodeHike, remarkCodeHike} from \"codehike/mdx\";\nimport {compile as mdxCompile} from \"@mdx-js/mdx\";\n\nconst codeHikeOptions = {\n lineNumbers: true,\n showCopyButton: true,\n autoImport: true,\n components: {code: \"Code\"},\n // syntaxHighlighting: { // TODO: !!! FROM SETTINGS !!! wait for rr7 rsc ??\n // theme: \"github-dark\",\n // },\n};\n//\n// // since unist does not support heading level > 6, we need to normalize them\nfunction normalizeCustomHeadings() {\n return (tree: any) => {\n visit(tree, 'paragraph', (node, index, parent) => {\n const match = node.children[0] && node.children[0].value.match(/^(#+)\\s+(.*)/);\n if (match) {\n const level = match[1].length;\n const text = match[2];\n if (level > 6) {\n // Create a new heading node with depth 6\n const headingNode = {\n type: 'heading',\n depth: level,\n children: [{type: 'text', value: text}]\n };\n // Replace the paragraph node with the new heading node\n //@ts-ignore\n parent.children[index] = headingNode;\n }\n }\n });\n };\n}\n\n//\nasync function compile(content: string): Promise<string> {\n const compiled = await mdxCompile(content, {\n remarkPlugins: [normalizeCustomHeadings, [remarkCodeHike, codeHikeOptions]],\n recmaPlugins: [\n [recmaCodeHike, codeHikeOptions]\n ],\n outputFormat: 'function-body',\n development: false,\n });\n\n return String(compiled)\n}\n\nasync function compileBySlug(slug: string) {\n // TODO: cwd ?\n const filePath = path.join(process.cwd(), `${slug}.md`)\n\n try {\n await fs.access(filePath)\n } catch (e) {\n console.error(e)\n return \"\"\n }\n\n const content = await fs.readFile(filePath, \"utf-8\");\n\n return await compile(content)\n}\n\nfunction getMDXComponent(code: string) {\n const mdxExport = getMDXExport(code)\n return mdxExport.default\n}\n\nfunction getMDXExport(code: string) {\n const scope = {\n Fragment: React.Fragment,\n jsxs: React.createElement,\n jsx: React.createElement,\n jsxDEV: React.createElement,\n }\n const fn = new Function(...Object.keys(scope), code)\n return fn(scope)\n}\n\n//\n// function MDXContent(code: string) {\n// return React.useMemo(\n// () => code ? getMDXComponent(code) : null,\n// [code]\n// )\n// }\n\n// TODO: mod ts\nasync function lazyReferences(mod: any) {\n const references: any[] = []\n\n if (Array.isArray(mod.default)) {\n for (const chunk of mod.default) {\n try {\n const code = await compile(chunk) // TODO: do we need real path?\n const Content = getMDXComponent(code)\n const content = Content ? parse(Content) : null\n\n references.push(...content.references as [])\n } catch (e) {\n console.error(e)\n }\n }\n } else {\n console.warn(`mod.default is not an array, current type is: ${typeof mod.default}`)\n }\n\n return references\n}\n\nexport {\n compileBySlug,\n lazyReferences\n}\n"],"mappings":";AAAA,OAAO,UAAU;AACjB,SAAQ,YAAY,UAAS;AAE7B,OAAO,WAAW;AAClB,SAAQ,aAAY;AACpB,SAAQ,aAAY;AACpB,SAAQ,eAAe,sBAAqB;AAC5C,SAAQ,WAAW,kBAAiB;AAEpC,IAAM,kBAAkB;AAAA,EACpB,aAAa;AAAA,EACb,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,YAAY,EAAC,MAAM,OAAM;AAAA;AAAA;AAAA;AAI7B;AAGA,SAAS,0BAA0B;AAC/B,SAAO,CAAC,SAAc;AAClB,UAAM,MAAM,aAAa,CAAC,MAAM,OAAO,WAAW;AAC9C,YAAM,QAAQ,KAAK,SAAS,CAAC,KAAK,KAAK,SAAS,CAAC,EAAE,MAAM,MAAM,cAAc;AAC7E,UAAI,OAAO;AACP,cAAM,QAAQ,MAAM,CAAC,EAAE;AACvB,cAAM,OAAO,MAAM,CAAC;AACpB,YAAI,QAAQ,GAAG;AAEX,gBAAM,cAAc;AAAA,YAChB,MAAM;AAAA,YACN,OAAO;AAAA,YACP,UAAU,CAAC,EAAC,MAAM,QAAQ,OAAO,KAAI,CAAC;AAAA,UAC1C;AAGA,iBAAO,SAAS,KAAK,IAAI;AAAA,QAC7B;AAAA,MACJ;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;AAGA,eAAe,QAAQ,SAAkC;AACrD,QAAM,WAAW,MAAM,WAAW,SAAS;AAAA,IACvC,eAAe,CAAC,yBAAyB,CAAC,gBAAgB,eAAe,CAAC;AAAA,IAC1E,cAAc;AAAA,MACV,CAAC,eAAe,eAAe;AAAA,IACnC;AAAA,IACA,cAAc;AAAA,IACd,aAAa;AAAA,EACjB,CAAC;AAED,SAAO,OAAO,QAAQ;AAC1B;AAEA,eAAe,cAAc,MAAc;AAEvC,QAAM,WAAW,KAAK,KAAK,QAAQ,IAAI,GAAG,GAAG,IAAI,KAAK;AAEtD,MAAI;AACA,UAAM,GAAG,OAAO,QAAQ;AAAA,EAC5B,SAAS,GAAG;AACR,YAAQ,MAAM,CAAC;AACf,WAAO;AAAA,EACX;AAEA,QAAM,UAAU,MAAM,GAAG,SAAS,UAAU,OAAO;AAEnD,SAAO,MAAM,QAAQ,OAAO;AAChC;AAEA,SAAS,gBAAgB,MAAc;AACnC,QAAM,YAAY,aAAa,IAAI;AACnC,SAAO,UAAU;AACrB;AAEA,SAAS,aAAa,MAAc;AAChC,QAAM,QAAQ;AAAA,IACV,UAAU,MAAM;AAAA,IAChB,MAAM,MAAM;AAAA,IACZ,KAAK,MAAM;AAAA,IACX,QAAQ,MAAM;AAAA,EAClB;AACA,QAAM,KAAK,IAAI,SAAS,GAAG,OAAO,KAAK,KAAK,GAAG,IAAI;AACnD,SAAO,GAAG,KAAK;AACnB;AAWA,eAAe,eAAe,KAAU;AACpC,QAAM,aAAoB,CAAC;AAE3B,MAAI,MAAM,QAAQ,IAAI,OAAO,GAAG;AAC5B,eAAW,SAAS,IAAI,SAAS;AAC7B,UAAI;AACA,cAAM,OAAO,MAAM,QAAQ,KAAK;AAChC,cAAM,UAAU,gBAAgB,IAAI;AACpC,cAAM,UAAU,UAAU,MAAM,OAAO,IAAI;AAE3C,mBAAW,KAAK,GAAG,QAAQ,UAAgB;AAAA,MAC/C,SAAS,GAAG;AACR,gBAAQ,MAAM,CAAC;AAAA,MACnB;AAAA,IACJ;AAAA,EACJ,OAAO;AACH,YAAQ,KAAK,iDAAiD,OAAO,IAAI,OAAO,EAAE;AAAA,EACtF;AAEA,SAAO;AACX;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
ReferenceCategory: () => ReferenceCategory,
|
|
34
|
+
ReferenceType: () => ReferenceType,
|
|
35
|
+
default: () => uniform,
|
|
36
|
+
pluginNavigation: () => pluginNavigation
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
|
|
40
|
+
// src/index.ts
|
|
41
|
+
function uniform(references, config) {
|
|
42
|
+
const response = {
|
|
43
|
+
references,
|
|
44
|
+
out: {}
|
|
45
|
+
};
|
|
46
|
+
const finishCallbacks = /* @__PURE__ */ new Set();
|
|
47
|
+
config.plugins.forEach((plugin) => {
|
|
48
|
+
const call = plugin((cb) => {
|
|
49
|
+
finishCallbacks.add(cb);
|
|
50
|
+
});
|
|
51
|
+
references.forEach((ref) => {
|
|
52
|
+
call(ref);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
finishCallbacks.forEach((cb) => {
|
|
56
|
+
if (typeof cb === "function") {
|
|
57
|
+
const resp = cb();
|
|
58
|
+
if (typeof resp !== "object") {
|
|
59
|
+
throw new Error(`Invalid callback return type: ${typeof resp}`);
|
|
60
|
+
}
|
|
61
|
+
response.out = {
|
|
62
|
+
...response.out,
|
|
63
|
+
...resp
|
|
64
|
+
};
|
|
65
|
+
} else {
|
|
66
|
+
throw new Error(`Invalid callback type: ${typeof cb}`);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return response;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// src/utils.ts
|
|
73
|
+
var import_path = __toESM(require("path"), 1);
|
|
74
|
+
var import_gray_matter = __toESM(require("gray-matter"), 1);
|
|
75
|
+
function pluginNavigation(options) {
|
|
76
|
+
if (!options.urlPrefix) {
|
|
77
|
+
throw new Error("urlPrefix is required");
|
|
78
|
+
}
|
|
79
|
+
return function pluginNavigationInner(cb) {
|
|
80
|
+
const pageFrontMatter = {};
|
|
81
|
+
const groupMaps = {};
|
|
82
|
+
cb(() => {
|
|
83
|
+
return {
|
|
84
|
+
pageFrontMatter,
|
|
85
|
+
sidebar: convertGroupMapsToNavigations(groupMaps)
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
return (ref) => {
|
|
89
|
+
var _a;
|
|
90
|
+
const content = (0, import_gray_matter.default)(ref.description || "");
|
|
91
|
+
if (content.data) {
|
|
92
|
+
const data = content.data;
|
|
93
|
+
const pagePath = import_path.default.join(options.urlPrefix, ref.canonical);
|
|
94
|
+
if (data.title) {
|
|
95
|
+
pageFrontMatter[pagePath] = {
|
|
96
|
+
title: data.title
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (data.group) {
|
|
100
|
+
if (typeof ((_a = content == null ? void 0 : content.data) == null ? void 0 : _a.group) === "string") {
|
|
101
|
+
throw new Error("group as string is not supported yet");
|
|
102
|
+
}
|
|
103
|
+
content.data.group.reduce((groups, group, i) => {
|
|
104
|
+
if (!groups[group]) {
|
|
105
|
+
groups[group] = {
|
|
106
|
+
__groups: {},
|
|
107
|
+
pages: /* @__PURE__ */ new Set()
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (i === content.data.group.length - 1) {
|
|
111
|
+
groups[group].pages.add(pagePath);
|
|
112
|
+
}
|
|
113
|
+
return groups[group].__groups;
|
|
114
|
+
}, groupMaps);
|
|
115
|
+
}
|
|
116
|
+
ref.description = content.content;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function convertGroupMapsToNavigations(groupMaps) {
|
|
122
|
+
const nav = [];
|
|
123
|
+
Object.keys(groupMaps).map((groupName) => {
|
|
124
|
+
const current = groupMaps[groupName];
|
|
125
|
+
const pages = [];
|
|
126
|
+
current.pages.forEach((page) => {
|
|
127
|
+
pages.push(page);
|
|
128
|
+
});
|
|
129
|
+
if (Object.keys(current.__groups).length) {
|
|
130
|
+
const subNav = {
|
|
131
|
+
group: groupName,
|
|
132
|
+
pages: convertGroupMapsToNavigations(current.__groups)
|
|
133
|
+
};
|
|
134
|
+
nav.push(subNav);
|
|
135
|
+
} else {
|
|
136
|
+
nav.push({
|
|
137
|
+
group: groupName,
|
|
138
|
+
pages
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
return nav;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/types.ts
|
|
146
|
+
var ReferenceCategory = /* @__PURE__ */ ((ReferenceCategory2) => {
|
|
147
|
+
ReferenceCategory2["COMPONENTS"] = "components";
|
|
148
|
+
ReferenceCategory2["HOOKS"] = "hooks";
|
|
149
|
+
ReferenceCategory2["REST"] = "rest";
|
|
150
|
+
ReferenceCategory2["GRAPHQL"] = "graphql";
|
|
151
|
+
ReferenceCategory2["FUNCTIONS"] = "functions";
|
|
152
|
+
return ReferenceCategory2;
|
|
153
|
+
})(ReferenceCategory || {});
|
|
154
|
+
var ReferenceType = /* @__PURE__ */ ((ReferenceType2) => {
|
|
155
|
+
ReferenceType2["COMPONENT"] = "component";
|
|
156
|
+
ReferenceType2["HOOK"] = "hook";
|
|
157
|
+
ReferenceType2["REST_HTTP_GET"] = "rest_get";
|
|
158
|
+
ReferenceType2["REST_HTTP_POST"] = "rest_post";
|
|
159
|
+
ReferenceType2["REST_HTTP_PUT"] = "rest_put";
|
|
160
|
+
ReferenceType2["REST_HTTP_PATCH"] = "rest_patch";
|
|
161
|
+
ReferenceType2["REST_HTTP_DELETE"] = "rest_delete";
|
|
162
|
+
ReferenceType2["GRAPHQL_QUERY"] = "graphql_query";
|
|
163
|
+
ReferenceType2["GRAPHQL_MUTATION"] = "graphql_mutation";
|
|
164
|
+
ReferenceType2["FUNCTION_JS"] = "function_js";
|
|
165
|
+
return ReferenceType2;
|
|
166
|
+
})(ReferenceType || {});
|
|
167
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
168
|
+
0 && (module.exports = {
|
|
169
|
+
ReferenceCategory,
|
|
170
|
+
ReferenceType,
|
|
171
|
+
pluginNavigation
|
|
172
|
+
});
|
|
173
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../index.ts","../src/index.ts","../src/utils.ts","../src/types.ts"],"sourcesContent":["export {default} from \"./src/index\"\n\nexport {\n pluginNavigation\n} from \"./src/utils\"\n\nexport * from \"./src/types\"\n\n","// Define the new PluginV type with a callback function that returns another function\nimport {Reference} from \"./types\";\n\n// Define the new PluginV type with a callback function that returns another function\nexport type UniformPlugin<T> = (cb: (cb: () => T) => void) => (ref: Reference) => void;\n\n// Utility type to infer if a type is an array and avoid wrapping it into an array twice\ntype NormalizeArray<T> = T extends Array<infer U> ? U[] : T;\n\n// Infer the return type of the plugin callback properly and normalize array types\ntype PluginResult<T extends UniformPlugin<any>> = T extends UniformPlugin<infer R> ? R : never;\n\n// Merge all plugin return types into a single object and normalize arrays\ntype MergePluginResults<T extends UniformPlugin<any>[]> = {\n [K in keyof UnionToIntersection<PluginResult<T[number]>>]: NormalizeArray<UnionToIntersection<PluginResult<T[number]>>[K]>\n};\n\n// Utility type to handle intersection to an object type\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;\n\n// Implement the uniform function\nexport default function uniform<T extends UniformPlugin<any>[]>(\n references: Reference[],\n config: { plugins: T }\n) {\n // Infer the merged result type from all plugins\n type ResultType = MergePluginResults<T>;\n\n // Initialize the response with a type-safe out object\n const response: {\n references: Reference[]\n out: { [K in keyof ResultType]: ResultType[K] }\n } = {\n references,\n out: {} as { [K in keyof ResultType]: ResultType[K] }\n };\n\n\n const finishCallbacks = new Set();\n\n config.plugins.forEach((plugin) => {\n const call = plugin(cb => {\n finishCallbacks.add(cb);\n })\n\n references.forEach((ref) => {\n call(ref)\n });\n })\n\n finishCallbacks.forEach(cb => {\n if (typeof cb === \"function\") {\n const resp = cb()\n if (typeof resp !== \"object\") {\n throw new Error(`Invalid callback return type: ${typeof resp}`)\n }\n\n response.out = {\n ...response.out,\n ...resp\n }\n } else {\n throw new Error(`Invalid callback type: ${typeof cb}`)\n }\n });\n\n return response;\n}\n\n// Example usage\n// const examplePlugin: UniformPlugin<{ value: boolean }> = (cb) => {\n// return (ref: Reference) => {\n// };\n// };\n// function examplePlugin(cb: (cb: () => { value: boolean }) => void) {\n// cb(() => ({\n// value: true,\n// }));\n//\n// return (ref: Reference) => {\n//\n// };\n// }\n// const response = uniform([/* references */], {\n// plugins: [examplePlugin],\n// });\n// response.out\n","import path from 'path';\nimport matter from 'gray-matter';\nimport {Sidebar, FrontMatter, PageFrontMatter} from \"@xyd-js/core\";\n\nimport {Reference} from \"./types\";\nimport uniform from \"./index\";\n\n// interface UniformFrontMatter extends FrontMatter { // TODO: it's concept only\n// scopes?: string\n// }\n\ntype GroupMap = {\n [key: string]: {\n __groups: GroupMap\n pages: Set<string>\n }\n}\n\nexport interface pluginNavigationOptions {\n urlPrefix: string\n}\n\nexport function pluginNavigation(options: pluginNavigationOptions) {\n if (!options.urlPrefix) {\n throw new Error(\"urlPrefix is required\")\n }\n\n return function pluginNavigationInner(cb: (cb: () => {\n pageFrontMatter: PageFrontMatter\n sidebar: Sidebar[]\n }) => void) {\n const pageFrontMatter: PageFrontMatter = {}\n const groupMaps: GroupMap = {}\n\n cb(() => {\n return {\n pageFrontMatter: pageFrontMatter,\n sidebar: convertGroupMapsToNavigations(groupMaps) as Sidebar[]\n }\n })\n\n return (ref: Reference) => {\n const content = matter(ref.description || \"\") // TODO: pluginMatter before?\n\n if (content.data) {\n const data = content.data as FrontMatter\n\n const pagePath = path.join(options.urlPrefix, ref.canonical)\n\n if (data.title) {\n pageFrontMatter[pagePath] = {\n title: data.title,\n }\n }\n\n if (data.group) {\n if (typeof content?.data?.group === \"string\") {\n // TODO: seek nested group (it's not always from 0)\n throw new Error(\"group as string is not supported yet\")\n }\n\n content.data.group.reduce((groups: GroupMap, group: string, i: number) => {\n if (!groups[group]) {\n groups[group] = {\n __groups: {},\n pages: new Set()\n }\n }\n\n if (i === content.data.group.length - 1) {\n groups[group].pages.add(pagePath)\n }\n\n return groups[group].__groups\n }, groupMaps)\n }\n\n // back description to original without frontmatter\n ref.description = content.content\n }\n }\n }\n}\n\n\nfunction convertGroupMapsToNavigations(groupMaps: GroupMap): Sidebar[] {\n const nav: Sidebar[] = []\n\n Object.keys(groupMaps).map((groupName) => {\n const current = groupMaps[groupName]\n\n const pages: string[] | Sidebar[] = []\n\n current.pages.forEach((page: string) => {\n pages.push(page)\n })\n\n if (Object.keys(current.__groups).length) {\n const subNav: Sidebar = {\n group: groupName,\n pages: convertGroupMapsToNavigations(current.__groups)\n }\n\n nav.push(subNav)\n } else {\n nav.push({\n group: groupName,\n pages,\n })\n }\n })\n\n return nav\n}\n\n// example usage:\n// const response = uniform([/* references */], {\n// plugins: [pluginNavigation({\n// urlPrefix: \"/docs\"\n// })],\n// });\n\n\n","// TODO: concept only\nexport enum ReferenceCategory {\n // for React\n COMPONENTS = \"components\",\n HOOKS = \"hooks\",\n // end for React\n\n // for API\n REST = \"rest\",\n GRAPHQL = \"graphql\",\n // end for API\n\n // for code\n FUNCTIONS = \"functions\",\n //\n}\n\n// TODO: concept only\nexport enum ReferenceType {\n // for React\n COMPONENT = \"component\",\n HOOK = \"hook\",\n // end for React\n\n // for API\n REST_HTTP_GET = \"rest_get\",\n REST_HTTP_POST = \"rest_post\",\n REST_HTTP_PUT = \"rest_put\",\n REST_HTTP_PATCH = \"rest_patch\",\n REST_HTTP_DELETE = \"rest_delete\",\n // ---\n GRAPHQL_QUERY = \"graphql_query\",\n GRAPHQL_MUTATION = \"graphql_mutation\",\n // end for API\n\n // for code\n FUNCTION_JS = \"function_js\",\n // end for code\n}\n\nexport interface GraphQLReferenceContext {\n}\n\n// TODO: custom value?\nexport interface OpenAPIReferenceContext {\n method: string;\n\n path: string;\n}\n\nexport type ReferenceContext = GraphQLReferenceContext | OpenAPIReferenceContext;\n\nexport interface ExampleRoot {\n groups: ExampleGroup[];\n}\n\nexport interface ExampleGroup {\n description?: string;\n\n examples: Example[];\n}\n\nexport interface Example {\n description?: string; // TODO: replace with title ?\n\n codeblock: CodeBlock;\n}\n\nexport interface CodeBlock {\n title?: string;\n\n tabs: CodeBlockTab[];\n}\n\nexport interface GraphQLExampleContext {\n schema?: any; // TODO:\n}\n\nexport interface OpenAPIExampleContext {\n status?: number;\n\n content?: string;\n}\n\nexport type ExampleContext = GraphQLExampleContext | OpenAPIExampleContext;\n\nexport interface CodeBlockTab {\n // title of the tab e.g \"JavaScript\"\n title: string;\n\n // code in the tab e.g \"console.log('Hello World')\"\n code: string\n \n // language of the code e.g \"js\"\n language: string;\n\n // context of the generation method e.g openapi or graphql\n context?: ExampleContext;\n}\n\nexport interface Reference {\n title: string;\n description: string;\n canonical: string;\n\n definitions: Definition[]\n examples: ExampleRoot\n\n category?: ReferenceCategory; // TODO: do we need that?\n type?: ReferenceType; // TODO: do we need that?\n context?: ReferenceContext;\n}\n\nexport interface Definition {\n title: string;\n\n properties: DefinitionProperty[];\n\n type?: string;\n\n id?: string;\n\n description?: string;\n}\n\nexport interface DefinitionProperty {\n name: string;\n\n type: string;\n\n description: string;\n\n properties?: DefinitionProperty[];\n}"],"mappings":"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","names":["matter","path","ReferenceCategory","ReferenceType"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { R as Reference } from './types-C8Pm_zQH.cjs';
|
|
2
|
+
export { C as CodeBlock, i as CodeBlockTab, D as Definition, j as DefinitionProperty, e as Example, h as ExampleContext, d as ExampleGroup, E as ExampleRoot, f as GraphQLExampleContext, G as GraphQLReferenceContext, g as OpenAPIExampleContext, O as OpenAPIReferenceContext, a as ReferenceCategory, c as ReferenceContext, b as ReferenceType } from './types-C8Pm_zQH.cjs';
|
|
3
|
+
import { PageFrontMatter, Sidebar } from '@xyd-js/core';
|
|
4
|
+
|
|
5
|
+
type UniformPlugin<T> = (cb: (cb: () => T) => void) => (ref: Reference) => void;
|
|
6
|
+
type NormalizeArray<T> = T extends Array<infer U> ? U[] : T;
|
|
7
|
+
type PluginResult<T extends UniformPlugin<any>> = T extends UniformPlugin<infer R> ? R : never;
|
|
8
|
+
type MergePluginResults<T extends UniformPlugin<any>[]> = {
|
|
9
|
+
[K in keyof UnionToIntersection<PluginResult<T[number]>>]: NormalizeArray<UnionToIntersection<PluginResult<T[number]>>[K]>;
|
|
10
|
+
};
|
|
11
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
12
|
+
declare function uniform<T extends UniformPlugin<any>[]>(references: Reference[], config: {
|
|
13
|
+
plugins: T;
|
|
14
|
+
}): {
|
|
15
|
+
references: Reference[];
|
|
16
|
+
out: { [K in keyof UnionToIntersection<PluginResult<T[number]>>]: MergePluginResults<T>[K]; };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
interface pluginNavigationOptions {
|
|
20
|
+
urlPrefix: string;
|
|
21
|
+
}
|
|
22
|
+
declare function pluginNavigation(options: pluginNavigationOptions): (cb: (cb: () => {
|
|
23
|
+
pageFrontMatter: PageFrontMatter;
|
|
24
|
+
sidebar: Sidebar[];
|
|
25
|
+
}) => void) => (ref: Reference) => void;
|
|
26
|
+
|
|
27
|
+
export { Reference, uniform as default, pluginNavigation };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { R as Reference } from './types-C8Pm_zQH.js';
|
|
2
|
+
export { C as CodeBlock, i as CodeBlockTab, D as Definition, j as DefinitionProperty, e as Example, h as ExampleContext, d as ExampleGroup, E as ExampleRoot, f as GraphQLExampleContext, G as GraphQLReferenceContext, g as OpenAPIExampleContext, O as OpenAPIReferenceContext, a as ReferenceCategory, c as ReferenceContext, b as ReferenceType } from './types-C8Pm_zQH.js';
|
|
3
|
+
import { PageFrontMatter, Sidebar } from '@xyd-js/core';
|
|
4
|
+
|
|
5
|
+
type UniformPlugin<T> = (cb: (cb: () => T) => void) => (ref: Reference) => void;
|
|
6
|
+
type NormalizeArray<T> = T extends Array<infer U> ? U[] : T;
|
|
7
|
+
type PluginResult<T extends UniformPlugin<any>> = T extends UniformPlugin<infer R> ? R : never;
|
|
8
|
+
type MergePluginResults<T extends UniformPlugin<any>[]> = {
|
|
9
|
+
[K in keyof UnionToIntersection<PluginResult<T[number]>>]: NormalizeArray<UnionToIntersection<PluginResult<T[number]>>[K]>;
|
|
10
|
+
};
|
|
11
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
12
|
+
declare function uniform<T extends UniformPlugin<any>[]>(references: Reference[], config: {
|
|
13
|
+
plugins: T;
|
|
14
|
+
}): {
|
|
15
|
+
references: Reference[];
|
|
16
|
+
out: { [K in keyof UnionToIntersection<PluginResult<T[number]>>]: MergePluginResults<T>[K]; };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
interface pluginNavigationOptions {
|
|
20
|
+
urlPrefix: string;
|
|
21
|
+
}
|
|
22
|
+
declare function pluginNavigation(options: pluginNavigationOptions): (cb: (cb: () => {
|
|
23
|
+
pageFrontMatter: PageFrontMatter;
|
|
24
|
+
sidebar: Sidebar[];
|
|
25
|
+
}) => void) => (ref: Reference) => void;
|
|
26
|
+
|
|
27
|
+
export { Reference, uniform as default, pluginNavigation };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function uniform(references, config) {
|
|
3
|
+
const response = {
|
|
4
|
+
references,
|
|
5
|
+
out: {}
|
|
6
|
+
};
|
|
7
|
+
const finishCallbacks = /* @__PURE__ */ new Set();
|
|
8
|
+
config.plugins.forEach((plugin) => {
|
|
9
|
+
const call = plugin((cb) => {
|
|
10
|
+
finishCallbacks.add(cb);
|
|
11
|
+
});
|
|
12
|
+
references.forEach((ref) => {
|
|
13
|
+
call(ref);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
finishCallbacks.forEach((cb) => {
|
|
17
|
+
if (typeof cb === "function") {
|
|
18
|
+
const resp = cb();
|
|
19
|
+
if (typeof resp !== "object") {
|
|
20
|
+
throw new Error(`Invalid callback return type: ${typeof resp}`);
|
|
21
|
+
}
|
|
22
|
+
response.out = {
|
|
23
|
+
...response.out,
|
|
24
|
+
...resp
|
|
25
|
+
};
|
|
26
|
+
} else {
|
|
27
|
+
throw new Error(`Invalid callback type: ${typeof cb}`);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return response;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/utils.ts
|
|
34
|
+
import path from "path";
|
|
35
|
+
import matter from "gray-matter";
|
|
36
|
+
function pluginNavigation(options) {
|
|
37
|
+
if (!options.urlPrefix) {
|
|
38
|
+
throw new Error("urlPrefix is required");
|
|
39
|
+
}
|
|
40
|
+
return function pluginNavigationInner(cb) {
|
|
41
|
+
const pageFrontMatter = {};
|
|
42
|
+
const groupMaps = {};
|
|
43
|
+
cb(() => {
|
|
44
|
+
return {
|
|
45
|
+
pageFrontMatter,
|
|
46
|
+
sidebar: convertGroupMapsToNavigations(groupMaps)
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
return (ref) => {
|
|
50
|
+
var _a;
|
|
51
|
+
const content = matter(ref.description || "");
|
|
52
|
+
if (content.data) {
|
|
53
|
+
const data = content.data;
|
|
54
|
+
const pagePath = path.join(options.urlPrefix, ref.canonical);
|
|
55
|
+
if (data.title) {
|
|
56
|
+
pageFrontMatter[pagePath] = {
|
|
57
|
+
title: data.title
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (data.group) {
|
|
61
|
+
if (typeof ((_a = content == null ? void 0 : content.data) == null ? void 0 : _a.group) === "string") {
|
|
62
|
+
throw new Error("group as string is not supported yet");
|
|
63
|
+
}
|
|
64
|
+
content.data.group.reduce((groups, group, i) => {
|
|
65
|
+
if (!groups[group]) {
|
|
66
|
+
groups[group] = {
|
|
67
|
+
__groups: {},
|
|
68
|
+
pages: /* @__PURE__ */ new Set()
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
if (i === content.data.group.length - 1) {
|
|
72
|
+
groups[group].pages.add(pagePath);
|
|
73
|
+
}
|
|
74
|
+
return groups[group].__groups;
|
|
75
|
+
}, groupMaps);
|
|
76
|
+
}
|
|
77
|
+
ref.description = content.content;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function convertGroupMapsToNavigations(groupMaps) {
|
|
83
|
+
const nav = [];
|
|
84
|
+
Object.keys(groupMaps).map((groupName) => {
|
|
85
|
+
const current = groupMaps[groupName];
|
|
86
|
+
const pages = [];
|
|
87
|
+
current.pages.forEach((page) => {
|
|
88
|
+
pages.push(page);
|
|
89
|
+
});
|
|
90
|
+
if (Object.keys(current.__groups).length) {
|
|
91
|
+
const subNav = {
|
|
92
|
+
group: groupName,
|
|
93
|
+
pages: convertGroupMapsToNavigations(current.__groups)
|
|
94
|
+
};
|
|
95
|
+
nav.push(subNav);
|
|
96
|
+
} else {
|
|
97
|
+
nav.push({
|
|
98
|
+
group: groupName,
|
|
99
|
+
pages
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return nav;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/types.ts
|
|
107
|
+
var ReferenceCategory = /* @__PURE__ */ ((ReferenceCategory2) => {
|
|
108
|
+
ReferenceCategory2["COMPONENTS"] = "components";
|
|
109
|
+
ReferenceCategory2["HOOKS"] = "hooks";
|
|
110
|
+
ReferenceCategory2["REST"] = "rest";
|
|
111
|
+
ReferenceCategory2["GRAPHQL"] = "graphql";
|
|
112
|
+
ReferenceCategory2["FUNCTIONS"] = "functions";
|
|
113
|
+
return ReferenceCategory2;
|
|
114
|
+
})(ReferenceCategory || {});
|
|
115
|
+
var ReferenceType = /* @__PURE__ */ ((ReferenceType2) => {
|
|
116
|
+
ReferenceType2["COMPONENT"] = "component";
|
|
117
|
+
ReferenceType2["HOOK"] = "hook";
|
|
118
|
+
ReferenceType2["REST_HTTP_GET"] = "rest_get";
|
|
119
|
+
ReferenceType2["REST_HTTP_POST"] = "rest_post";
|
|
120
|
+
ReferenceType2["REST_HTTP_PUT"] = "rest_put";
|
|
121
|
+
ReferenceType2["REST_HTTP_PATCH"] = "rest_patch";
|
|
122
|
+
ReferenceType2["REST_HTTP_DELETE"] = "rest_delete";
|
|
123
|
+
ReferenceType2["GRAPHQL_QUERY"] = "graphql_query";
|
|
124
|
+
ReferenceType2["GRAPHQL_MUTATION"] = "graphql_mutation";
|
|
125
|
+
ReferenceType2["FUNCTION_JS"] = "function_js";
|
|
126
|
+
return ReferenceType2;
|
|
127
|
+
})(ReferenceType || {});
|
|
128
|
+
export {
|
|
129
|
+
ReferenceCategory,
|
|
130
|
+
ReferenceType,
|
|
131
|
+
uniform as default,
|
|
132
|
+
pluginNavigation
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=index.js.map
|