@lukoweb/apitogo 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/cli.js +168 -57
- package/dist/declarations/lib/ui/Command.d.ts +1 -1
- package/dist/declarations/lib/util/MdxComponents.d.ts +1 -1
- package/package.json +2 -1
- package/src/app/main.tsx +150 -150
- package/src/config/loader.ts +245 -245
- package/src/index.ts +33 -33
- package/src/lib/authentication/components/CallbackHandler.tsx +45 -45
- package/src/lib/authentication/components/SignIn.tsx +46 -46
- package/src/lib/authentication/components/SignUp.tsx +48 -48
- package/src/lib/authentication/providers/clerk.tsx +224 -224
- package/src/lib/authentication/ui/AuthCard.tsx +7 -7
- package/src/lib/authentication/ui/EmailLinkCallbackUi.tsx +129 -125
- package/src/lib/authentication/ui/EmailLinkSentUi.tsx +105 -101
- package/src/lib/authentication/ui/EmailLinkSignInUi.tsx +100 -96
- package/src/lib/authentication/ui/EmailVerificationUi.tsx +128 -124
- package/src/lib/authentication/ui/ZudokuAuthUi.tsx +620 -616
- package/src/lib/components/AiAssistantMenuItems.tsx +102 -102
- package/src/lib/components/Autocomplete.tsx +123 -123
- package/src/lib/components/DeveloperHint.tsx +39 -35
- package/src/lib/components/Header.tsx +260 -260
- package/src/lib/components/Layout.tsx +53 -53
- package/src/lib/components/Main.tsx +51 -51
- package/src/lib/components/Mermaid.tsx +74 -70
- package/src/lib/components/MobileTopNavigation.tsx +276 -276
- package/src/lib/components/MultiSelect.tsx +86 -82
- package/src/lib/components/TopNavigation.tsx +103 -103
- package/src/lib/components/index.ts +26 -26
- package/src/lib/components/navigation/NavigationCategory.tsx +157 -157
- package/src/lib/components/navigation/NavigationFilterInput.tsx +35 -35
- package/src/lib/components/navigation/NavigationItem.tsx +181 -177
- package/src/lib/core/RouteGuard.tsx +193 -193
- package/src/lib/errors/ErrorMessage.tsx +50 -46
- package/src/lib/plugins/api-catalog/Catalog.tsx +80 -80
- package/src/lib/plugins/api-keys/CreateApiKey.tsx +128 -124
- package/src/lib/plugins/api-keys/CreateApiKeyDialog.tsx +49 -49
- package/src/lib/plugins/api-keys/SettingsApiKeys.tsx +72 -72
- package/src/lib/plugins/api-keys/settings/ApiKeyItem.tsx +342 -342
- package/src/lib/plugins/api-keys/settings/RevealApiKey.tsx +127 -127
- package/src/lib/plugins/markdown/MdxPage.tsx +285 -285
- package/src/lib/plugins/openapi/ApiHeader.tsx +96 -96
- package/src/lib/plugins/openapi/CollapsibleCode.tsx +88 -88
- package/src/lib/plugins/openapi/DownloadSchemaButton.tsx +94 -94
- package/src/lib/plugins/openapi/GeneratedExampleSidecarBox.tsx +52 -52
- package/src/lib/plugins/openapi/OperationListItem.tsx +183 -183
- package/src/lib/plugins/openapi/RequestBodySidecarBox.tsx +63 -63
- package/src/lib/plugins/openapi/ResponsesSidecarBox.tsx +120 -117
- package/src/lib/plugins/openapi/SchemaInfo.tsx +344 -344
- package/src/lib/plugins/openapi/SchemaList.tsx +113 -113
- package/src/lib/plugins/openapi/Sidecar.tsx +312 -309
- package/src/lib/plugins/openapi/SidecarExamples.tsx +177 -174
- package/src/lib/plugins/openapi/components/EnumValues.tsx +58 -58
- package/src/lib/plugins/openapi/components/ResponseContent.tsx +117 -114
- package/src/lib/plugins/openapi/playground/BodyPanel.tsx +274 -271
- package/src/lib/plugins/openapi/playground/CollapsibleHeader.tsx +51 -51
- package/src/lib/plugins/openapi/playground/ExamplesDropdown.tsx +60 -60
- package/src/lib/plugins/openapi/playground/Headers.tsx +188 -181
- package/src/lib/plugins/openapi/playground/IdentityDialog.tsx +75 -75
- package/src/lib/plugins/openapi/playground/IdentitySelector.tsx +38 -38
- package/src/lib/plugins/openapi/playground/ParamsGrid.tsx +45 -45
- package/src/lib/plugins/openapi/playground/Playground.tsx +602 -599
- package/src/lib/plugins/openapi/playground/PlaygroundDialog.tsx +56 -56
- package/src/lib/plugins/openapi/playground/QueryParams.tsx +151 -148
- package/src/lib/plugins/openapi/playground/RequestLoginDialog.tsx +70 -70
- package/src/lib/plugins/openapi/playground/request-panel/MultipartField.tsx +91 -91
- package/src/lib/plugins/openapi/playground/result-panel/AudioPlayer.tsx +50 -50
- package/src/lib/plugins/openapi/playground/result-panel/ResponseTab.tsx +355 -355
- package/src/lib/plugins/openapi/playground/result-panel/ResultPanel.tsx +106 -102
- package/src/lib/plugins/openapi/schema/SchemaPropertyItem.tsx +189 -184
- package/src/lib/plugins/openapi/schema/SchemaView.tsx +299 -299
- package/src/lib/plugins/search-pagefind/IndexingDialog.tsx +162 -162
- package/src/lib/plugins/search-pagefind/PagefindSearch.tsx +202 -202
- package/src/lib/plugins/search-pagefind/ResultList.tsx +122 -118
- package/src/lib/ui/ActionButton.tsx +21 -21
- package/src/lib/ui/Command.tsx +191 -191
- package/src/lib/util/MdxComponents.tsx +150 -150
- package/src/vite/config.ts +234 -231
- package/src/vite/dev-server.ts +291 -291
- package/src/vite/plugin-api-keys.ts +50 -50
- package/src/vite/plugin-api.ts +320 -318
- package/src/vite/plugin-auth.ts +38 -38
- package/src/vite/plugin-component.ts +45 -39
- package/src/vite/plugin-config.ts +75 -75
- package/src/vite/plugin-custom-pages.ts +36 -36
- package/src/vite/plugin-docs.ts +202 -202
- package/src/vite/plugin-markdown-export.ts +214 -214
- package/src/vite/plugin-mdx.ts +149 -149
- package/src/vite/plugin-navigation.ts +106 -106
- package/src/vite/plugin-search.ts +47 -47
- package/src/vite/plugin.ts +42 -42
- package/src/vite/prerender/prerender.ts +233 -233
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
AiAssistantCustom,
|
|
5
|
-
AiAssistantsConfig,
|
|
6
|
-
} from "../../config/validators/ZudokuConfig.js";
|
|
7
|
-
import { ChatGPTLogo } from "../plugins/markdown/assets/ChatGPTLogo.js";
|
|
8
|
-
import { ClaudeLogo } from "../plugins/markdown/assets/ClaudeLogo.js";
|
|
9
|
-
|
|
10
|
-
type AiAssistantContext = {
|
|
11
|
-
pageUrl: string;
|
|
12
|
-
type: "docs" | "openapi";
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
type ResolvedAssistant = {
|
|
16
|
-
label: string;
|
|
17
|
-
icon?: ReactNode;
|
|
18
|
-
getUrl: (context: AiAssistantContext) => string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const PRESETS: Record<string, ResolvedAssistant> = {
|
|
22
|
-
claude: {
|
|
23
|
-
label: "Use in Claude",
|
|
24
|
-
icon: <ClaudeLogo className="size-4" />,
|
|
25
|
-
getUrl: ({ pageUrl, type }) => {
|
|
26
|
-
const contextText =
|
|
27
|
-
type === "openapi" ? "this API" : "this documentation page";
|
|
28
|
-
const prompt = encodeURIComponent(
|
|
29
|
-
`Help me understand ${contextText}: ${pageUrl}`,
|
|
30
|
-
);
|
|
31
|
-
return `https://claude.ai/new?q=${prompt}`;
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
chatgpt: {
|
|
35
|
-
label: "Use in ChatGPT",
|
|
36
|
-
icon: <ChatGPTLogo className="size-4" />,
|
|
37
|
-
getUrl: ({ pageUrl, type }) => {
|
|
38
|
-
const contextText =
|
|
39
|
-
type === "openapi" ? "this API" : "this documentation page";
|
|
40
|
-
const prompt = encodeURIComponent(
|
|
41
|
-
`Help me understand ${contextText}: ${pageUrl}`,
|
|
42
|
-
);
|
|
43
|
-
return `https://chatgpt.com/?q=${prompt}`;
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const resolveAssistant = (
|
|
49
|
-
entry: string | AiAssistantCustom,
|
|
50
|
-
): ResolvedAssistant | undefined => {
|
|
51
|
-
if (typeof entry === "string") {
|
|
52
|
-
return PRESETS[entry];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
label: entry.label,
|
|
57
|
-
icon: entry.icon,
|
|
58
|
-
getUrl: (context) => {
|
|
59
|
-
if (typeof entry.url === "function") {
|
|
60
|
-
return entry.url(context);
|
|
61
|
-
}
|
|
62
|
-
return entry.url.replaceAll("{pageUrl}", context.pageUrl);
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const DEFAULT_ASSISTANTS: AiAssistantsConfig = ["claude", "chatgpt"];
|
|
68
|
-
|
|
69
|
-
export const AiAssistantMenuItems = ({
|
|
70
|
-
aiAssistants,
|
|
71
|
-
getPageUrl,
|
|
72
|
-
type,
|
|
73
|
-
}: {
|
|
74
|
-
aiAssistants: AiAssistantsConfig;
|
|
75
|
-
getPageUrl: () => string;
|
|
76
|
-
type: "docs" | "openapi";
|
|
77
|
-
}) => {
|
|
78
|
-
const config = aiAssistants ?? DEFAULT_ASSISTANTS;
|
|
79
|
-
|
|
80
|
-
if (config === false) {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return config.map((entry, index) => {
|
|
85
|
-
const assistant = resolveAssistant(entry);
|
|
86
|
-
if (!assistant) return null;
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<DropdownMenuItem
|
|
90
|
-
key={typeof entry === "string" ? entry : index}
|
|
91
|
-
className="gap-2"
|
|
92
|
-
onClick={() => {
|
|
93
|
-
const url = assistant.getUrl({ pageUrl: getPageUrl(), type });
|
|
94
|
-
window.open(url, "_blank", "noopener,noreferrer");
|
|
95
|
-
}}
|
|
96
|
-
>
|
|
97
|
-
{assistant.icon}
|
|
98
|
-
{assistant.label}
|
|
99
|
-
</DropdownMenuItem>
|
|
100
|
-
);
|
|
101
|
-
});
|
|
102
|
-
};
|
|
1
|
+
import { DropdownMenuItem } from "@lukoweb/apitogo/ui/DropdownMenu.js";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type {
|
|
4
|
+
AiAssistantCustom,
|
|
5
|
+
AiAssistantsConfig,
|
|
6
|
+
} from "../../config/validators/ZudokuConfig.js";
|
|
7
|
+
import { ChatGPTLogo } from "../plugins/markdown/assets/ChatGPTLogo.js";
|
|
8
|
+
import { ClaudeLogo } from "../plugins/markdown/assets/ClaudeLogo.js";
|
|
9
|
+
|
|
10
|
+
type AiAssistantContext = {
|
|
11
|
+
pageUrl: string;
|
|
12
|
+
type: "docs" | "openapi";
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type ResolvedAssistant = {
|
|
16
|
+
label: string;
|
|
17
|
+
icon?: ReactNode;
|
|
18
|
+
getUrl: (context: AiAssistantContext) => string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const PRESETS: Record<string, ResolvedAssistant> = {
|
|
22
|
+
claude: {
|
|
23
|
+
label: "Use in Claude",
|
|
24
|
+
icon: <ClaudeLogo className="size-4" />,
|
|
25
|
+
getUrl: ({ pageUrl, type }) => {
|
|
26
|
+
const contextText =
|
|
27
|
+
type === "openapi" ? "this API" : "this documentation page";
|
|
28
|
+
const prompt = encodeURIComponent(
|
|
29
|
+
`Help me understand ${contextText}: ${pageUrl}`,
|
|
30
|
+
);
|
|
31
|
+
return `https://claude.ai/new?q=${prompt}`;
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
chatgpt: {
|
|
35
|
+
label: "Use in ChatGPT",
|
|
36
|
+
icon: <ChatGPTLogo className="size-4" />,
|
|
37
|
+
getUrl: ({ pageUrl, type }) => {
|
|
38
|
+
const contextText =
|
|
39
|
+
type === "openapi" ? "this API" : "this documentation page";
|
|
40
|
+
const prompt = encodeURIComponent(
|
|
41
|
+
`Help me understand ${contextText}: ${pageUrl}`,
|
|
42
|
+
);
|
|
43
|
+
return `https://chatgpt.com/?q=${prompt}`;
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const resolveAssistant = (
|
|
49
|
+
entry: string | AiAssistantCustom,
|
|
50
|
+
): ResolvedAssistant | undefined => {
|
|
51
|
+
if (typeof entry === "string") {
|
|
52
|
+
return PRESETS[entry];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
label: entry.label,
|
|
57
|
+
icon: entry.icon,
|
|
58
|
+
getUrl: (context) => {
|
|
59
|
+
if (typeof entry.url === "function") {
|
|
60
|
+
return entry.url(context);
|
|
61
|
+
}
|
|
62
|
+
return entry.url.replaceAll("{pageUrl}", context.pageUrl);
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const DEFAULT_ASSISTANTS: AiAssistantsConfig = ["claude", "chatgpt"];
|
|
68
|
+
|
|
69
|
+
export const AiAssistantMenuItems = ({
|
|
70
|
+
aiAssistants,
|
|
71
|
+
getPageUrl,
|
|
72
|
+
type,
|
|
73
|
+
}: {
|
|
74
|
+
aiAssistants: AiAssistantsConfig;
|
|
75
|
+
getPageUrl: () => string;
|
|
76
|
+
type: "docs" | "openapi";
|
|
77
|
+
}) => {
|
|
78
|
+
const config = aiAssistants ?? DEFAULT_ASSISTANTS;
|
|
79
|
+
|
|
80
|
+
if (config === false) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return config.map((entry, index) => {
|
|
85
|
+
const assistant = resolveAssistant(entry);
|
|
86
|
+
if (!assistant) return null;
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<DropdownMenuItem
|
|
90
|
+
key={typeof entry === "string" ? entry : index}
|
|
91
|
+
className="gap-2"
|
|
92
|
+
onClick={() => {
|
|
93
|
+
const url = assistant.getUrl({ pageUrl: getPageUrl(), type });
|
|
94
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
95
|
+
}}
|
|
96
|
+
>
|
|
97
|
+
{assistant.icon}
|
|
98
|
+
{assistant.label}
|
|
99
|
+
</DropdownMenuItem>
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
};
|
|
@@ -1,123 +1,123 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "
|
|
10
|
-
import {
|
|
11
|
-
import { cn } from "../util/cn.js";
|
|
12
|
-
|
|
13
|
-
type AutocompleteProps = {
|
|
14
|
-
value?: string | number | readonly string[] | undefined;
|
|
15
|
-
options: readonly string[];
|
|
16
|
-
onChange: (e: string) => void;
|
|
17
|
-
onSelect?: (e: string) => void;
|
|
18
|
-
className?: string;
|
|
19
|
-
placeholder?: string;
|
|
20
|
-
onEnterPress?: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
21
|
-
onKeyDown?: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
22
|
-
ref?: Ref<HTMLInputElement>;
|
|
23
|
-
shouldFilter?: boolean;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const AutocompletePopover = ({
|
|
27
|
-
value,
|
|
28
|
-
options,
|
|
29
|
-
onChange,
|
|
30
|
-
className,
|
|
31
|
-
placeholder = "Value",
|
|
32
|
-
onEnterPress,
|
|
33
|
-
onKeyDown,
|
|
34
|
-
ref,
|
|
35
|
-
onSelect,
|
|
36
|
-
}: AutocompleteProps) => {
|
|
37
|
-
const [open, setOpen] = useState(false);
|
|
38
|
-
const [dontClose, setDontClose] = useState(false);
|
|
39
|
-
const count = useCommandState((state) => state.filtered.count);
|
|
40
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
<Popover open={open}>
|
|
44
|
-
<PopoverAnchor>
|
|
45
|
-
<CommandInlineInput
|
|
46
|
-
autoComplete="off"
|
|
47
|
-
ref={(el) => {
|
|
48
|
-
inputRef.current = el;
|
|
49
|
-
if (typeof ref === "function") {
|
|
50
|
-
ref(el);
|
|
51
|
-
} else if (ref) {
|
|
52
|
-
ref.current = el;
|
|
53
|
-
}
|
|
54
|
-
}}
|
|
55
|
-
value={value ? String(value) : undefined}
|
|
56
|
-
placeholder={placeholder}
|
|
57
|
-
className={cn("h-9 bg-transparent", className)}
|
|
58
|
-
onFocus={() => setOpen(true)}
|
|
59
|
-
onBlur={() => {
|
|
60
|
-
if (dontClose) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
setOpen(false);
|
|
64
|
-
}}
|
|
65
|
-
onKeyDown={(e) => {
|
|
66
|
-
onKeyDown?.(e);
|
|
67
|
-
|
|
68
|
-
if (e.defaultPrevented) return;
|
|
69
|
-
|
|
70
|
-
if (e.key === "Enter") {
|
|
71
|
-
setOpen(false);
|
|
72
|
-
inputRef.current?.blur();
|
|
73
|
-
onEnterPress?.(e);
|
|
74
|
-
}
|
|
75
|
-
}}
|
|
76
|
-
onValueChange={(e) => onChange(e)}
|
|
77
|
-
/>
|
|
78
|
-
</PopoverAnchor>
|
|
79
|
-
<PopoverContent
|
|
80
|
-
onMouseEnter={() => setDontClose(true)}
|
|
81
|
-
onMouseLeave={() => setDontClose(false)}
|
|
82
|
-
onOpenAutoFocus={(e) => e.preventDefault()}
|
|
83
|
-
className={cn("p-0 w-(--radix-popover-trigger-width)", {
|
|
84
|
-
"border-0": count === 0,
|
|
85
|
-
})}
|
|
86
|
-
align="start"
|
|
87
|
-
side="bottom"
|
|
88
|
-
onWheel={(e) => {
|
|
89
|
-
// See: https://github.com/radix-ui/primitives/issues/1159
|
|
90
|
-
e.stopPropagation();
|
|
91
|
-
}}
|
|
92
|
-
onTouchMove={(e) => {
|
|
93
|
-
e.stopPropagation();
|
|
94
|
-
}}
|
|
95
|
-
>
|
|
96
|
-
<CommandList className="max-h-[140px]">
|
|
97
|
-
{options.map((enumValue) => (
|
|
98
|
-
<CommandItem
|
|
99
|
-
key={enumValue}
|
|
100
|
-
value={enumValue}
|
|
101
|
-
onSelect={(selected) => {
|
|
102
|
-
onSelect?.(selected);
|
|
103
|
-
onChange(selected);
|
|
104
|
-
setOpen(false);
|
|
105
|
-
}}
|
|
106
|
-
className="cursor-pointer"
|
|
107
|
-
>
|
|
108
|
-
{enumValue}
|
|
109
|
-
</CommandItem>
|
|
110
|
-
))}
|
|
111
|
-
</CommandList>
|
|
112
|
-
</PopoverContent>
|
|
113
|
-
</Popover>
|
|
114
|
-
);
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export const Autocomplete = ({ shouldFilter, ...props }: AutocompleteProps) => {
|
|
118
|
-
return (
|
|
119
|
-
<Command className="bg-transparent" shouldFilter={shouldFilter}>
|
|
120
|
-
<AutocompletePopover {...props} />
|
|
121
|
-
</Command>
|
|
122
|
-
);
|
|
123
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
Command,
|
|
3
|
+
CommandInlineInput,
|
|
4
|
+
CommandItem,
|
|
5
|
+
CommandList,
|
|
6
|
+
} from "@lukoweb/apitogo/ui/Command.js";
|
|
7
|
+
import { Popover, PopoverContent } from "@lukoweb/apitogo/ui/Popover.js";
|
|
8
|
+
import { PopoverAnchor } from "@radix-ui/react-popover";
|
|
9
|
+
import { useCommandState } from "cmdk";
|
|
10
|
+
import { type KeyboardEvent, type Ref, useRef, useState } from "react";
|
|
11
|
+
import { cn } from "../util/cn.js";
|
|
12
|
+
|
|
13
|
+
type AutocompleteProps = {
|
|
14
|
+
value?: string | number | readonly string[] | undefined;
|
|
15
|
+
options: readonly string[];
|
|
16
|
+
onChange: (e: string) => void;
|
|
17
|
+
onSelect?: (e: string) => void;
|
|
18
|
+
className?: string;
|
|
19
|
+
placeholder?: string;
|
|
20
|
+
onEnterPress?: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
21
|
+
onKeyDown?: (e: KeyboardEvent<HTMLInputElement>) => void;
|
|
22
|
+
ref?: Ref<HTMLInputElement>;
|
|
23
|
+
shouldFilter?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const AutocompletePopover = ({
|
|
27
|
+
value,
|
|
28
|
+
options,
|
|
29
|
+
onChange,
|
|
30
|
+
className,
|
|
31
|
+
placeholder = "Value",
|
|
32
|
+
onEnterPress,
|
|
33
|
+
onKeyDown,
|
|
34
|
+
ref,
|
|
35
|
+
onSelect,
|
|
36
|
+
}: AutocompleteProps) => {
|
|
37
|
+
const [open, setOpen] = useState(false);
|
|
38
|
+
const [dontClose, setDontClose] = useState(false);
|
|
39
|
+
const count = useCommandState((state) => state.filtered.count);
|
|
40
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<Popover open={open}>
|
|
44
|
+
<PopoverAnchor>
|
|
45
|
+
<CommandInlineInput
|
|
46
|
+
autoComplete="off"
|
|
47
|
+
ref={(el) => {
|
|
48
|
+
inputRef.current = el;
|
|
49
|
+
if (typeof ref === "function") {
|
|
50
|
+
ref(el);
|
|
51
|
+
} else if (ref) {
|
|
52
|
+
ref.current = el;
|
|
53
|
+
}
|
|
54
|
+
}}
|
|
55
|
+
value={value ? String(value) : undefined}
|
|
56
|
+
placeholder={placeholder}
|
|
57
|
+
className={cn("h-9 bg-transparent", className)}
|
|
58
|
+
onFocus={() => setOpen(true)}
|
|
59
|
+
onBlur={() => {
|
|
60
|
+
if (dontClose) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
setOpen(false);
|
|
64
|
+
}}
|
|
65
|
+
onKeyDown={(e) => {
|
|
66
|
+
onKeyDown?.(e);
|
|
67
|
+
|
|
68
|
+
if (e.defaultPrevented) return;
|
|
69
|
+
|
|
70
|
+
if (e.key === "Enter") {
|
|
71
|
+
setOpen(false);
|
|
72
|
+
inputRef.current?.blur();
|
|
73
|
+
onEnterPress?.(e);
|
|
74
|
+
}
|
|
75
|
+
}}
|
|
76
|
+
onValueChange={(e) => onChange(e)}
|
|
77
|
+
/>
|
|
78
|
+
</PopoverAnchor>
|
|
79
|
+
<PopoverContent
|
|
80
|
+
onMouseEnter={() => setDontClose(true)}
|
|
81
|
+
onMouseLeave={() => setDontClose(false)}
|
|
82
|
+
onOpenAutoFocus={(e) => e.preventDefault()}
|
|
83
|
+
className={cn("p-0 w-(--radix-popover-trigger-width)", {
|
|
84
|
+
"border-0": count === 0,
|
|
85
|
+
})}
|
|
86
|
+
align="start"
|
|
87
|
+
side="bottom"
|
|
88
|
+
onWheel={(e) => {
|
|
89
|
+
// See: https://github.com/radix-ui/primitives/issues/1159
|
|
90
|
+
e.stopPropagation();
|
|
91
|
+
}}
|
|
92
|
+
onTouchMove={(e) => {
|
|
93
|
+
e.stopPropagation();
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
<CommandList className="max-h-[140px]">
|
|
97
|
+
{options.map((enumValue) => (
|
|
98
|
+
<CommandItem
|
|
99
|
+
key={enumValue}
|
|
100
|
+
value={enumValue}
|
|
101
|
+
onSelect={(selected) => {
|
|
102
|
+
onSelect?.(selected);
|
|
103
|
+
onChange(selected);
|
|
104
|
+
setOpen(false);
|
|
105
|
+
}}
|
|
106
|
+
className="cursor-pointer"
|
|
107
|
+
>
|
|
108
|
+
{enumValue}
|
|
109
|
+
</CommandItem>
|
|
110
|
+
))}
|
|
111
|
+
</CommandList>
|
|
112
|
+
</PopoverContent>
|
|
113
|
+
</Popover>
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const Autocomplete = ({ shouldFilter, ...props }: AutocompleteProps) => {
|
|
118
|
+
return (
|
|
119
|
+
<Command className="bg-transparent" shouldFilter={shouldFilter}>
|
|
120
|
+
<AutocompletePopover {...props} />
|
|
121
|
+
</Command>
|
|
122
|
+
);
|
|
123
|
+
};
|
|
@@ -1,35 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
import {
|
|
2
|
+
Alert,
|
|
3
|
+
AlertDescription,
|
|
4
|
+
AlertTitle,
|
|
5
|
+
} from "@lukoweb/apitogo/ui/Alert.js";
|
|
6
|
+
import { InfoIcon } from "lucide-react";
|
|
7
|
+
import { type ReactNode, Suspense, lazy } from "react";
|
|
8
|
+
|
|
9
|
+
// Lazy: Markdown imports shiki.ts — keeping it out of the entry chunk.
|
|
10
|
+
const Markdown = lazy(() =>
|
|
11
|
+
import("./Markdown.js").then((m) => ({ default: m.Markdown })),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const DeveloperHint = ({
|
|
15
|
+
children,
|
|
16
|
+
className,
|
|
17
|
+
}: {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
className?: string;
|
|
20
|
+
}) => {
|
|
21
|
+
if (process.env.NODE_ENV !== "development") return null;
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Alert variant="info" className={className}>
|
|
25
|
+
<InfoIcon />
|
|
26
|
+
<AlertTitle>Developer hint</AlertTitle>
|
|
27
|
+
<AlertDescription>
|
|
28
|
+
{typeof children === "string" ? (
|
|
29
|
+
<Suspense>
|
|
30
|
+
<Markdown content={children} />
|
|
31
|
+
</Suspense>
|
|
32
|
+
) : (
|
|
33
|
+
<div>{children}</div>
|
|
34
|
+
)}
|
|
35
|
+
<small className="italic">Only shown in development mode.</small>
|
|
36
|
+
</AlertDescription>
|
|
37
|
+
</Alert>
|
|
38
|
+
);
|
|
39
|
+
};
|