zudoku 0.3.0-dev.64 → 0.3.0-dev.65

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 (36) hide show
  1. package/dist/lib/plugins/api-keys/CreateApiKey.js +1 -1
  2. package/dist/lib/plugins/api-keys/CreateApiKey.js.map +1 -1
  3. package/dist/lib/plugins/openapi/ColorizedParam.d.ts +2 -1
  4. package/dist/lib/plugins/openapi/ColorizedParam.js +13 -8
  5. package/dist/lib/plugins/openapi/ColorizedParam.js.map +1 -1
  6. package/dist/lib/plugins/openapi/playground/PathParams.d.ts +1 -1
  7. package/dist/lib/plugins/openapi/playground/PathParams.js +9 -12
  8. package/dist/lib/plugins/openapi/playground/PathParams.js.map +1 -1
  9. package/dist/lib/plugins/openapi/playground/Playground.js +9 -3
  10. package/dist/lib/plugins/openapi/playground/Playground.js.map +1 -1
  11. package/dist/lib/plugins/openapi/playground/QueryParams.d.ts +1 -1
  12. package/dist/lib/plugins/openapi/playground/QueryParams.js +12 -9
  13. package/dist/lib/plugins/openapi/playground/QueryParams.js.map +1 -1
  14. package/dist/lib/ui/Input.js.map +1 -0
  15. package/lib/{Select-CEnkyfyn.js → Input-a4Q9eY9j.js} +263 -247
  16. package/lib/Input-a4Q9eY9j.js.map +1 -0
  17. package/lib/{OperationList-DDTtK3I7.js → OperationList-DuRwWfdq.js} +1894 -1846
  18. package/lib/OperationList-DuRwWfdq.js.map +1 -0
  19. package/lib/{index-BE2a6gGC.js → index-BDkyi7gS.js} +2 -2
  20. package/lib/{index-BE2a6gGC.js.map → index-BDkyi7gS.js.map} +1 -1
  21. package/lib/zudoku.plugin-api-keys.js +79 -95
  22. package/lib/zudoku.plugin-api-keys.js.map +1 -1
  23. package/lib/zudoku.plugin-openapi.js +1 -1
  24. package/package.json +1 -1
  25. package/src/app/main.css +2 -2
  26. package/src/lib/plugins/api-keys/CreateApiKey.tsx +1 -1
  27. package/src/lib/plugins/openapi/ColorizedParam.tsx +22 -15
  28. package/src/lib/plugins/openapi/playground/PathParams.tsx +79 -47
  29. package/src/lib/plugins/openapi/playground/Playground.tsx +37 -34
  30. package/src/lib/plugins/openapi/playground/QueryParams.tsx +92 -68
  31. package/dist/lib/components/Input.js.map +0 -1
  32. package/lib/OperationList-DDTtK3I7.js.map +0 -1
  33. package/lib/Select-CEnkyfyn.js.map +0 -1
  34. /package/dist/lib/{components → ui}/Input.d.ts +0 -0
  35. /package/dist/lib/{components → ui}/Input.js +0 -0
  36. /package/src/lib/{components → ui}/Input.tsx +0 -0
@@ -1,31 +1,17 @@
1
- import { forwardRef, InputHTMLAttributes } from "react";
2
- import { Control, useFieldArray, UseFormRegister } from "react-hook-form";
1
+ import { EraserIcon } from "lucide-react";
2
+ import {
3
+ Control,
4
+ Controller,
5
+ useFieldArray,
6
+ useFormContext,
7
+ UseFormRegister,
8
+ } from "react-hook-form";
9
+ import { Button } from "../../../ui/Button.js";
10
+ import { Input } from "../../../ui/Input.js";
3
11
  import { cn } from "../../../util/cn.js";
4
- import { DATA_ATTR, usePastellizedColor } from "../ColorizedParam.js";
5
- import { InlineInput } from "./InlineInput.js";
12
+ import { ColorizedParam } from "../ColorizedParam.js";
6
13
  import type { PlaygroundForm } from "./Playground.js";
7
14
 
