|
| 1 | +export const ACCEPTED_IMAGE_TYPES = ["image/png", "image/jpeg", "image/gif", "image/webp"] |
| 2 | + |
| 3 | +export const ACCEPTED_FILE_TYPES = [ |
| 4 | + ...ACCEPTED_IMAGE_TYPES, |
| 5 | + "application/pdf", |
| 6 | + "text/*", |
| 7 | + "application/json", |
| 8 | + "application/ld+json", |
| 9 | + "application/toml", |
| 10 | + "application/x-toml", |
| 11 | + "application/x-yaml", |
| 12 | + "application/xml", |
| 13 | + "application/yaml", |
| 14 | + ".c", |
| 15 | + ".cc", |
| 16 | + ".cjs", |
| 17 | + ".conf", |
| 18 | + ".cpp", |
| 19 | + ".css", |
| 20 | + ".csv", |
| 21 | + ".cts", |
| 22 | + ".env", |
| 23 | + ".go", |
| 24 | + ".gql", |
| 25 | + ".graphql", |
| 26 | + ".h", |
| 27 | + ".hh", |
| 28 | + ".hpp", |
| 29 | + ".htm", |
| 30 | + ".html", |
| 31 | + ".ini", |
| 32 | + ".java", |
| 33 | + ".js", |
| 34 | + ".json", |
| 35 | + ".jsx", |
| 36 | + ".log", |
| 37 | + ".md", |
| 38 | + ".mdx", |
| 39 | + ".mjs", |
| 40 | + ".mts", |
| 41 | + ".py", |
| 42 | + ".rb", |
| 43 | + ".rs", |
| 44 | + ".sass", |
| 45 | + ".scss", |
| 46 | + ".sh", |
| 47 | + ".sql", |
| 48 | + ".toml", |
| 49 | + ".ts", |
| 50 | + ".tsx", |
| 51 | + ".txt", |
| 52 | + ".xml", |
| 53 | + ".yaml", |
| 54 | + ".yml", |
| 55 | + ".zsh", |
| 56 | +] |
| 57 | + |
| 58 | +const MIME_EXT = new Map([ |
| 59 | + ["image/png", "png"], |
| 60 | + ["image/jpeg", "jpg"], |
| 61 | + ["image/gif", "gif"], |
| 62 | + ["image/webp", "webp"], |
| 63 | + ["application/pdf", "pdf"], |
| 64 | + ["application/json", "json"], |
| 65 | + ["application/ld+json", "jsonld"], |
| 66 | + ["application/toml", "toml"], |
| 67 | + ["application/x-toml", "toml"], |
| 68 | + ["application/x-yaml", "yaml"], |
| 69 | + ["application/xml", "xml"], |
| 70 | + ["application/yaml", "yaml"], |
| 71 | +]) |
| 72 | + |
| 73 | +const TEXT_EXT = ["txt", "text", "md", "markdown", "log", "csv"] |
| 74 | + |
| 75 | +export const ACCEPTED_FILE_EXTENSIONS = Array.from( |
| 76 | + new Set( |
| 77 | + ACCEPTED_FILE_TYPES.flatMap((item) => { |
| 78 | + if (item.startsWith(".")) return [item.slice(1)] |
| 79 | + if (item === "text/*") return TEXT_EXT |
| 80 | + const out = MIME_EXT.get(item) |
| 81 | + return out ? [out] : [] |
| 82 | + }), |
| 83 | + ), |
| 84 | +).sort() |
| 85 | + |
| 86 | +export function filePickerFilters(ext?: string[]) { |
| 87 | + if (!ext || ext.length === 0) return undefined |
| 88 | + return [{ name: "Files", extensions: ext }] |
| 89 | +} |
0 commit comments