@mintlify/msft-sdk 1.1.60 → 1.1.62
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-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 +36 -35
- package/dist/components/content-components/code-snippets.js +12 -10
- package/dist/httpsnippet/src/helpers/code-builder.js +27 -0
- package/dist/httpsnippet/src/helpers/escape.js +11 -0
- package/dist/httpsnippet/src/helpers/headers.js +13 -0
- package/dist/httpsnippet/src/helpers/reducer.js +7 -0
- package/dist/httpsnippet/src/helpers/shell.js +5 -0
- package/dist/httpsnippet/src/helpers/url-format.js +35 -0
- package/dist/httpsnippet/src/helpers/url-parse.js +76 -0
- package/dist/httpsnippet/src/index.js +157 -0
- package/dist/httpsnippet/src/targets/c/libcurl/client.js +22 -0
- package/dist/httpsnippet/src/targets/c/target.js +15 -0
- package/dist/httpsnippet/src/targets/clojure/clj_http/client.js +120 -0
- package/dist/httpsnippet/src/targets/clojure/target.js +14 -0
- package/dist/httpsnippet/src/targets/csharp/httpclient/client.js +76 -0
- package/dist/httpsnippet/src/targets/csharp/restsharp/client.js +63 -0
- package/dist/httpsnippet/src/targets/csharp/target.js +17 -0
- package/dist/httpsnippet/src/targets/go/native/client.js +24 -0
- package/dist/httpsnippet/src/targets/go/target.js +15 -0
- package/dist/httpsnippet/src/targets/http/http1.1/client.js +34 -0
- package/dist/httpsnippet/src/targets/http/target.js +14 -0
- package/dist/httpsnippet/src/targets/index.js +43 -0
- package/dist/httpsnippet/src/targets/java/asynchttp/client.js +23 -0
- package/dist/httpsnippet/src/targets/java/nethttp/client.js +28 -0
- package/dist/httpsnippet/src/targets/java/okhttp/client.js +23 -0
- package/dist/httpsnippet/src/targets/java/target.js +20 -0
- package/dist/httpsnippet/src/targets/java/unirest/client.js +23 -0
- package/dist/httpsnippet/src/targets/javascript/axios/client.js +50 -0
- package/dist/httpsnippet/src/targets/javascript/fetch/client.js +61 -0
- package/dist/httpsnippet/src/targets/javascript/jquery/client.js +51 -0
- package/dist/httpsnippet/src/targets/javascript/target.js +20 -0
- package/dist/httpsnippet/src/targets/javascript/xhr/client.js +49 -0
- package/dist/httpsnippet/src/targets/json/native/client.js +39 -0
- package/dist/httpsnippet/src/targets/json/target.js +14 -0
- package/dist/httpsnippet/src/targets/kotlin/okhttp/client.js +23 -0
- package/dist/httpsnippet/src/targets/kotlin/target.js +14 -0
- package/dist/httpsnippet/src/targets/node/axios/client.js +40 -0
- package/dist/httpsnippet/src/targets/node/fetch/client.js +68 -0
- package/dist/httpsnippet/src/targets/node/native/client.js +45 -0
- package/dist/httpsnippet/src/targets/node/target.js +19 -0
- package/dist/httpsnippet/src/targets/objc/helpers.js +27 -0
- package/dist/httpsnippet/src/targets/objc/nsurlsession/client.js +63 -0
- package/dist/httpsnippet/src/targets/objc/target.js +14 -0
- package/dist/httpsnippet/src/targets/ocaml/cohttp/client.js +32 -0
- package/dist/httpsnippet/src/targets/ocaml/target.js +14 -0
- package/dist/httpsnippet/src/targets/php/curl/client.js +85 -0
- package/dist/httpsnippet/src/targets/php/guzzle/client.js +57 -0
- package/dist/httpsnippet/src/targets/php/helpers.js +65 -0
- package/dist/httpsnippet/src/targets/php/http1/client.js +28 -0
- package/dist/httpsnippet/src/targets/php/http2/client.js +55 -0
- package/dist/httpsnippet/src/targets/php/target.js +21 -0
- package/dist/httpsnippet/src/targets/powershell/common.js +19 -0
- package/dist/httpsnippet/src/targets/powershell/restmethod/client.js +14 -0
- package/dist/httpsnippet/src/targets/powershell/target.js +16 -0
- package/dist/httpsnippet/src/targets/powershell/webrequest/client.js +14 -0
- package/dist/httpsnippet/src/targets/python/helpers.js +33 -0
- package/dist/httpsnippet/src/targets/python/requests/client.js +74 -0
- package/dist/httpsnippet/src/targets/python/target.js +15 -0
- package/dist/httpsnippet/src/targets/r/httr/client.js +46 -0
- package/dist/httpsnippet/src/targets/r/target.js +14 -0
- package/dist/httpsnippet/src/targets/ruby/native/client.js +37 -0
- package/dist/httpsnippet/src/targets/ruby/target.js +14 -0
- package/dist/httpsnippet/src/targets/shell/curl/client.js +92 -0
- package/dist/httpsnippet/src/targets/shell/httpie/client.js +56 -0
- package/dist/httpsnippet/src/targets/shell/target.js +19 -0
- package/dist/httpsnippet/src/targets/shell/wget/client.js +30 -0
- package/dist/httpsnippet/src/targets/swift/helpers.js +38 -0
- package/dist/httpsnippet/src/targets/swift/target.js +14 -0
- package/dist/httpsnippet/src/targets/swift/urlsession/client.js +59 -0
- package/dist/index.d.ts +2 -1
- package/package.json +17 -3
|
@@ -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 "../../httpsnippet/src/index.js";
|
|
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,5 +1,5 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { ClipboardCheckmarkRegular as
|
|
1
|
+
import { jsxs as _, jsx as o } from "react/jsx-runtime";
|
|
2
|
+
import { ClipboardCheckmarkRegular as E, Copy20Regular as P } from "@fluentui/react-icons";
|
|
3
3
|
import g from "prismjs";
|
|
4
4
|
import "prismjs/components/prism-bash.js";
|
|
5
5
|
import "prismjs/components/prism-csharp.js";
|
|
@@ -9,13 +9,13 @@ 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
|
|
12
|
+
import z, { useState as v, useEffect as F } from "react";
|
|
13
13
|
import { cn as p } from "../../utils/cn.js";
|
|
14
|
-
import { getNodeText as
|
|
15
|
-
import { getCodeBlockScrollbarClassname as
|
|
16
|
-
const
|
|
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
21
|
} catch (i) {
|
|
@@ -24,7 +24,7 @@ function y() {
|
|
|
24
24
|
};
|
|
25
25
|
return { isCopied: t, copy: r, copyBlob: async (n, i) => {
|
|
26
26
|
try {
|
|
27
|
-
if (
|
|
27
|
+
if (T.includes(i)) {
|
|
28
28
|
const a = await n.arrayBuffer(), m = new Blob([a], { type: i }), u = new ClipboardItem({
|
|
29
29
|
[i]: m
|
|
30
30
|
});
|
|
@@ -45,7 +45,7 @@ function y() {
|
|
|
45
45
|
} };
|
|
46
46
|
}
|
|
47
47
|
function C({ onClick: t, isCopied: e, showTooltip: r = !0 }) {
|
|
48
|
-
return /* @__PURE__ */
|
|
48
|
+
return /* @__PURE__ */ _("div", { className: "mint:relative", children: [
|
|
49
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
50
|
/* @__PURE__ */ o(
|
|
51
51
|
"button",
|
|
@@ -53,12 +53,12 @@ function C({ onClick: t, isCopied: e, showTooltip: r = !0 }) {
|
|
|
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__ */ o(
|
|
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
|
}) {
|
|
@@ -67,67 +67,68 @@ function G({
|
|
|
67
67
|
c(t);
|
|
68
68
|
}, isCopied: r, showTooltip: e });
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function et({
|
|
71
71
|
data: t,
|
|
72
72
|
showTooltip: e = !0
|
|
73
73
|
}) {
|
|
74
74
|
const { isCopied: r, copy: c, copyBlob: n } = y();
|
|
75
75
|
return /* @__PURE__ */ o(C, { onClick: () => {
|
|
76
|
-
t.contentType &&
|
|
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
77
|
}, isCopied: r, showTooltip: e });
|
|
78
78
|
}
|
|
79
|
-
function
|
|
79
|
+
function ot({
|
|
80
80
|
children: t,
|
|
81
81
|
className: e,
|
|
82
82
|
fileName: r,
|
|
83
83
|
language: c,
|
|
84
84
|
blob: n,
|
|
85
85
|
contentType: i,
|
|
86
|
-
dataGroup: a = !1
|
|
86
|
+
dataGroup: a = !1,
|
|
87
|
+
showCopyButton: m = !0
|
|
87
88
|
}) {
|
|
88
|
-
const [
|
|
89
|
-
var x,
|
|
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;
|
|
90
91
|
if (typeof t != "object" || t == null)
|
|
91
92
|
return !1;
|
|
92
93
|
const f = Array.isArray(t) ? t : [t];
|
|
93
94
|
for (const l of f)
|
|
94
95
|
if (typeof l == "object" && l != null && "props" in l && ((x = l.props) != null && x.children)) {
|
|
95
|
-
const
|
|
96
|
-
for (const b of
|
|
97
|
-
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))
|
|
98
99
|
return !0;
|
|
99
100
|
}
|
|
100
101
|
return !1;
|
|
101
102
|
}, [t]);
|
|
102
|
-
|
|
103
|
+
F(() => {
|
|
103
104
|
if (!h)
|
|
104
105
|
try {
|
|
105
106
|
const f = g.languages[s] || g.languages.plaintext, x = g.highlight(d, f, s);
|
|
106
|
-
|
|
107
|
+
k(x);
|
|
107
108
|
} catch (f) {
|
|
108
|
-
console.error("Failed to highlight code:", f),
|
|
109
|
+
console.error("Failed to highlight code:", f), k(d);
|
|
109
110
|
}
|
|
110
111
|
}, [d, s, h]);
|
|
111
|
-
const
|
|
112
|
-
n && i ?
|
|
113
|
-
},
|
|
114
|
-
return /* @__PURE__ */
|
|
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
118
|
className: p(
|
|
118
119
|
"mint:relative",
|
|
119
|
-
|
|
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
|
|
120
121
|
),
|
|
121
122
|
"data-group": a,
|
|
122
123
|
children: [
|
|
123
|
-
/* @__PURE__ */ o("div", { className: "mint:absolute mint:top-2 mint:right-2 mint:z-10", children: /* @__PURE__ */ o(C, { onClick:
|
|
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 }) }),
|
|
124
125
|
/* @__PURE__ */ o(
|
|
125
126
|
"div",
|
|
126
127
|
{
|
|
127
128
|
className: p(
|
|
128
129
|
"not-prose mint:relative mint:rounded-xl mint:bg-[#f5f5f5] mint:dark:bg-[#141414] code-block-wrapper",
|
|
129
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",
|
|
130
|
-
|
|
131
|
+
R,
|
|
131
132
|
a && "mint:group"
|
|
132
133
|
),
|
|
133
134
|
children: /* @__PURE__ */ o(
|
|
@@ -145,14 +146,14 @@ function et({
|
|
|
145
146
|
),
|
|
146
147
|
children: t
|
|
147
148
|
}
|
|
148
|
-
) :
|
|
149
|
+
) : u ? /* @__PURE__ */ o(
|
|
149
150
|
"code",
|
|
150
151
|
{
|
|
151
152
|
className: p(
|
|
152
153
|
`language-${s}`,
|
|
153
154
|
"mint:block mint:text-[#24292e] mint:dark:text-[#e6edf3]"
|
|
154
155
|
),
|
|
155
|
-
dangerouslySetInnerHTML: { __html:
|
|
156
|
+
dangerouslySetInnerHTML: { __html: u }
|
|
156
157
|
}
|
|
157
158
|
) : /* @__PURE__ */ o(
|
|
158
159
|
"code",
|
|
@@ -173,9 +174,9 @@ function et({
|
|
|
173
174
|
);
|
|
174
175
|
}
|
|
175
176
|
export {
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
ot as CodeBlock,
|
|
178
|
+
et as CopyDataToClipboardButton,
|
|
178
179
|
C as CopyIconButton,
|
|
179
|
-
|
|
180
|
+
tt as CopyToClipboardButton,
|
|
180
181
|
y as useCopyToClipboard
|
|
181
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
|
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const n = "", e = `
|
|
2
|
+
`;
|
|
3
|
+
class d {
|
|
4
|
+
/**
|
|
5
|
+
* Helper object to format and aggragate lines of code.
|
|
6
|
+
* Lines are aggregated in a `code` array, and need to be joined to obtain a proper code snippet.
|
|
7
|
+
*/
|
|
8
|
+
constructor({ indent: o, join: h } = {}) {
|
|
9
|
+
this.postProcessors = [], this.code = [], this.indentationCharacter = n, this.lineJoin = e, this.indentLine = (t, s = 0) => `${this.indentationCharacter.repeat(s)}${t}`, this.unshift = (t, s) => {
|
|
10
|
+
const i = this.indentLine(t, s);
|
|
11
|
+
this.code.unshift(i);
|
|
12
|
+
}, this.push = (t, s) => {
|
|
13
|
+
const i = this.indentLine(t, s);
|
|
14
|
+
this.code.push(i);
|
|
15
|
+
}, this.blank = () => {
|
|
16
|
+
this.code.push("");
|
|
17
|
+
}, this.join = () => {
|
|
18
|
+
const t = this.code.join(this.lineJoin);
|
|
19
|
+
return this.postProcessors.reduce((i, r) => r(i), t);
|
|
20
|
+
}, this.addPostProcessor = (t) => {
|
|
21
|
+
this.postProcessors = [...this.postProcessors, t];
|
|
22
|
+
}, this.indentationCharacter = o || n, this.lineJoin = h ?? e;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
d as CodeBuilder
|
|
27
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function s(t, u = {}) {
|
|
2
|
+
const { delimiter: n = '"', escapeChar: r = "\\", escapeNewlines: i = !0 } = u;
|
|
3
|
+
return [...t.toString()].map((e) => e === "\b" ? `${r}b` : e === " " ? `${r}t` : e === `
|
|
4
|
+
` ? i ? `${r}n` : e : e === "\f" ? `${r}f` : e === "\r" ? i ? `${r}r` : e : e === r ? r + r : e === n ? r + n : e < " " || e > "~" ? JSON.stringify(e).slice(1, -1) : e).join("");
|
|
5
|
+
}
|
|
6
|
+
const f = (t) => s(t, { delimiter: "'" }), o = (t) => s(t, { delimiter: '"' });
|
|
7
|
+
export {
|
|
8
|
+
o as escapeForDoubleQuotes,
|
|
9
|
+
f as escapeForSingleQuotes,
|
|
10
|
+
s as escapeString
|
|
11
|
+
};
|