8
- type ParameterValueProps = {
9
- part: string;
10
- } & InputHTMLAttributes<HTMLInputElement>;
11
-
12
- const ParameterValue = forwardRef<HTMLInputElement, ParameterValueProps>(
13
- function ParameterValue({ part, className, ...props }, ref) {
14
- const color = usePastellizedColor(part);
15
- return (
16
- <InlineInput
17
- {...props}
18
- ref={ref}
19
- className={cn(className, "opacity-80 data-[active=true]:opacity-100")}
20
- style={{
21
- // color: `hsl(${color})`,
22
- outlineColor: `hsl(${color})`,
23
- }}
24
- />
25
- );
26
- },
27
- );
28
-
29
15
  export const PathParams = ({
30
16
  control,
31
17
  register,
@@ -33,31 +19,77 @@ export const PathParams = ({
33
19
  register: UseFormRegister<PlaygroundForm>;
34
20
  control: Control<PlaygroundForm>;
35
21
  }) => {
22
+ const form = useFormContext<PlaygroundForm>();
36
23
  const { fields } = useFieldArray<PlaygroundForm>({
37
24
  control,
38
25
  name: "pathParams",
39
26
  });
40
27
 
41
- return fields.map((part, i) => (
42
- <div
43
- key={part.id}
44
- className="grid-cols-subgrid col-span-full grid items-center gap-x-2 has-[:focus]:bg-muted hover:bg-muted rounded overflow-hidden group"
45
- >
46
- <InlineInput
47
- {...register(`pathParams.${i}.name`)}
48
- disabled
49
- placeholder="Name"
50
- className="peer"
51
- />
52
- <ParameterValue
53
- {...register(`pathParams.${i}.value`)}
54
- part={part.name}
55
- {...{ [DATA_ATTR]: part.name }}
56
- placeholder="Value"
57
- className="peer"
58
- />
59
-
60
- <div className="col-span-full border-b border-border"></div>
61
- </div>
62
- ));
28
+ return (
29
+ <table className="w-full table-auto [&_td]:border [&_td]:py-1 [&_td]:px-2">
30
+ <tbody>
31
+ {fields.map((part, i) => (
32
+ <tr key={part.id} className="hover:bg-accent/40">
33
+ <td>
34
+ <Controller
35
+ control={control}
36
+ name={`pathParams.${i}.value`}
37
+ render={({ field }) => (
38
+ <ColorizedParam
39
+ slug={part.name}
40
+ name={part.name}
41
+ backgroundOpacity="0"
42
+ borderOpacity={field.value ? "100%" : "0"}
43
+ className={cn(
44
+ "font-mono text-xs m-2",
45
+ !field.value && "opacity-60",
46
+ )}
47
+ />
48
+ )}
49
+ />
50
+ </td>
51
+ <td>
52
+ <div className="flex justify-between items-center">
53
+ <Controller
54
+ control={control}
55
+ name={`pathParams.${i}.value`}
56
+ render={({ field }) => (
57
+ <Input
58
+ {...field}
59
+ placeholder="Enter value"
60
+ className={cn(
61
+ "border-0 shadow-none ring-0 font-mono text-xs",
62
+ )}
63
+ />
64
+ )}
65
+ />
66
+ <Controller
67
+ control={control}
68
+ name={`pathParams.${i}.value`}
69
+ render={({ field }) => (
70
+ <Button
71
+ size="icon"
72
+ type="button"
73
+ variant="ghost"
74
+ aria-label="Clear value"
75
+ className={cn(
76
+ "ms-2",
77
+ field.value.length === 0
78
+ ? "opacity-0 pointer-events-none"
79
+ : "opacity-100",
80
+ )}
81
+ title="Clear value"
82
+ onClick={() => field.onChange("")}
83
+ >
84
+ <EraserIcon size={16} />
85
+ </Button>
86
+ )}
87
+ />
88
+ </div>
89
+ </td>
90
+ </tr>
91
+ ))}
92
+ </tbody>
93
+ </table>
94
+ );
63
95
  };
@@ -152,26 +152,31 @@ export const Playground = ({
152
152
  },
153
153
  });
154
154
 
155
- const path = url.split("/").map((part, i, arr) => (
156
- <Fragment key={part}>
157
- {part.startsWith("{") && part.endsWith("}") ? (
158
- <ColorizedParam
159
- name={part}
160
- backgroundOpacity="0"
161
- slug={part.slice(1, -1)}
162
- >
163
- {
164
- formState.pathParams.find((p) => p.name === part.slice(1, -1))
165
- ?.value
166
- }
167
- </ColorizedParam>
168
- ) : (
169
- part
170
- )}
171
- {i < arr.length - 1 && "/"}
172
- <wbr />
173
- </Fragment>
174
- ));
155
+ const path = url.split("/").map((part, i, arr) => {
156
+ const isPathParam = part.startsWith("{") && part.endsWith("}");
157
+ const value = formState.pathParams.find(
158
+ (p) => p.name === part.slice(1, -1),
159
+ )?.value;
160
+
161
+ const pathParamValue = value ? (
162
+ <ColorizedParam backgroundOpacity="0%" name={part} slug={part}>
163
+ {value}
164
+ </ColorizedParam>
165
+ ) : (
166
+ <span className="underline decoration-wavy decoration-red-500">
167
+ {part}
168
+ </span>
169
+ );
170
+
171
+ return (
172
+ // eslint-disable-next-line react/no-array-index-key
173
+ <Fragment key={part + i}>
174
+ {isPathParam ? pathParamValue : part}
175
+ {i < arr.length - 1 && "/"}
176
+ <wbr />
177
+ </Fragment>
178
+ );
179
+ });
175
180
 
176
181
  const lang = mimeTypeToLanguage(
177
182
  queryMutation.data?.headers.get("Content-Type") ?? "",
@@ -251,20 +256,18 @@ export const Playground = ({
251
256
  <Headers control={control} register={register} />
252
257
  </TabsContent>
253
258
  <TabsContent value="parameters">
254
- <div className="grid grid-cols-[min-content_1fr_1fr_auto]">
255
- {pathParams.length > 0 && (
256
- <div className="font-semibold my-3 col-span-3">
257
- Path Parameters
258
- </div>
259
- )}
260
- <PathParams control={control} register={register} />
261
- {queryParams.length > 0 && (
262
- <span className="font-semibold my-3 col-span-3">
263
- Query Parameters
264
- </span>
265
- )}
266
- <QueryParams control={control} />
267
- </div>
259
+ {pathParams.length > 0 && (
260
+ <div className="flex flex-col gap-4 my-4">
261
+ <span className="font-semibold">Path Parameters</span>
262
+ <PathParams control={control} register={register} />
263
+ </div>
264
+ )}
265
+ {queryParams.length > 0 && (
266
+ <div className="flex flex-col gap-4 my-4">
267
+ <span className="font-semibold">Query Parameters</span>
268
+ <QueryParams control={control} />
269
+ </div>
270
+ )}
268
271
  </TabsContent>
269
272
  <TabsContent value="body">
270
273
  <textarea
@@ -1,10 +1,12 @@
1
- import { XIcon } from "lucide-react";
1
+ import { EraserIcon } from "lucide-react";
2
2
  import {
3
3
  Control,
4
4
  Controller,
5
5
  useFieldArray,
6
6
  useFormContext,
7
7
  } from "react-hook-form";
8
+ import { Button } from "../../../ui/Button.js";
9
+ import { Input } from "../../../ui/Input.js";
8
10
  import { cn } from "../../../util/cn.js";
9
11
  import { InlineInput } from "./InlineInput.js";
10
12
  import type { PlaygroundForm } from "./Playground.js";
@@ -21,74 +23,96 @@ export const QueryParams = ({
21
23
  const form = useFormContext<PlaygroundForm>();
22
24
 
23
25
  const requiredFields = form
24
- .getValues(`queryParams`)
26
+ .getValues("queryParams")
25
27
  .map((param) => param.isRequired);
26
28
 
27
- return fields.map((field, i) => (
28
- <div
29
- key={field.id}
30
- className="px-2 grid-cols-subgrid col-span-full grid items-center gap-x-2 has-[:focus]:bg-muted hover:bg-accent rounded overflow-hidden group"
31
- >
32
- <Controller
33
- control={control}
34
- name={`queryParams.${i}.active`}
35
- render={({ field }) => (
36
- <input
37
- type="checkbox"
38
- id={`queryParams.${i}.active`}
39
- checked={field.value}
40
- onChange={field.onChange}
41
- />
42
- )}
43
- />
44
-
45
- <Controller
46
- control={control}
47
- render={({ field }) => {
48
- return (
49
- <InlineInput asChild>
50
- <label
51
- className="flex items-center"
52
- htmlFor={`queryParams.${i}.active`}
53
- title={requiredFields[i] ? "Required field" : undefined}
54
- >
55
- {field.value}
56
- {requiredFields[i] && <sup className="text-destructive">*</sup>}
57
- </label>
58
- </InlineInput>
59
- );
60
- }}
61
- name={`queryParams.${i}.name`}
62
- />
63
- <Controller
64
- control={control}
65
- render={({ field }) => {
66
- return (
67
- <InlineInput {...field} placeholder="Value" className="peer" />
68
- );
69
- }}
70
- name={`queryParams.${i}.value`}
71
- />
72
- <Controller
73
- control={control}
74
- render={({ field }) => {
75
- return (
76
- <button
77
- type="button"
78
- className={cn(
79
- "hover:bg-black/5 p-1 rounded mr-2 text-muted-foreground invisible group-hover:visible peer-focus:visible",
80
- field.value.length === 0 && "opacity-0 pointer-events-none",
81
- )}
82
- onClick={() => field.onChange("")}
83
- >
84
- <XIcon size={16} />
85
- </button>
86
- );
87
- }}
88
- name={`queryParams.${i}.value`}
89
- />
90
-
91
- <div className="-mx-2 col-span-full border-b border-border"></div>
29
+ return (
30
+ <div className="">
31
+ <table className="w-full [&_td]:border [&_td]:p-1.5 [&_td]:px-2">
32
+ <tbody>
33
+ {fields.map((field, i) => (
34
+ <tr key={field.id} className="hover:bg-accent/40">
35
+ <td className="text-center">
36
+ <Controller
37
+ control={control}
38
+ name={`queryParams.${i}.active`}
39
+ render={({ field }) => (
40
+ <input
41
+ type="checkbox"
42
+ id={`queryParams.${i}.active`}
43
+ checked={field.value}
44
+ onChange={field.onChange}
45
+ />
46
+ )}
47
+ />
48
+ </td>
49
+ <td>
50
+ <Controller
51
+ control={control}
52
+ render={({ field }) => (
53
+ <InlineInput asChild>
54
+ <label
55
+ className="flex items-center cursor-pointer"
56
+ htmlFor={`queryParams.${i}.active`}
57
+ title={requiredFields[i] ? "Required field" : undefined}
58
+ >
59
+ {field.value}
60
+ {requiredFields[i] && (
61
+ <sup className="text-destructive">*</sup>
62
+ )}
63
+ </label>
64
+ </InlineInput>
65
+ )}
66
+ name={`queryParams.${i}.name`}
67
+ />
68
+ </td>
69
+ <td>
70
+ <div className="flex justify-between items-center">
71
+ <Controller
72
+ control={control}
73
+ render={({ field }) => (
74
+ <Input
75
+ {...field}
76
+ onChange={(e) => {
77
+ field.onChange(e.target.value);
78
+ if (e.target.value.length > 0) {
79
+ form.setValue(`queryParams.${i}.active`, true);
80
+ }
81
+ }}
82
+ placeholder="Enter value"
83
+ className="w-full border-0 shadow-none text-xs font-mono"
84
+ />
85
+ )}
86
+ name={`queryParams.${i}.value`}
87
+ />
88
+ <Controller
89
+ control={control}
90
+ render={({ field }) => (
91
+ <Button
92
+ size="icon"
93
+ type="button"
94
+ variant="ghost"
95
+ aria-label="Clear value"
96
+ className={cn(
97
+ "ms-2",
98
+ field.value.length === 0
99
+ ? "opacity-0 pointer-events-none"
100
+ : "opacity-100",
101
+ )}
102
+ title="Clear value"
103
+ onClick={() => field.onChange("")}
104
+ >
105
+ <EraserIcon size={16} />
106
+ </Button>
107
+ )}
108
+ name={`queryParams.${i}.value`}
109
+ />
110
+ </div>
111
+ </td>
112
+ </tr>
113
+ ))}
114
+ </tbody>
115
+ </table>
92
116
  </div>
93
- ));
117
+ );
94
118
  };
@@ -1 +0,0 @@
1
- {"version":3,"file":"Input.js","sourceRoot":"","sources":["../../../src/lib/components/Input.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AAKnC,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAC5B,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG,EAAE,EAAE;IACrC,OAAO,CACL,gBACE,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,EAAE,CACX,uUAAuU,EACvU,SAAS,CACV,EACD,GAAG,EAAE,GAAG,KACJ,KAAK,GACT,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AACF,KAAK,CAAC,WAAW,GAAG,OAAO,CAAC;AAE5B,OAAO,EAAE,KAAK,EAAE,CAAC"}