-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
311 additions
and
47 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import React, { useId } from 'react'; | ||
|
||
import { twMerge } from 'tailwind-merge'; | ||
|
||
import { ReactComponent as Arrow } from '@renderer/assets/icons/arrow-down.svg'; | ||
import { CanvasEditor } from '@renderer/lib/CanvasEditor'; | ||
import { Action, actionDescriptions, Stack } from '@renderer/lib/data/UndoRedo'; | ||
|
||
interface HistoryProps { | ||
editor: CanvasEditor | null; | ||
} | ||
|
||
const groupByNumberOfConnectedActions = (stack: Stack) => { | ||
const res: Array<Action<any> | Action<any>[]> = []; | ||
|
||
let i = stack.length - 1; | ||
while (i >= 0) { | ||
const numberOfConnectedActions = stack[i].numberOfConnectedActions; | ||
if (numberOfConnectedActions) { | ||
const block: Action<any>[] = []; | ||
for (let j = 0; j < numberOfConnectedActions + 1; j++) { | ||
block.push(stack[i]); | ||
i--; | ||
} | ||
res.push(block.reverse()); | ||
} else { | ||
res.push(stack[i]); | ||
i--; | ||
} | ||
} | ||
|
||
return res; | ||
}; | ||
|
||
const HistoryItem: React.FC<{ data: Action<any>; labelClassName?: string }> = ({ | ||
data, | ||
labelClassName, | ||
}) => { | ||
const { type } = data; | ||
|
||
const id = useId(); | ||
|
||
return ( | ||
<div className="w-full"> | ||
<input id={id} type="checkbox" className="peer sr-only" /> | ||
<label | ||
htmlFor={id} | ||
className={twMerge( | ||
'flex w-full items-center justify-between rounded-sm p-1 peer-checked:rounded-b-none peer-checked:bg-bg-hover hover:bg-bg-hover', | ||
labelClassName | ||
)} | ||
> | ||
{actionDescriptions[type](data.args).name} | ||
<Arrow height={20} width={20} /> | ||
</label> | ||
|
||
<div className="max-h-0 overflow-hidden rounded-b-sm bg-bg-hover transition-all peer-checked:max-h-[1000px]"> | ||
<p className="whitespace-pre-wrap border-t border-border-primary p-1"> | ||
{actionDescriptions[type](data.args).description} | ||
</p> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const HistoryWithoutEditor: React.FC = () => { | ||
return <p>Нельзя посмотреть историю до инциализации</p>; | ||
}; | ||
|
||
const HistoryWithEditor: React.FC<{ editor: CanvasEditor }> = ({ editor }) => { | ||
const { undoStack, redoStack } = editor.container.machine.undoRedo.use(); | ||
|
||
return ( | ||
<div> | ||
<div className="mb-4 flex gap-1"> | ||
<button className="btn-secondary" onClick={() => editor.container.machine.undoRedo.undo()}> | ||
Назад | ||
</button> | ||
<button className="btn-secondary" onClick={() => editor.container.machine.undoRedo.redo()}> | ||
Вперёд | ||
</button> | ||
</div> | ||
|
||
<div> | ||
<h3 className="mb-3 font-semibold">Undo Stack</h3> | ||
<div className="h-[400px] space-y-1 overflow-y-auto pr-3 scrollbar-thin scrollbar-track-scrollbar-track scrollbar-thumb-scrollbar-thumb scrollbar-track-rounded-full scrollbar-thumb-rounded-full"> | ||
{groupByNumberOfConnectedActions(undoStack).map((item, i) => { | ||
if (Array.isArray(item)) { | ||
return ( | ||
<div key={i} className="space-y-1 rounded-sm border border-border-primary p-1"> | ||
{item.map((data, j) => ( | ||
<HistoryItem key={j} data={data} /> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
return <HistoryItem key={i} data={item} labelClassName="pr-2" />; | ||
})} | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<h3 className="mb-3 font-semibold">Redo Stack</h3> | ||
<div className="h-[400px] space-y-1 overflow-y-auto pr-3 scrollbar-thin scrollbar-track-scrollbar-track scrollbar-thumb-scrollbar-thumb scrollbar-track-rounded-full scrollbar-thumb-rounded-full"> | ||
{groupByNumberOfConnectedActions(redoStack).map((item, i) => { | ||
if (Array.isArray(item)) { | ||
return ( | ||
<div key={i} className="space-y-1 rounded-sm border border-border-primary p-1"> | ||
{item.map((data, j) => ( | ||
<HistoryItem key={j} data={data} /> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
return <HistoryItem key={i} data={item} />; | ||
})} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export const History: React.FC<HistoryProps> = ({ editor }) => { | ||
return ( | ||
<section className="flex flex-col"> | ||
<h3 className="mx-4 mb-3 border-b border-border-primary py-2 text-center text-lg"> | ||
История изменений | ||
</h3> | ||
<div className="px-4"> | ||
{editor ? <HistoryWithEditor editor={editor} /> : <HistoryWithoutEditor />} | ||
</div> | ||
</section> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/renderer/src/components/Setting.tsx → ...nderer/src/components/Sidebar/Setting.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.