Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

MarkdownFileLink.logic.ts

62 lines1.8 KB

1import type { EnvironmentId } from "@t3tools/contracts";
2import { splitFilePathPosition } from "@t3tools/shared/fileLinks";
3​
4import {
5 shouldOpenMarkdownFileLinkInBrowserByDefault,
6 type MarkdownFileLinkMeta,
7} from "../../markdown-links";
8import type { RemoteOpenMode } from "../../remoteOpen";
9​
10export function canUseMarkdownFileShellActions(
11 environmentId: EnvironmentId | null,
12 remoteOpenMode: RemoteOpenMode,
13 isRemoteOpenResolved: boolean,
14): boolean {
15 return environmentId !== null && isRemoteOpenResolved && remoteOpenMode === "local-exec";
17​
18export function hasMarkdownFilePrimaryAction(input: {
19 canOpenInEditor: boolean;
20 canOpenInBrowser: boolean;
21 canOpenInPanel: boolean;
22 canOpenMedia?: boolean;
23}): boolean {
24 return (
25 input.canOpenInEditor ||
26 input.canOpenInBrowser ||
27 input.canOpenInPanel ||
28 input.canOpenMedia === true
29 );
31​
32export function markdownFileCopyMenuItems({
33 targetPath,
34 workspaceRelativePath,
35}: Pick<MarkdownFileLinkMeta, "targetPath" | "workspaceRelativePath">) {
36 const items = [
37 { id: "copy-full", label: "Copy full path", value: targetPath, title: "Full path" },
38 ];
39 if (workspaceRelativePath !== null) {
40 const position = targetPath.slice(splitFilePathPosition(targetPath).path.length);
41 items.unshift({
42 id: "copy-relative",
43 label: "Copy relative path",
44 value: `${workspaceRelativePath}${position}`,
45 title: "Relative path",
46 });
47 }
48 return items;
50​
51export function shouldUseMarkdownFileBrowserPrimaryAction(input: {
52 iconPath: string;
53 canOpenInEditor: boolean;
54 canOpenInBrowser: boolean;
55 canOpenInPanel: boolean;
56}): boolean {
57 return (
58 input.canOpenInBrowser &&
59 (shouldOpenMarkdownFileLinkInBrowserByDefault(input.iconPath) ||
60 (!input.canOpenInEditor && !input.canOpenInPanel))
61 );