@mintlify/msft-sdk 1.1.59 → 1.1.61
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/api-playground/EndpointFields/ParamFields/RecursiveParamField.js +7 -6
- package/dist/api-playground/EndpointFields/index.js +4 -3
- package/dist/api-playground-2/components/Example/GeneratedRequestExample.js +54 -54
- package/dist/api-playground-2/generators/generateSnippet.js +30 -183
- package/dist/components/content-components/code-block.js +120 -113
- package/dist/components/content-components/code-snippets.js +12 -10
- package/dist/index.d.ts +2 -1
- package/package.json +2 -1
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import i from "@sindresorhus/slugify";
|
|
3
|
+
import "../../../contexts/EndpointLocationContext.js";
|
|
4
|
+
const s = (r, t, e, $) => i(
|
|
5
|
+
`${r ? `${r}-` : ""}${e ? `${e}-` : ""}${t || ""}-`,
|
|
5
6
|
{
|
|
6
7
|
decamelize: !0
|
|
7
8
|
}
|
|
8
|
-
),
|
|
9
|
+
), m = (r, t) => r ? `${t ? `${t}` : ""}${r}.` : "";
|
|
9
10
|
export {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
s as buildRecursiveParamFieldId,
|
|
12
|
+
m as getRecursiveParentName
|
|
12
13
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import "../../contexts/EndpointLocationContext.js";
|
|
3
|
+
import { useOpenApiEndpoint as t } from "../../hooks/useEndpoint.js";
|
|
4
|
+
const i = () => (t(), null);
|
|
4
5
|
export {
|
|
5
|
-
|
|
6
|
+
i as default
|
|
6
7
|
};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { generateRequest as
|
|
4
|
-
import { generateSnippet as
|
|
1
|
+
import { jsx as y } from "react/jsx-runtime";
|
|
2
|
+
import { useState as B, useEffect as E } from "react";
|
|
3
|
+
import { generateRequest as j } from "../../generators/generateRequest.js";
|
|
4
|
+
import { generateSnippet as S } from "../../generators/generateSnippet.js";
|
|
5
5
|
import { getFirstExampleValue as V } from "../../schemaGraph/processExamples.js";
|
|
6
|
-
import { CodeGroupSelect as
|
|
7
|
-
import { CodeSnippets as
|
|
8
|
-
import { langToPresetMap as
|
|
6
|
+
import { CodeGroupSelect as w } from "../../../components/content-components/CodeGroupSelect/index.js";
|
|
7
|
+
import { CodeSnippets as G } from "../../../components/content-components/code-snippets.js";
|
|
8
|
+
import { langToPresetMap as P } from "../../../constants/snippetPresets.js";
|
|
9
9
|
const J = ({
|
|
10
|
-
baseUrl:
|
|
10
|
+
baseUrl: s,
|
|
11
11
|
apiReferenceData: t,
|
|
12
12
|
inputs: e,
|
|
13
13
|
requestExampleLanguages: u,
|
|
14
|
-
requiredOnly:
|
|
14
|
+
requiredOnly: r,
|
|
15
15
|
maxHeight: o,
|
|
16
16
|
selectedSecurityOptionIndex: f
|
|
17
17
|
}) => {
|
|
18
|
-
var
|
|
19
|
-
const p = (
|
|
18
|
+
var T, h, c, n, x;
|
|
19
|
+
const p = (T = t.dependencies) == null ? void 0 : T.requestBody;
|
|
20
20
|
if (!p)
|
|
21
|
-
return /* @__PURE__ */
|
|
22
|
-
|
|
21
|
+
return /* @__PURE__ */ y(
|
|
22
|
+
a,
|
|
23
23
|
{
|
|
24
24
|
apiReferenceData: t,
|
|
25
|
-
baseUrl:
|
|
25
|
+
baseUrl: s,
|
|
26
26
|
inputs: e,
|
|
27
27
|
requestExampleLanguages: u,
|
|
28
|
-
requiredOnly:
|
|
28
|
+
requiredOnly: r,
|
|
29
29
|
maxHeight: o,
|
|
30
30
|
selectedSecurityOptionIndex: f
|
|
31
31
|
}
|
|
@@ -33,84 +33,84 @@ const J = ({
|
|
|
33
33
|
const i = V(p.content);
|
|
34
34
|
if (!i) return null;
|
|
35
35
|
const m = Object.entries(p.content).map(
|
|
36
|
-
([
|
|
37
|
-
contentType:
|
|
38
|
-
examples:
|
|
36
|
+
([C, d]) => ({
|
|
37
|
+
contentType: C,
|
|
38
|
+
examples: d.examples
|
|
39
39
|
})
|
|
40
40
|
), l = 0;
|
|
41
|
-
return ((
|
|
42
|
-
|
|
41
|
+
return ((h = m[l]) == null ? void 0 : h.examples.length) > 1 ? /* @__PURE__ */ y(
|
|
42
|
+
k,
|
|
43
43
|
{
|
|
44
44
|
apiReferenceData: t,
|
|
45
45
|
selectedBodyContentType: (c = m[l]) == null ? void 0 : c.contentType,
|
|
46
|
-
baseUrl:
|
|
46
|
+
baseUrl: s,
|
|
47
47
|
inputs: e,
|
|
48
48
|
examples: (n = m[l]) == null ? void 0 : n.examples,
|
|
49
|
-
requiredOnly:
|
|
49
|
+
requiredOnly: r,
|
|
50
50
|
maxHeight: o,
|
|
51
51
|
selectedSecurityOptionIndex: f
|
|
52
52
|
}
|
|
53
|
-
) : /* @__PURE__ */
|
|
54
|
-
|
|
53
|
+
) : /* @__PURE__ */ y(
|
|
54
|
+
a,
|
|
55
55
|
{
|
|
56
56
|
apiReferenceData: t,
|
|
57
57
|
selectedBodyContentType: (x = m[l]) == null ? void 0 : x.contentType,
|
|
58
|
-
baseUrl:
|
|
58
|
+
baseUrl: s,
|
|
59
59
|
inputs: e,
|
|
60
60
|
exampleValue: i,
|
|
61
61
|
requestExampleLanguages: u,
|
|
62
|
-
requiredOnly:
|
|
62
|
+
requiredOnly: r,
|
|
63
63
|
maxHeight: o,
|
|
64
64
|
selectedSecurityOptionIndex: f
|
|
65
65
|
}
|
|
66
66
|
);
|
|
67
|
-
},
|
|
68
|
-
baseUrl:
|
|
67
|
+
}, a = ({
|
|
68
|
+
baseUrl: s,
|
|
69
69
|
apiReferenceData: t,
|
|
70
70
|
inputs: e,
|
|
71
71
|
selectedBodyContentType: u,
|
|
72
|
-
exampleValue:
|
|
72
|
+
exampleValue: r,
|
|
73
73
|
requestExampleLanguages: o,
|
|
74
74
|
requiredOnly: f,
|
|
75
75
|
maxHeight: p,
|
|
76
76
|
selectedSecurityOptionIndex: i
|
|
77
77
|
}) => {
|
|
78
|
-
const m =
|
|
79
|
-
baseUrl:
|
|
78
|
+
const m = j({
|
|
79
|
+
baseUrl: s,
|
|
80
80
|
apiReferenceData: t,
|
|
81
81
|
inputs: e,
|
|
82
82
|
selectedBodyContentType: u,
|
|
83
|
-
exampleData:
|
|
83
|
+
exampleData: r,
|
|
84
84
|
requiredOnly: f,
|
|
85
85
|
selectedSecurityOptionIndex: i
|
|
86
|
-
}), l = o == null ? void 0 : o.reduce((
|
|
87
|
-
const n =
|
|
88
|
-
return n &&
|
|
89
|
-
}, []),
|
|
86
|
+
}), l = o == null ? void 0 : o.reduce((h, c) => {
|
|
87
|
+
const n = P[c];
|
|
88
|
+
return n && h.push(n), h;
|
|
89
|
+
}, []), T = S({
|
|
90
90
|
apiReferenceData: t,
|
|
91
91
|
pathInputs: e.path,
|
|
92
92
|
request: m,
|
|
93
93
|
snippetPresets: l
|
|
94
94
|
});
|
|
95
|
-
return /* @__PURE__ */
|
|
96
|
-
},
|
|
97
|
-
baseUrl:
|
|
95
|
+
return /* @__PURE__ */ y(G, { snippets: T, dropdown: !0, maxHeight: p, showCopyButton: !1 });
|
|
96
|
+
}, k = ({
|
|
97
|
+
baseUrl: s,
|
|
98
98
|
apiReferenceData: t,
|
|
99
99
|
inputs: e,
|
|
100
100
|
selectedBodyContentType: u,
|
|
101
|
-
examples:
|
|
101
|
+
examples: r,
|
|
102
102
|
requiredOnly: o,
|
|
103
103
|
maxHeight: f,
|
|
104
104
|
selectedSecurityOptionIndex: p
|
|
105
105
|
}) => {
|
|
106
|
-
const [i, m] =
|
|
106
|
+
const [i, m] = B({}), [l, T] = B(null);
|
|
107
107
|
return E(() => {
|
|
108
|
-
const
|
|
108
|
+
const h = e.path, c = {};
|
|
109
109
|
try {
|
|
110
|
-
for (const [n, { value: x }] of Object.entries(
|
|
110
|
+
for (const [n, { value: x }] of Object.entries(r)) {
|
|
111
111
|
if (!x) continue;
|
|
112
|
-
const
|
|
113
|
-
baseUrl:
|
|
112
|
+
const C = j({
|
|
113
|
+
baseUrl: s,
|
|
114
114
|
apiReferenceData: t,
|
|
115
115
|
inputs: e,
|
|
116
116
|
selectedBodyContentType: u,
|
|
@@ -118,23 +118,23 @@ const J = ({
|
|
|
118
118
|
requiredOnly: o,
|
|
119
119
|
selectedSecurityOptionIndex: p
|
|
120
120
|
});
|
|
121
|
-
|
|
121
|
+
S({
|
|
122
122
|
apiReferenceData: t,
|
|
123
|
-
pathInputs:
|
|
124
|
-
request:
|
|
123
|
+
pathInputs: h,
|
|
124
|
+
request: C,
|
|
125
125
|
isMultipleRequest: !0
|
|
126
|
-
}).forEach((
|
|
127
|
-
c[
|
|
128
|
-
...c[
|
|
129
|
-
[n]:
|
|
126
|
+
}).forEach((M) => {
|
|
127
|
+
c[M.filename] = {
|
|
128
|
+
...c[M.filename],
|
|
129
|
+
[n]: M
|
|
130
130
|
};
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
m(c);
|
|
134
134
|
} catch (n) {
|
|
135
|
-
console.error(n),
|
|
135
|
+
console.error(n), T(n);
|
|
136
136
|
}
|
|
137
|
-
}, [
|
|
137
|
+
}, [s, t, e, u, r, o, p]), l || Object.keys(i).length === 0 ? null : /* @__PURE__ */ y(w, { snippets: i, maxHeight: f });
|
|
138
138
|
};
|
|
139
139
|
export {
|
|
140
140
|
J as GeneratedRequestExample
|
|
@@ -1,192 +1,39 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HTTPSnippet as U } from "@readme/httpsnippet";
|
|
2
|
+
import { generateUniqueString as x } from "../../utils/uuid.js";
|
|
2
3
|
import { snippetPresets as R } from "../../constants/snippetPresets.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
s.forEach((p) => {
|
|
10
|
-
p.name && p.value && (n[p.name] = p.value);
|
|
11
|
-
});
|
|
12
|
-
const a = (i == null ? void 0 : i.text) || "";
|
|
13
|
-
switch (r) {
|
|
14
|
-
case "shell":
|
|
15
|
-
return this.generateCurl(t, e, n, a);
|
|
16
|
-
case "python":
|
|
17
|
-
return this.generatePython(t, e, n, a, o);
|
|
18
|
-
case "javascript":
|
|
19
|
-
return this.generateJavaScript(t, e, n, a, o);
|
|
20
|
-
case "php":
|
|
21
|
-
return this.generatePHP(t, e, n, a);
|
|
22
|
-
case "go":
|
|
23
|
-
return this.generateGo(t, e, n, a);
|
|
24
|
-
case "java":
|
|
25
|
-
return this.generateJava(t, e, n, a);
|
|
26
|
-
case "ruby":
|
|
27
|
-
return this.generateRuby(t, e, n, a);
|
|
28
|
-
default:
|
|
29
|
-
return `# Code generation for ${r} not implemented yet`;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
generateCurl(r, o, t, e) {
|
|
33
|
-
let s = `curl -X ${r.toUpperCase()} "${o}"`;
|
|
34
|
-
return Object.entries(t).forEach(([i, n]) => {
|
|
35
|
-
s += ` \\
|
|
36
|
-
-H "${i}: ${n}"`;
|
|
37
|
-
}), e && (s += ` \\
|
|
38
|
-
-d '${e}'`), s;
|
|
39
|
-
}
|
|
40
|
-
generatePython(r, o, t, e, s) {
|
|
41
|
-
if (s === "requests") {
|
|
42
|
-
const i = JSON.stringify(t, null, 2).split(`
|
|
43
|
-
`).join(`
|
|
44
|
-
`), n = e ? `,
|
|
45
|
-
data=${JSON.stringify(e)}` : "";
|
|
46
|
-
return `import requests
|
|
47
|
-
|
|
48
|
-
response = requests.${r.toLowerCase()}(
|
|
49
|
-
"${o}",
|
|
50
|
-
headers=${i}${n}
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
print(response.json())`;
|
|
54
|
-
}
|
|
55
|
-
return `# Python code generation not implemented for client: ${s}`;
|
|
56
|
-
}
|
|
57
|
-
generateJavaScript(r, o, t, e, s) {
|
|
58
|
-
if (s === "fetch") {
|
|
59
|
-
const i = JSON.stringify(t, null, 2).split(`
|
|
60
|
-
`).map((a, p) => p === 0 ? a : " " + a).join(`
|
|
61
|
-
`), n = e ? `,
|
|
62
|
-
body: ${JSON.stringify(e)}` : "";
|
|
63
|
-
return `fetch("${o}", {
|
|
64
|
-
method: "${r.toUpperCase()}",
|
|
65
|
-
headers: ${i}${n}
|
|
66
|
-
})
|
|
67
|
-
.then(response => response.json())
|
|
68
|
-
.then(data => console.log(data))
|
|
69
|
-
.catch(error => console.error('Error:', error));`;
|
|
70
|
-
}
|
|
71
|
-
return `// JavaScript code generation not implemented for client: ${s}`;
|
|
72
|
-
}
|
|
73
|
-
generatePHP(r, o, t, e) {
|
|
74
|
-
const s = Object.entries(t).map(([n, a]) => ` "${n}: ${a}"`).join(`,
|
|
75
|
-
`), i = e ? `,
|
|
76
|
-
CURLOPT_POSTFIELDS => '${e}'` : "";
|
|
77
|
-
return `<?php
|
|
78
|
-
$ch = curl_init();
|
|
79
|
-
|
|
80
|
-
curl_setopt_array($ch, [
|
|
81
|
-
CURLOPT_URL => "${o}",
|
|
82
|
-
CURLOPT_RETURNTRANSFER => true,
|
|
83
|
-
CURLOPT_CUSTOMREQUEST => "${r.toUpperCase()}",
|
|
84
|
-
CURLOPT_HTTPHEADER => [
|
|
85
|
-
${s}
|
|
86
|
-
]${i}
|
|
87
|
-
]);
|
|
88
|
-
|
|
89
|
-
$response = curl_exec($ch);
|
|
90
|
-
curl_close($ch);
|
|
91
|
-
|
|
92
|
-
echo $response;
|
|
93
|
-
?>`;
|
|
94
|
-
}
|
|
95
|
-
generateGo(r, o, t, e) {
|
|
96
|
-
const s = e ? `
|
|
97
|
-
reqBody := strings.NewReader(${JSON.stringify(e)})
|
|
98
|
-
req, _ := http.NewRequest("${r.toUpperCase()}", "${o}", reqBody)` : `
|
|
99
|
-
req, _ := http.NewRequest("${r.toUpperCase()}", "${o}", nil)`, i = Object.entries(t).map(([n, a]) => ` req.Header.Add("${n}", "${a}")`).join(`
|
|
100
|
-
`);
|
|
101
|
-
return `package main
|
|
102
|
-
|
|
103
|
-
import (
|
|
104
|
-
"fmt"
|
|
105
|
-
"net/http"
|
|
106
|
-
"io/ioutil"
|
|
107
|
-
"strings"
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
func main() {${s}
|
|
111
|
-
${i}
|
|
112
|
-
|
|
113
|
-
client := &http.Client{}
|
|
114
|
-
resp, _ := client.Do(req)
|
|
115
|
-
defer resp.Body.Close()
|
|
116
|
-
|
|
117
|
-
body, _ := ioutil.ReadAll(resp.Body)
|
|
118
|
-
fmt.Println(string(body))
|
|
119
|
-
}`;
|
|
120
|
-
}
|
|
121
|
-
generateJava(r, o, t, e) {
|
|
122
|
-
const s = Object.entries(t).map(([n, a]) => ` .header("${n}", "${a}")`).join(`
|
|
123
|
-
`), i = e ? `.POST(HttpRequest.BodyPublishers.ofString(${JSON.stringify(e)}))` : `.method("${r.toUpperCase()}", HttpRequest.BodyPublishers.noBody())`;
|
|
124
|
-
return `import java.net.http.*;
|
|
125
|
-
import java.net.URI;
|
|
126
|
-
|
|
127
|
-
public class Main {
|
|
128
|
-
public static void main(String[] args) throws Exception {
|
|
129
|
-
HttpClient client = HttpClient.newHttpClient();
|
|
130
|
-
HttpRequest request = HttpRequest.newBuilder()
|
|
131
|
-
.uri(URI.create("${o}"))
|
|
132
|
-
${s}
|
|
133
|
-
${i}
|
|
134
|
-
.build();
|
|
135
|
-
|
|
136
|
-
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
|
137
|
-
System.out.println(response.body());
|
|
138
|
-
}
|
|
139
|
-
}`;
|
|
140
|
-
}
|
|
141
|
-
generateRuby(r, o, t, e) {
|
|
142
|
-
const s = Object.entries(t).map(([n, a]) => `request["${n}"] = "${a}"`).join(`
|
|
143
|
-
`), i = e ? `
|
|
144
|
-
request.body = ${JSON.stringify(e)}` : "";
|
|
145
|
-
return `require 'net/http'
|
|
146
|
-
require 'uri'
|
|
147
|
-
|
|
148
|
-
uri = URI.parse("${o}")
|
|
149
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
|
150
|
-
request = Net::HTTP::${r.charAt(0).toUpperCase() + r.slice(1).toLowerCase()}.new(uri.request_uri)
|
|
151
|
-
${s}${i}
|
|
152
|
-
|
|
153
|
-
response = http.request(request)
|
|
154
|
-
puts response.body`;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
const T = ({
|
|
158
|
-
request: l,
|
|
159
|
-
pathInputs: r,
|
|
160
|
-
apiReferenceData: o,
|
|
161
|
-
snippetPresets: t = R,
|
|
162
|
-
isMultipleRequest: e = !1
|
|
4
|
+
const N = ({
|
|
5
|
+
request: r,
|
|
6
|
+
pathInputs: p,
|
|
7
|
+
apiReferenceData: s,
|
|
8
|
+
snippetPresets: i = R,
|
|
9
|
+
isMultipleRequest: c = !1
|
|
163
10
|
}) => {
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
return
|
|
167
|
-
}),
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
11
|
+
const a = {}, g = /:{[^{}]+}/g, m = r.url.replace(g, (t) => {
|
|
12
|
+
const e = ":62437";
|
|
13
|
+
return a[e] = t, e;
|
|
14
|
+
}), f = /{[^{}]+}/g, d = m.replace(f, (t) => {
|
|
15
|
+
const e = t.slice(1, t.length - 1), n = p[e];
|
|
16
|
+
if (t === "{endpoint}")
|
|
170
17
|
return "https://{endpoint}";
|
|
171
|
-
if (
|
|
172
|
-
return `${encodeURIComponent(
|
|
173
|
-
const
|
|
174
|
-
return
|
|
175
|
-
}),
|
|
176
|
-
...
|
|
177
|
-
url:
|
|
178
|
-
postData:
|
|
18
|
+
if (n && (typeof n != "string" || n.length > 0))
|
|
19
|
+
return `${encodeURIComponent(n.toString())}`;
|
|
20
|
+
const o = x();
|
|
21
|
+
return a[o] = t, o;
|
|
22
|
+
}), h = new U({
|
|
23
|
+
...r,
|
|
24
|
+
url: d,
|
|
25
|
+
postData: r.postData || { mimeType: "application/json" }
|
|
179
26
|
});
|
|
180
|
-
return
|
|
181
|
-
var
|
|
182
|
-
const { filename:
|
|
27
|
+
return i.map((t) => {
|
|
28
|
+
var u;
|
|
29
|
+
const { filename: e, snippet: n, language: o } = t, { target: P, client: S } = n, l = h.convert(P, S), T = j(a, (l == null ? void 0 : l.toString()) || "");
|
|
183
30
|
return {
|
|
184
|
-
filename:
|
|
185
|
-
code:
|
|
186
|
-
language:
|
|
31
|
+
filename: c ? e : ((u = s.operation) == null ? void 0 : u.title) || e,
|
|
32
|
+
code: T,
|
|
33
|
+
language: o
|
|
187
34
|
};
|
|
188
35
|
});
|
|
189
|
-
},
|
|
36
|
+
}, j = (r, p) => Object.entries(r).reduce((s, [i, c]) => s.replace(i, c), p);
|
|
190
37
|
export {
|
|
191
|
-
|
|
38
|
+
N as generateSnippet
|
|
192
39
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ClipboardCheckmarkRegular as
|
|
3
|
-
import
|
|
1
|
+
import { jsxs as _, jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import { ClipboardCheckmarkRegular as E, Copy20Regular as P } from "@fluentui/react-icons";
|
|
3
|
+
import g from "prismjs";
|
|
4
4
|
import "prismjs/components/prism-bash.js";
|
|
5
5
|
import "prismjs/components/prism-csharp.js";
|
|
6
6
|
import "prismjs/components/prism-javascript.js";
|
|
@@ -9,167 +9,174 @@ import "prismjs/components/prism-markdown.js";
|
|
|
9
9
|
import "prismjs/components/prism-powershell.js";
|
|
10
10
|
import "prismjs/components/prism-python.js";
|
|
11
11
|
import "prismjs/components/prism-typescript.js";
|
|
12
|
-
import
|
|
13
|
-
import { cn as
|
|
14
|
-
import { getNodeText as
|
|
15
|
-
import { getCodeBlockScrollbarClassname as
|
|
16
|
-
const
|
|
12
|
+
import z, { useState as v, useEffect as F } from "react";
|
|
13
|
+
import { cn as p } from "../../utils/cn.js";
|
|
14
|
+
import { getNodeText as D } from "../../utils/get-node-text.js";
|
|
15
|
+
import { getCodeBlockScrollbarClassname as H } from "../../utils/getScrollbarClassname.js";
|
|
16
|
+
const T = ["image/png", "text/plain"];
|
|
17
17
|
function y() {
|
|
18
|
-
const [t, e] =
|
|
18
|
+
const [t, e] = v(!1), r = async (n) => {
|
|
19
19
|
try {
|
|
20
20
|
await navigator.clipboard.writeText(n), e(!0), setTimeout(() => e(!1), 2e3);
|
|
21
|
-
} catch (
|
|
22
|
-
console.error("Failed to copy to clipboard:",
|
|
21
|
+
} catch (i) {
|
|
22
|
+
console.error("Failed to copy to clipboard:", i);
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
return { isCopied: t, copy:
|
|
25
|
+
return { isCopied: t, copy: r, copyBlob: async (n, i) => {
|
|
26
26
|
try {
|
|
27
|
-
if (
|
|
28
|
-
const
|
|
29
|
-
[
|
|
27
|
+
if (T.includes(i)) {
|
|
28
|
+
const a = await n.arrayBuffer(), m = new Blob([a], { type: i }), u = new ClipboardItem({
|
|
29
|
+
[i]: m
|
|
30
30
|
});
|
|
31
|
-
await navigator.clipboard.write([
|
|
31
|
+
await navigator.clipboard.write([u]), e(!0), setTimeout(() => e(!1), 2e3);
|
|
32
32
|
} else {
|
|
33
|
-
const
|
|
34
|
-
await
|
|
33
|
+
const a = await n.text();
|
|
34
|
+
await r(a);
|
|
35
35
|
}
|
|
36
|
-
} catch (
|
|
37
|
-
console.error("Failed to copy blob to clipboard:",
|
|
36
|
+
} catch (a) {
|
|
37
|
+
console.error("Failed to copy blob to clipboard:", a);
|
|
38
38
|
try {
|
|
39
|
-
const
|
|
40
|
-
await
|
|
41
|
-
} catch (
|
|
42
|
-
console.error("Failed to copy as text fallback:",
|
|
39
|
+
const m = await n.text();
|
|
40
|
+
await r(m);
|
|
41
|
+
} catch (m) {
|
|
42
|
+
console.error("Failed to copy as text fallback:", m);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
} };
|
|
46
46
|
}
|
|
47
|
-
function
|
|
48
|
-
return /* @__PURE__ */
|
|
49
|
-
|
|
50
|
-
/* @__PURE__ */
|
|
47
|
+
function C({ onClick: t, isCopied: e, showTooltip: r = !0 }) {
|
|
48
|
+
return /* @__PURE__ */ _("div", { className: "mint:relative", children: [
|
|
49
|
+
r && e && /* @__PURE__ */ o("div", { className: "mint:absolute mint:bottom-[calc(100%+0.5rem)] mint:left-1/2 mint:-translate-x-1/2 mint:bg-white mint:dark:bg-[#1a1a1a] mint:text-[#171717] mint:dark:text-[#fafafa] mint:px-2.5 mint:py-1.5 mint:rounded-md mint:text-xs mint:font-medium mint:whitespace-nowrap mint:shadow-[0_4px_6px_-1px_rgba(0,0,0,0.1),0_2px_4px_-1px_rgba(0,0,0,0.06)] mint:dark:shadow-[0_4px_6px_-1px_rgba(0,0,0,0.3),0_2px_4px_-1px_rgba(0,0,0,0.2)] mint:z-10 mint:animate-[fadeIn_0.15s_ease-out] mint:after:content-[''] mint:after:absolute mint:after:top-full mint:after:left-1/2 mint:after:-translate-x-1/2 mint:after:w-0 mint:after:h-0 mint:after:border-l-[6px] mint:after:border-l-transparent mint:after:border-r-[6px] mint:after:border-r-transparent mint:after:border-t-[6px] mint:after:border-t-white mint:dark:after:border-t-[#1a1a1a]", children: "Copied!" }),
|
|
50
|
+
/* @__PURE__ */ o(
|
|
51
51
|
"button",
|
|
52
52
|
{
|
|
53
53
|
onClick: t,
|
|
54
54
|
className: "mint:flex mint:items-center mint:gap-1.5 mint:px-2 mint:py-1 mint:text-xs mint:text-[#737373] mint:dark:text-[#a3a3a3] mint:rounded mint:transition-colors mint:duration-150 mint:border-none mint:bg-transparent mint:cursor-pointer mint:hover:text-[#9263f1] mint:dark:hover:text-[#c9aaf9]",
|
|
55
55
|
"aria-label": e ? "Copied" : "Copy code",
|
|
56
|
-
children: e ? /* @__PURE__ */
|
|
56
|
+
children: e ? /* @__PURE__ */ o(E, { className: "mint:w-5 mint:h-5 mint:text-[#737373] mint:dark:text-[#a3a3a3]" }) : /* @__PURE__ */ o(P, { className: "mint:w-5 mint:h-5" })
|
|
57
57
|
}
|
|
58
58
|
)
|
|
59
59
|
] });
|
|
60
60
|
}
|
|
61
|
-
function
|
|
61
|
+
function tt({
|
|
62
62
|
textToCopy: t,
|
|
63
63
|
showTooltip: e = !0
|
|
64
64
|
}) {
|
|
65
|
-
const { isCopied:
|
|
66
|
-
return /* @__PURE__ */
|
|
65
|
+
const { isCopied: r, copy: c } = y();
|
|
66
|
+
return /* @__PURE__ */ o(C, { onClick: () => {
|
|
67
67
|
c(t);
|
|
68
|
-
}, isCopied:
|
|
68
|
+
}, isCopied: r, showTooltip: e });
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function et({
|
|
71
71
|
data: t,
|
|
72
72
|
showTooltip: e = !0
|
|
73
73
|
}) {
|
|
74
|
-
const { isCopied:
|
|
75
|
-
return /* @__PURE__ */
|
|
76
|
-
t.contentType &&
|
|
77
|
-
}, isCopied:
|
|
74
|
+
const { isCopied: r, copy: c, copyBlob: n } = y();
|
|
75
|
+
return /* @__PURE__ */ o(C, { onClick: () => {
|
|
76
|
+
t.contentType && T.includes(t.contentType) ? n(t.blob, t.contentType) : t.type === "other" && t.content ? c(t.content) : console.error("Unsupported content type for clipboard");
|
|
77
|
+
}, isCopied: r, showTooltip: e });
|
|
78
78
|
}
|
|
79
|
-
function
|
|
79
|
+
function ot({
|
|
80
80
|
children: t,
|
|
81
81
|
className: e,
|
|
82
|
-
fileName:
|
|
82
|
+
fileName: r,
|
|
83
83
|
language: c,
|
|
84
84
|
blob: n,
|
|
85
|
-
contentType:
|
|
86
|
-
dataGroup:
|
|
85
|
+
contentType: i,
|
|
86
|
+
dataGroup: a = !1,
|
|
87
|
+
showCopyButton: m = !0
|
|
87
88
|
}) {
|
|
88
|
-
const [
|
|
89
|
-
|
|
90
|
-
const s = c || (e == null ? void 0 : e.replace(/^language-/, "")) || "text", u = j(t), T = !!o, g = A.useMemo(() => {
|
|
91
|
-
var x, C;
|
|
89
|
+
const [u, k] = v(""), { isCopied: B, copy: N, copyBlob: I } = y(), s = c || (e == null ? void 0 : e.replace(/^language-/, "")) || "text", d = D(t), S = !!r, h = z.useMemo(() => {
|
|
90
|
+
var x, w;
|
|
92
91
|
if (typeof t != "object" || t == null)
|
|
93
92
|
return !1;
|
|
94
|
-
const
|
|
95
|
-
for (const l of
|
|
93
|
+
const f = Array.isArray(t) ? t : [t];
|
|
94
|
+
for (const l of f)
|
|
96
95
|
if (typeof l == "object" && l != null && "props" in l && ((x = l.props) != null && x.children)) {
|
|
97
|
-
const
|
|
98
|
-
for (const b of
|
|
99
|
-
if (typeof b == "object" && b != null && "props" in b && ((
|
|
96
|
+
const j = Array.isArray(l.props.children) ? l.props.children : [l.props.children];
|
|
97
|
+
for (const b of j)
|
|
98
|
+
if (typeof b == "object" && b != null && "props" in b && ((w = b.props) != null && w.className))
|
|
100
99
|
return !0;
|
|
101
100
|
}
|
|
102
101
|
return !1;
|
|
103
102
|
}, [t]);
|
|
104
|
-
|
|
105
|
-
if (!
|
|
103
|
+
F(() => {
|
|
104
|
+
if (!h)
|
|
106
105
|
try {
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
} catch (
|
|
110
|
-
console.error("Failed to highlight code:",
|
|
106
|
+
const f = g.languages[s] || g.languages.plaintext, x = g.highlight(d, f, s);
|
|
107
|
+
k(x);
|
|
108
|
+
} catch (f) {
|
|
109
|
+
console.error("Failed to highlight code:", f), k(d);
|
|
111
110
|
}
|
|
112
|
-
}, [
|
|
113
|
-
const
|
|
114
|
-
|
|
111
|
+
}, [d, s, h]);
|
|
112
|
+
const A = () => {
|
|
113
|
+
n && i ? I(n, i) : N(d);
|
|
114
|
+
}, R = H("system", a);
|
|
115
|
+
return /* @__PURE__ */ _(
|
|
115
116
|
"div",
|
|
116
117
|
{
|
|
117
|
-
className:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
118
|
+
className: p(
|
|
119
|
+
"mint:relative",
|
|
120
|
+
S ? "mint:flex mint:flex-col mint:gap-2 mint:px-0.5 mint:pb-0.5 mint:rounded-xl mint:overflow-hidden" : void 0
|
|
121
|
+
),
|
|
122
|
+
"data-group": a,
|
|
123
|
+
children: [
|
|
124
|
+
m && /* @__PURE__ */ o("div", { className: "mint:absolute mint:top-2 mint:right-2 mint:z-10", children: /* @__PURE__ */ o(C, { onClick: A, isCopied: B, showTooltip: !0 }) }),
|
|
125
|
+
/* @__PURE__ */ o(
|
|
126
|
+
"div",
|
|
127
|
+
{
|
|
128
|
+
className: p(
|
|
129
|
+
"not-prose mint:relative mint:rounded-xl mint:bg-[#f5f5f5] mint:dark:bg-[#141414] code-block-wrapper",
|
|
130
|
+
"mint:px-4 mint:py-2 mint:overflow-scroll mint:[scrollbar-gutter:stable] mint:scrollbar-track-zinc-200 mint:dark:scrollbar-track-zinc-800",
|
|
131
|
+
R,
|
|
132
|
+
a && "mint:group"
|
|
133
|
+
),
|
|
134
|
+
children: /* @__PURE__ */ o(
|
|
135
|
+
"pre",
|
|
136
|
+
{
|
|
137
|
+
className: p(
|
|
138
|
+
"mint:m-0 mint:whitespace-pre mint:text-sm"
|
|
139
|
+
),
|
|
140
|
+
children: h ? /* @__PURE__ */ o(
|
|
141
|
+
"code",
|
|
142
|
+
{
|
|
143
|
+
className: p(
|
|
144
|
+
`language-${s}`,
|
|
145
|
+
"mint:block mint:text-[#24292e] mint:dark:text-[#e6edf3]"
|
|
146
|
+
),
|
|
147
|
+
children: t
|
|
148
|
+
}
|
|
149
|
+
) : u ? /* @__PURE__ */ o(
|
|
150
|
+
"code",
|
|
151
|
+
{
|
|
152
|
+
className: p(
|
|
153
|
+
`language-${s}`,
|
|
154
|
+
"mint:block mint:text-[#24292e] mint:dark:text-[#e6edf3]"
|
|
155
|
+
),
|
|
156
|
+
dangerouslySetInnerHTML: { __html: u }
|
|
157
|
+
}
|
|
158
|
+
) : /* @__PURE__ */ o(
|
|
159
|
+
"code",
|
|
160
|
+
{
|
|
161
|
+
className: p(
|
|
162
|
+
`language-${s}`,
|
|
163
|
+
"mint:block mint:text-[#24292e] mint:dark:text-[#e6edf3]"
|
|
164
|
+
),
|
|
165
|
+
children: d
|
|
166
|
+
}
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
)
|
|
170
|
+
}
|
|
171
|
+
)
|
|
172
|
+
]
|
|
166
173
|
}
|
|
167
174
|
);
|
|
168
175
|
}
|
|
169
176
|
export {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
177
|
+
ot as CodeBlock,
|
|
178
|
+
et as CopyDataToClipboardButton,
|
|
179
|
+
C as CopyIconButton,
|
|
180
|
+
tt as CopyToClipboardButton,
|
|
174
181
|
y as useCopyToClipboard
|
|
175
182
|
};
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { jsx as a } from "react/jsx-runtime";
|
|
2
|
-
import { CodeBlock as
|
|
3
|
-
import { CodeGroup as
|
|
4
|
-
import { CodeSnippet as
|
|
5
|
-
const
|
|
2
|
+
import { CodeBlock as u } from "./code-block.js";
|
|
3
|
+
import { CodeGroup as d } from "./code-group.js";
|
|
4
|
+
import { CodeSnippet as f } from "./code-snippet.js";
|
|
5
|
+
const p = ({
|
|
6
6
|
snippets: o,
|
|
7
7
|
dropdown: r,
|
|
8
8
|
maxHeight: l,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
showCopyButton: m,
|
|
10
|
+
...g
|
|
11
|
+
}) => /* @__PURE__ */ a(d, { isSmallText: !0, ...g, dropdown: r, noMargins: !0, className: l, children: o.map(({ code: n, ...e }, i) => /* @__PURE__ */ a(
|
|
12
|
+
u,
|
|
12
13
|
{
|
|
13
14
|
language: e.language,
|
|
14
15
|
fileName: e.filename,
|
|
15
|
-
|
|
16
|
+
showCopyButton: m,
|
|
17
|
+
children: /* @__PURE__ */ a(f, { language: e.language, children: n })
|
|
16
18
|
},
|
|
17
|
-
`${e.filename}-${e.language}-${
|
|
19
|
+
`${e.filename}-${e.language}-${i}`
|
|
18
20
|
)) });
|
|
19
21
|
export {
|
|
20
|
-
|
|
22
|
+
p as CodeSnippets
|
|
21
23
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -240,7 +240,7 @@ export declare function cleanTitle(title: string): string;
|
|
|
240
240
|
|
|
241
241
|
export declare function cn(...inputs: ClassValue[]): string;
|
|
242
242
|
|
|
243
|
-
export declare function CodeBlock({ children, className, fileName, language, blob, contentType, dataGroup, }: CodeBlockProps): JSX_2.Element;
|
|
243
|
+
export declare function CodeBlock({ children, className, fileName, language, blob, contentType, dataGroup, showCopyButton, }: CodeBlockProps): JSX_2.Element;
|
|
244
244
|
|
|
245
245
|
declare interface CodeBlockProps {
|
|
246
246
|
children: default_2.ReactNode;
|
|
@@ -250,6 +250,7 @@ declare interface CodeBlockProps {
|
|
|
250
250
|
blob?: Blob;
|
|
251
251
|
contentType?: string;
|
|
252
252
|
dataGroup?: boolean;
|
|
253
|
+
showCopyButton?: boolean;
|
|
253
254
|
}
|
|
254
255
|
|
|
255
256
|
export declare type CodeExample = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mintlify/msft-sdk",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.61",
|
|
4
4
|
"description": "Lightweight SDK for Microsoft documentation with MDX rendering",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"@mintlify/validation": "^0.1.513",
|
|
57
57
|
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
|
58
58
|
"@radix-ui/react-tabs": "^1.1.3",
|
|
59
|
+
"@readme/httpsnippet": "^11.0.0",
|
|
59
60
|
"@sindresorhus/slugify": "^3.0.0",
|
|
60
61
|
"@tailwindcss/typography": "^0.5.19",
|
|
61
62
|
"@types/har-format": "^1.2.16",
|