UNPKG

@scalar/api-client

Version:

the open source API testing client

113 lines (112 loc) 2.54 kB
import { useModal as g } from "@scalar/components"; import { ref as s, computed as c } from "vue"; const n = () => null, v = [ { label: "", commands: [ { type: "folder", id: "import-from-openapi-swagger-postman-curl", name: "Import from OpenAPI/Swagger/Postman/cURL", icon: "Import" }, { type: "folder", id: "create-document", name: "Create Document", icon: "Collection" }, { type: "folder", id: "add-tag", name: "Add Tag", icon: "Folder", props: n() }, { type: "folder", id: "create-request", name: "Create Request", icon: "ExternalLink", props: n() }, { type: "folder", id: "add-example", name: "Add Example", icon: "Example", props: n() }, /** Hidden commands accessible programmatically but not shown in UI */ { type: "hidden-folder", id: "import-curl-command", name: "Import cURL Command", props: n() } ] }, { label: "Pages", commands: [ { type: "route", id: "environment", name: "Environment", icon: "Brackets", to: { name: "workspace.environment" } }, { type: "route", id: "cookies", name: "Cookies", icon: "Cookie", to: { name: "workspace.cookies" } }, { type: "route", id: "settings", name: "Settings", icon: "Settings", to: { name: "workspace.settings" } } ] } ], w = () => { const r = g(), t = s(""), a = s(null), m = s(null), d = c(() => r.open), p = c(() => { const e = t.value.toLowerCase().trim(); return v.map((o) => ({ label: o.label, commands: o.commands.filter((i) => i.type === "hidden-folder" ? !1 : e ? i.name.toLowerCase().includes(e) : !0) })).filter((o) => o.commands.length > 0); }), u = (e, ...o) => { e && (a.value = e, m.value = o[0] ?? null), r.show(); }, f = () => { r.hide(), l(); }, y = (e) => { t.value = e; }, l = () => { t.value = "", a.value = null, m.value = null; }; return { isOpen: d, activeCommand: a, activeCommandProps: m, filterQuery: t, filteredCommands: p, open: u, close: f, setFilterQuery: y, reset: l }; }; export { v as commands, w as useCommandPaletteState };