@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.
Files changed (73) hide show
  1. package/dist/api-playground-2/components/Example/GeneratedRequestExample.js +54 -54
  2. package/dist/api-playground-2/generators/generateSnippet.js +30 -183
  3. package/dist/components/content-components/code-block.js +36 -35
  4. package/dist/components/content-components/code-snippets.js +12 -10
  5. package/dist/httpsnippet/src/helpers/code-builder.js +27 -0
  6. package/dist/httpsnippet/src/helpers/escape.js +11 -0
  7. package/dist/httpsnippet/src/helpers/headers.js +13 -0
  8. package/dist/httpsnippet/src/helpers/reducer.js +7 -0
  9. package/dist/httpsnippet/src/helpers/shell.js +5 -0
  10. package/dist/httpsnippet/src/helpers/url-format.js +35 -0
  11. package/dist/httpsnippet/src/helpers/url-parse.js +76 -0
  12. package/dist/httpsnippet/src/index.js +157 -0
  13. package/dist/httpsnippet/src/targets/c/libcurl/client.js +22 -0
  14. package/dist/httpsnippet/src/targets/c/target.js +15 -0
  15. package/dist/httpsnippet/src/targets/clojure/clj_http/client.js +120 -0
  16. package/dist/httpsnippet/src/targets/clojure/target.js +14 -0
  17. package/dist/httpsnippet/src/targets/csharp/httpclient/client.js +76 -0
  18. package/dist/httpsnippet/src/targets/csharp/restsharp/client.js +63 -0
  19. package/dist/httpsnippet/src/targets/csharp/target.js +17 -0
  20. package/dist/httpsnippet/src/targets/go/native/client.js +24 -0
  21. package/dist/httpsnippet/src/targets/go/target.js +15 -0
  22. package/dist/httpsnippet/src/targets/http/http1.1/client.js +34 -0
  23. package/dist/httpsnippet/src/targets/http/target.js +14 -0
  24. package/dist/httpsnippet/src/targets/index.js +43 -0
  25. package/dist/httpsnippet/src/targets/java/asynchttp/client.js +23 -0
  26. package/dist/httpsnippet/src/targets/java/nethttp/client.js +28 -0
  27. package/dist/httpsnippet/src/targets/java/okhttp/client.js +23 -0
  28. package/dist/httpsnippet/src/targets/java/target.js +20 -0
  29. package/dist/httpsnippet/src/targets/java/unirest/client.js +23 -0
  30. package/dist/httpsnippet/src/targets/javascript/axios/client.js +50 -0
  31. package/dist/httpsnippet/src/targets/javascript/fetch/client.js +61 -0
  32. package/dist/httpsnippet/src/targets/javascript/jquery/client.js +51 -0
  33. package/dist/httpsnippet/src/targets/javascript/target.js +20 -0
  34. package/dist/httpsnippet/src/targets/javascript/xhr/client.js +49 -0
  35. package/dist/httpsnippet/src/targets/json/native/client.js +39 -0
  36. package/dist/httpsnippet/src/targets/json/target.js +14 -0
  37. package/dist/httpsnippet/src/targets/kotlin/okhttp/client.js +23 -0
  38. package/dist/httpsnippet/src/targets/kotlin/target.js +14 -0
  39. package/dist/httpsnippet/src/targets/node/axios/client.js +40 -0
  40. package/dist/httpsnippet/src/targets/node/fetch/client.js +68 -0
  41. package/dist/httpsnippet/src/targets/node/native/client.js +45 -0
  42. package/dist/httpsnippet/src/targets/node/target.js +19 -0
  43. package/dist/httpsnippet/src/targets/objc/helpers.js +27 -0
  44. package/dist/httpsnippet/src/targets/objc/nsurlsession/client.js +63 -0
  45. package/dist/httpsnippet/src/targets/objc/target.js +14 -0
  46. package/dist/httpsnippet/src/targets/ocaml/cohttp/client.js +32 -0
  47. package/dist/httpsnippet/src/targets/ocaml/target.js +14 -0
  48. package/dist/httpsnippet/src/targets/php/curl/client.js +85 -0
  49. package/dist/httpsnippet/src/targets/php/guzzle/client.js +57 -0
  50. package/dist/httpsnippet/src/targets/php/helpers.js +65 -0
  51. package/dist/httpsnippet/src/targets/php/http1/client.js +28 -0
  52. package/dist/httpsnippet/src/targets/php/http2/client.js +55 -0
  53. package/dist/httpsnippet/src/targets/php/target.js +21 -0
  54. package/dist/httpsnippet/src/targets/powershell/common.js +19 -0
  55. package/dist/httpsnippet/src/targets/powershell/restmethod/client.js +14 -0
  56. package/dist/httpsnippet/src/targets/powershell/target.js +16 -0
  57. package/dist/httpsnippet/src/targets/powershell/webrequest/client.js +14 -0
  58. package/dist/httpsnippet/src/targets/python/helpers.js +33 -0
  59. package/dist/httpsnippet/src/targets/python/requests/client.js +74 -0
  60. package/dist/httpsnippet/src/targets/python/target.js +15 -0
  61. package/dist/httpsnippet/src/targets/r/httr/client.js +46 -0
  62. package/dist/httpsnippet/src/targets/r/target.js +14 -0
  63. package/dist/httpsnippet/src/targets/ruby/native/client.js +37 -0
  64. package/dist/httpsnippet/src/targets/ruby/target.js +14 -0
  65. package/dist/httpsnippet/src/targets/shell/curl/client.js +92 -0
  66. package/dist/httpsnippet/src/targets/shell/httpie/client.js +56 -0
  67. package/dist/httpsnippet/src/targets/shell/target.js +19 -0
  68. package/dist/httpsnippet/src/targets/shell/wget/client.js +30 -0
  69. package/dist/httpsnippet/src/targets/swift/helpers.js +38 -0
  70. package/dist/httpsnippet/src/targets/swift/target.js +14 -0
  71. package/dist/httpsnippet/src/targets/swift/urlsession/client.js +59 -0
  72. package/dist/index.d.ts +2 -1
  73. package/package.json +17 -3
