mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-18 06:22:28 +03:00
pnpm format
This commit is contained in:
parent
03e0ae4429
commit
29a87b7efe
@ -80,7 +80,7 @@
|
||||
</script>
|
||||
|
||||
<form
|
||||
class="command-palette-commit flex w-full flex-col gap-4 rounded p-4 h-full"
|
||||
class="command-palette-commit flex h-full w-full flex-col gap-4 rounded p-4"
|
||||
on:submit|preventDefault={onCommit}
|
||||
>
|
||||
<header class="w-full border-b border-zinc-700 text-lg font-semibold text-white">
|
||||
|
@ -6,183 +6,183 @@ import type { SvelteComponent, SvelteComponentTyped } from 'svelte';
|
||||
import { format, startOfISOWeek, startOfMonth, subDays, subMonths, subWeeks } from 'date-fns';
|
||||
|
||||
type ActionLink = {
|
||||
href: string;
|
||||
href: string;
|
||||
};
|
||||
|
||||
interface Newable<ReturnType> {
|
||||
new(...args: any[]): ReturnType;
|
||||
new (...args: any[]): ReturnType;
|
||||
}
|
||||
|
||||
type ComponentProps<T extends SvelteComponentTyped> = T extends SvelteComponentTyped<infer R>
|
||||
? R
|
||||
: unknown;
|
||||
? R
|
||||
: unknown;
|
||||
|
||||
export type ActionComponent<Component extends SvelteComponentTyped> = {
|
||||
title: string;
|
||||
component: Newable<Component>;
|
||||
props: ComponentProps<QuickCommit>;
|
||||
title: string;
|
||||
component: Newable<Component>;
|
||||
props: ComponentProps<QuickCommit>;
|
||||
};
|
||||
|
||||
export type Action = ActionLink | ActionComponent<QuickCommit> | Group;
|
||||
|
||||
export namespace Action {
|
||||
export const isLink = (action: Action): action is ActionLink => 'href' in action;
|
||||
export const isComponent = (action: Action): action is ActionComponent<any> =>
|
||||
'component' in action;
|
||||
export const isGroup = (action: Action): action is Group => 'commands' in action;
|
||||
export const isLink = (action: Action): action is ActionLink => 'href' in action;
|
||||
export const isComponent = (action: Action): action is ActionComponent<any> =>
|
||||
'component' in action;
|
||||
export const isGroup = (action: Action): action is Group => 'commands' in action;
|
||||
}
|
||||
|
||||
export type Command = {
|
||||
title: string;
|
||||
hotkey?: string;
|
||||
action: Action;
|
||||
icon?: Newable<SvelteComponent>;
|
||||
title: string;
|
||||
hotkey?: string;
|
||||
action: Action;
|
||||
icon?: Newable<SvelteComponent>;
|
||||
};
|
||||
|
||||
export type Group = {
|
||||
title: string;
|
||||
description?: string;
|
||||
commands: Command[];
|
||||
title: string;
|
||||
description?: string;
|
||||
commands: Command[];
|
||||
};
|
||||
|
||||
const goToProjectGroup = ({ projects, input }: { projects: Project[]; input: string }): Group => ({
|
||||
title: 'Go to project',
|
||||
commands: projects
|
||||
.map((project, index) => ({
|
||||
title: project.title,
|
||||
hotkey: `${index + 1}`,
|
||||
action: {
|
||||
href: `/projects/${project.id}/`
|
||||
}
|
||||
}))
|
||||
.filter(({ title }) => input.length === 0 || title.toLowerCase().includes(input.toLowerCase()))
|
||||
title: 'Go to project',
|
||||
commands: projects
|
||||
.map((project, index) => ({
|
||||
title: project.title,
|
||||
hotkey: `${index + 1}`,
|
||||
action: {
|
||||
href: `/projects/${project.id}/`
|
||||
}
|
||||
}))
|
||||
.filter(({ title }) => input.length === 0 || title.toLowerCase().includes(input.toLowerCase()))
|
||||
});
|
||||
|
||||
const actionsGroup = ({ project, input }: { project: Project; input: string }): Group => ({
|
||||
title: 'Actions',
|
||||
commands: [
|
||||
{
|
||||
title: 'Quick commit',
|
||||
hotkey: 'c',
|
||||
action: {
|
||||
title: 'Quick commit',
|
||||
component: QuickCommit,
|
||||
props: { project }
|
||||
},
|
||||
icon: GitCommitIcon
|
||||
},
|
||||
{
|
||||
title: 'Commit',
|
||||
hotkey: 'Shift+c',
|
||||
action: {
|
||||
href: `/projects/${project.id}/commit/`
|
||||
},
|
||||
icon: GitCommitIcon
|
||||
},
|
||||
{
|
||||
title: 'Terminal',
|
||||
hotkey: 'Shift+t',
|
||||
action: {
|
||||
href: `/projects/${project?.id}/terminal/`
|
||||
},
|
||||
icon: IconTerminal
|
||||
},
|
||||
{
|
||||
title: 'Replay History',
|
||||
hotkey: 'r',
|
||||
action: {
|
||||
title: 'Replay working history',
|
||||
commands: [
|
||||
{
|
||||
title: 'Eralier today',
|
||||
icon: RewindIcon,
|
||||
hotkey: '1',
|
||||
action: {
|
||||
href: `/projects/${project.id}/player/${format(new Date(), 'yyyy-MM-dd')}/`
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Yesterday',
|
||||
icon: RewindIcon,
|
||||
hotkey: '2',
|
||||
action: {
|
||||
href: `/projects/${project.id}/player/${format(
|
||||
subDays(new Date(), 1),
|
||||
'yyyy-MM-dd'
|
||||
)}/`
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'The day before yesterday',
|
||||
icon: RewindIcon,
|
||||
hotkey: '3',
|
||||
action: {
|
||||
href: `/projects/${project.id}/player/${format(
|
||||
subDays(new Date(), 2),
|
||||
'yyyy-MM-dd'
|
||||
)}/`
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'The beginning of last week',
|
||||
icon: RewindIcon,
|
||||
hotkey: '4',
|
||||
action: {
|
||||
href: `/projects/${project.id}/player/${format(
|
||||
startOfISOWeek(subWeeks(new Date(), 1)),
|
||||
'yyyy-MM-dd'
|
||||
)}/`
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'The beginning of last month',
|
||||
icon: RewindIcon,
|
||||
hotkey: '5',
|
||||
action: {
|
||||
href: `/projects/${project.id}/player/${format(
|
||||
startOfMonth(subMonths(new Date(), 1)),
|
||||
'yyyy-MM-dd'
|
||||
)}/`
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
icon: RewindIcon
|
||||
}
|
||||
].filter(({ title }) => input.length === 0 || title.toLowerCase().includes(input.toLowerCase()))
|
||||
title: 'Actions',
|
||||
commands: [
|
||||
{
|
||||
title: 'Quick commit',
|
||||
hotkey: 'c',
|
||||
action: {
|
||||
title: 'Quick commit',
|
||||
component: QuickCommit,
|
||||
props: { project }
|
||||
},
|
||||
icon: GitCommitIcon
|
||||
},
|
||||
{
|
||||
title: 'Commit',
|
||||
hotkey: 'Shift+c',
|
||||
action: {
|
||||
href: `/projects/${project.id}/commit/`
|
||||
},
|
||||
icon: GitCommitIcon
|
||||
},
|
||||
{
|
||||
title: 'Terminal',
|
||||
hotkey: 'Shift+t',
|
||||
action: {
|
||||
href: `/projects/${project?.id}/terminal/`
|
||||
},
|
||||
icon: IconTerminal
|
||||
},
|
||||
{
|
||||
title: 'Replay History',
|
||||
hotkey: 'r',
|
||||
action: {
|
||||
title: 'Replay working history',
|
||||
commands: [
|
||||
{
|
||||
title: 'Eralier today',
|
||||
icon: RewindIcon,
|
||||
hotkey: '1',
|
||||
action: {
|
||||
href: `/projects/${project.id}/player/${format(new Date(), 'yyyy-MM-dd')}/`
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Yesterday',
|
||||
icon: RewindIcon,
|
||||
hotkey: '2',
|
||||
action: {
|
||||
href: `/projects/${project.id}/player/${format(
|
||||
subDays(new Date(), 1),
|
||||
'yyyy-MM-dd'
|
||||
)}/`
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'The day before yesterday',
|
||||
icon: RewindIcon,
|
||||
hotkey: '3',
|
||||
action: {
|
||||
href: `/projects/${project.id}/player/${format(
|
||||
subDays(new Date(), 2),
|
||||
'yyyy-MM-dd'
|
||||
)}/`
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'The beginning of last week',
|
||||
icon: RewindIcon,
|
||||
hotkey: '4',
|
||||
action: {
|
||||
href: `/projects/${project.id}/player/${format(
|
||||
startOfISOWeek(subWeeks(new Date(), 1)),
|
||||
'yyyy-MM-dd'
|
||||
)}/`
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'The beginning of last month',
|
||||
icon: RewindIcon,
|
||||
hotkey: '5',
|
||||
action: {
|
||||
href: `/projects/${project.id}/player/${format(
|
||||
startOfMonth(subMonths(new Date(), 1)),
|
||||
'yyyy-MM-dd'
|
||||
)}/`
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
icon: RewindIcon
|
||||
}
|
||||
].filter(({ title }) => input.length === 0 || title.toLowerCase().includes(input.toLowerCase()))
|
||||
});
|
||||
|
||||
const fileGroup = ({
|
||||
project,
|
||||
input
|
||||
project,
|
||||
input
|
||||
}: {
|
||||
project: Project;
|
||||
input: string;
|
||||
project: Project;
|
||||
input: string;
|
||||
}): Group | Promise<Group> =>
|
||||
input.length === 0
|
||||
? {
|
||||
title: 'Files',
|
||||
description: 'type part of a file name',
|
||||
commands: []
|
||||
}
|
||||
: matchFiles({ projectId: project.id, matchPattern: input }).then((files) => ({
|
||||
title: 'Files',
|
||||
description: files.length === 0 ? `no files containing '${input}'` : '',
|
||||
commands: files.map((file) => ({
|
||||
title: file,
|
||||
action: {
|
||||
href: '/'
|
||||
}
|
||||
}))
|
||||
}));
|
||||
input.length === 0
|
||||
? {
|
||||
title: 'Files',
|
||||
description: 'type part of a file name',
|
||||
commands: []
|
||||
}
|
||||
: matchFiles({ projectId: project.id, matchPattern: input }).then((files) => ({
|
||||
title: 'Files',
|
||||
description: files.length === 0 ? `no files containing '${input}'` : '',
|
||||
commands: files.map((file) => ({
|
||||
title: file,
|
||||
action: {
|
||||
href: '/'
|
||||
}
|
||||
}))
|
||||
}));
|
||||
|
||||
export default (params: { projects: Project[]; project?: Project; input: string }) => {
|
||||
const { projects, input, project } = params;
|
||||
const groups = [];
|
||||
const { projects, input, project } = params;
|
||||
const groups = [];
|
||||
|
||||
!project && groups.push(goToProjectGroup({ projects, input }));
|
||||
project && groups.push(actionsGroup({ project, input }));
|
||||
project && groups.push(fileGroup({ project, input }));
|
||||
!project && groups.push(goToProjectGroup({ projects, input }));
|
||||
project && groups.push(actionsGroup({ project, input }));
|
||||
project && groups.push(fileGroup({ project, input }));
|
||||
|
||||
return groups;
|
||||
return groups;
|
||||
};
|
||||
|
@ -1,4 +1,16 @@
|
||||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<script lang="ts">
|
||||
let className = '';
|
||||
export { className as class };
|
||||
</script>
|
||||
|
||||
<svg
|
||||
class={className}
|
||||
width="20"
|
||||
height="20"
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M9.88822 7.00178C9.16279 7.02506 8.46269 7.2735 7.88503 7.71283C7.30733 8.15203 6.88067 8.76019 6.66431 9.45298H3.03247C2.66239 9.45651 2.32189 9.65594 2.13796 9.97703C1.95401 10.2981 1.95401 10.6927 2.13796 11.0138C2.32191 11.3349 2.66239 11.5343 3.03247 11.5379H6.66431C6.96248 12.4919 7.655 13.2725 8.56658 13.6825C9.47816 14.0925 10.5217 14.0925 11.4333 13.6825C12.3449 13.2725 13.0374 12.4919 13.3356 11.5379H16.9674C17.3375 11.5343 17.678 11.3349 17.8619 11.0138C18.046 10.6927 18.046 10.2981 17.8619 9.97703C17.678 9.65594 17.3375 9.4565 16.9674 9.45298H13.3356C13.1079 8.72377 12.6475 8.08927 12.0249 7.64651C11.4022 7.20388 10.6517 6.97741 9.88822 7.00178ZM9.96575 9.08105C10.3461 9.07179 10.714 9.21698 10.9855 9.48347C11.2571 9.74994 11.4092 10.115 11.4071 10.4954C11.4136 10.8728 11.2682 11.2369 11.0036 11.5061C10.739 11.7752 10.3774 11.9267 10 11.9267C9.62248 11.9267 9.26091 11.7752 8.99641 11.5061C8.73176 11.2369 8.58632 10.8728 8.59278 10.4954C8.59083 10.1269 8.73357 9.77225 8.99029 9.50774C9.24701 9.24334 9.59723 9.0901 9.96575 9.08109V9.08105Z"
|
||||
fill="#71717A"
|
||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.3 KiB |
@ -1,4 +1,16 @@
|
||||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<script lang="ts">
|
||||
let className = '';
|
||||
export { className as class };
|
||||
</script>
|
||||
|
||||
<svg
|
||||
class={className}
|
||||
width="20"
|
||||
height="20"
|
||||
viewBox="0 0 20 20"
|
||||
fill="none"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
clip-rule="evenodd"
|
||||
|
Before Width: | Height: | Size: 767 B After Width: | Height: | Size: 875 B |
@ -4,13 +4,13 @@ export { default as statuses } from './statuses';
|
||||
export { default as activity } from './activity';
|
||||
|
||||
export const commit = (params: { projectId: string; message: string; push: boolean }) =>
|
||||
invoke<boolean>('git_commit', params);
|
||||
invoke<boolean>('git_commit', params);
|
||||
|
||||
export const stage = (params: { projectId: string; paths: Array<string> }) =>
|
||||
invoke<void>('git_stage', params);
|
||||
invoke<void>('git_stage', params);
|
||||
|
||||
export const unstage = (params: { projectId: string; paths: Array<string> }) =>
|
||||
invoke<void>('git_unstage', params);
|
||||
invoke<void>('git_unstage', params);
|
||||
|
||||
export const matchFiles = (params: { projectId: string; matchPattern: string }) =>
|
||||
invoke<string[]>('git_match_paths', params);
|
||||
invoke<string[]>('git_match_paths', params);
|
||||
|
@ -1,7 +1,7 @@
|
||||
export const debounce = <T extends (...args: any[]) => any>(fn: T, delay: number) => {
|
||||
let timeout: ReturnType<typeof setTimeout>;
|
||||
return (...args: any[]) => {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => fn(...args), delay);
|
||||
};
|
||||
let timeout: ReturnType<typeof setTimeout>;
|
||||
return (...args: any[]) => {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => fn(...args), delay);
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user