@@ -1,31 +1,31 @@
1
- import { jsx as M } from "react/jsx-runtime";
2
- import { useState as j, useEffect as E } from "react";
3
- import { generateRequest as S } from "../../generators/generateRequest.js";
4
- import { generateSnippet as a } from "../../generators/generateSnippet.js";
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 G } from "../../../components/content-components/CodeGroupSelect/index.js";
7
- import { CodeSnippets as P } from "../../../components/content-components/code-snippets.js";
8
- import { langToPresetMap as k } from "../../../constants/snippetPresets.js";
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: r,
10
+ baseUrl: s,
11
11
  apiReferenceData: t,
12
12
  inputs: e,
13
13
  requestExampleLanguages: u,
14
- requiredOnly: s,
14
+ requiredOnly: r,
15
15
  maxHeight: o,
16
16
  selectedSecurityOptionIndex: f
17
17
  }) => {
18
- var h, T, c, n, x;
19
- const p = (h = t.dependencies) == null ? void 0 : h.requestBody;
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__ */ M(
22
- B,
21
+ return /* @__PURE__ */ y(
22
+ a,
23
23
  {
24
24
  apiReferenceData: t,
25
- baseUrl: r,
25
+ baseUrl: s,
26
26
  inputs: e,
27
27
  requestExampleLanguages: u,
28
- requiredOnly: s,
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
- ([d, C]) => ({
37
- contentType: d,
38
- examples: C.examples
36
+ ([C, d]) => ({
37
+ contentType: C,
38
+ examples: d.examples
39
39
  })
40
40
  ), l = 0;
41
- return ((T = m[l]) == null ? void 0 : T.examples.length) > 1 ? /* @__PURE__ */ M(
42
- q,
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: r,
46
+ baseUrl: s,
47
47
  inputs: e,
48
48
  examples: (n = m[l]) == null ? void 0 : n.examples,
49
- requiredOnly: s,
49
+ requiredOnly: r,
50
50
  maxHeight: o,
51
51
  selectedSecurityOptionIndex: f
52
52
  }
53
- ) : /* @__PURE__ */ M(
54
- B,
53
+ ) : /* @__PURE__ */ y(
54
+ a,
55
55
  {
56
56
  apiReferenceData: t,
57
57
  selectedBodyContentType: (x = m[l]) == null ? void 0 : x.contentType,
58
- baseUrl: r,
58
+ baseUrl: s,
59
59
  inputs: e,
60
60
  exampleValue: i,
61
61
  requestExampleLanguages: u,
62
- requiredOnly: s,
62
+ requiredOnly: r,
63
63
  maxHeight: o,
64
64
  selectedSecurityOptionIndex: f
65
65
  }
66
66
  );
67
- }, B = ({
68
- baseUrl: r,
67
+ }, a = ({
68
+ baseUrl: s,
69
69
  apiReferenceData: t,
70
70
  inputs: e,
71
71
  selectedBodyContentType: u,
72
- exampleValue: s,
72
+ exampleValue: r,
73
73
  requestExampleLanguages: o,
74
74
  requiredOnly: f,
75
75
  maxHeight: p,
76
76
  selectedSecurityOptionIndex: i
77
77
  }) => {
78
- const m = S({
79
- baseUrl: r,
78
+ const m = j({
79
+ baseUrl: s,
80
80
  apiReferenceData: t,
81
81
  inputs: e,
82
82
  selectedBodyContentType: u,
83
- exampleData: s,
83
+ exampleData: r,
84
84
  requiredOnly: f,
85
85
  selectedSecurityOptionIndex: i
86
- }), l = o == null ? void 0 : o.reduce((T, c) => {
87
- const n = k[c];
88
- return n && T.push(n), T;
89
- }, []), h = a({
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__ */ M(P, { snippets: h, dropdown: !0, maxHeight: p });
96
- }, q = ({
97
- baseUrl: r,
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: s,
101
+ examples: r,
102
102
  requiredOnly: o,
103
103
  maxHeight: f,
104
104
  selectedSecurityOptionIndex: p
105
105
  }) => {
106
- const [i, m] = j({}), [l, h] = j(null);
106
+ const [i, m] = B({}), [l, T] = B(null);
107
107
  return E(() => {
108
- const T = e.path, c = {};
108
+ const h = e.path, c = {};
109
109
  try {
110
- for (const [n, { value: x }] of Object.entries(s)) {
110
+ for (const [n, { value: x }] of Object.entries(r)) {
111
111
  if (!x) continue;
112
- const d = S({
113
- baseUrl: r,
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
- a({
121
+ S({
122
122
  apiReferenceData: t,
123
- pathInputs: T,
124
- request: d,
123
+ pathInputs: h,
124
+ request: C,
125
125
  isMultipleRequest: !0
126
- }).forEach((y) => {
127
- c[y.filename] = {
128
- ...c[y.filename],
129
- [n]: y
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), h(n);
135
+ console.error(n), T(n);
136
136
  }
137
- }, [r, t, e, u, s, o, p]), l || Object.keys(i).length === 0 ? null : /* @__PURE__ */ M(G, { snippets: i, maxHeight: f });
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 { generateUniqueString as C } from "../../utils/uuid.js";
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
- class q {
4
- constructor(r) {
5
- this.request = r;
6
- }
7
- convert(r, o) {
8
- const { method: t, url: e, headers: s = [], postData: i } = this.request, n = {};
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 s = {}, i = /:{[^{}]+}/g, n = l.url.replace(i, (c) => {
165
- const u = ":62437";
166
- return s[u] = c, u;
167
- }), a = /{[^{}]+}/g, p = n.replace(a, (c) => {
168
- const u = c.slice(1, c.length - 1), d = r[u];
169
- if (c === "{endpoint}")
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 (d && (typeof d != "string" || d.length > 0))
172
- return `${encodeURIComponent(d.toString())}`;
173
- const h = C();
174
- return s[h] = c, h;
175
- }), m = new q({
176
- ...l,
177
- url: p,
178
- postData: l.postData || { mimeType: "application/json" }
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 t.map((c) => {
181
- var g;
182
- const { filename: u, snippet: d, language: h } = c, { target: f, client: y } = d, $ = m.convert(f, y), S = P(s, ($ == null ? void 0 : $.toString()) || "");
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: e ? u : ((g = o.operation) == null ? void 0 : g.title) || u,
185
- code: S,
186
- language: h
31
+ filename: c ? e : ((u = s.operation) == null ? void 0 : u.title) || e,
32
+ code: T,
33
+ language: o
187
34
  };
188
35
  });
189
- }, P = (l, r) => Object.entries(l).reduce((o, [t, e]) => o.replace(t, e), r);
36
+ }, j = (r, p) => Object.entries(r).reduce((s, [i, c]) => s.replace(i, c), p);
190
37
  export {
191
- T as generateSnippet
38
+ N as generateSnippet
192
39
  };
@@ -1,5 +1,5 @@
1
- import { jsxs as w, jsx as o } from "react/jsx-runtime";
2
- import { ClipboardCheckmarkRegular as j, Copy20Regular as E } from "@fluentui/react-icons";
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 P, { useState as _, useEffect as z } from "react";
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 F } from "../../utils/get-node-text.js";
15
- import { getCodeBlockScrollbarClassname as D } from "../../utils/getScrollbarClassname.js";
16
- const v = ["image/png", "text/plain"];
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] = _(!1), r = async (n) => {
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 (v.includes(i)) {
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__ */ w("div", { className: "mint:relative", children: [
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(j, { className: "mint:w-5 mint:h-5 mint:text-[#737373] mint:dark:text-[#a3a3a3]" }) : /* @__PURE__ */ o(E, { className: "mint:w-5 mint:h-5" })
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 G({
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 tt({
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 && v.includes(t.contentType) ? n(t.blob, t.contentType) : t.type === "other" && t.content ? c(t.content) : console.error("Unsupported content type for clipboard");
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 et({
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 [m, u] = _(""), { isCopied: T, copy: B, copyBlob: N } = y(), s = c || (e == null ? void 0 : e.replace(/^language-/, "")) || "text", d = F(t), I = !!r, h = P.useMemo(() => {
89
- var x, k;
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 R = Array.isArray(l.props.children) ? l.props.children : [l.props.children];
96
- for (const b of R)
97
- if (typeof b == "object" && b != null && "props" in b && ((k = b.props) != null && k.className))
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
- z(() => {
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
- u(x);
107
+ k(x);
107
108
  } catch (f) {
108
- console.error("Failed to highlight code:", f), u(d);
109
+ console.error("Failed to highlight code:", f), k(d);
109
110
  }
110
111
  }, [d, s, h]);
111
- const S = () => {
112
- n && i ? N(n, i) : B(d);
113
- }, A = D("system", a);
114
- return /* @__PURE__ */ w(
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
- I ? "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
+ 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: S, isCopied: T, showTooltip: !0 }) }),
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
- A,
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
- ) : m ? /* @__PURE__ */ o(
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: m }
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
- et as CodeBlock,
177
- tt as CopyDataToClipboardButton,
177
+ ot as CodeBlock,
178
+ et as CopyDataToClipboardButton,
178
179
  C as CopyIconButton,
179
- G as CopyToClipboardButton,
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 i } from "./code-block.js";
3
- import { CodeGroup as u } from "./code-group.js";
4
- import { CodeSnippet as d } from "./code-snippet.js";
5
- const h = ({
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
- ...m
10
- }) => /* @__PURE__ */ a(u, { isSmallText: !0, ...m, dropdown: r, noMargins: !0, className: l, children: o.map(({ code: g, ...e }, n) => /* @__PURE__ */ a(
11
- i,
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
- children: /* @__PURE__ */ a(d, { language: e.language, children: g })
16
+ showCopyButton: m,
17
+ children: /* @__PURE__ */ a(f, { language: e.language, children: n })
16
18
  },
17
- `${e.filename}-${e.language}-${n}`
19
+ `${e.filename}-${e.language}-${i}`
18
20
  )) });
19
21
  export {
20
- h as CodeSnippets
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
+ };