fix historyversion

This commit is contained in:
Víctor Losada Hernández
2026-09-30 22:05:37 +02:00
parent e3d3289d8d
commit d3c186aa5f
4 changed files with 86 additions and 34 deletions
+17 -2
View File
@@ -22,7 +22,7 @@ import _ from 'lodash';
// use react context to keep track of the menu depth (menus in menus) // use react context to keep track of the menu depth (menus in menus)
const MenuDepthContext = React.createContext(0); const MenuDepthContext = React.createContext(0);
const Dropdown = ({ groupName, className = null, icon, children, color = null, customTrigger, ...props })=>{ const Dropdown = ({ groupName, className = null, icon, children, color = null, customTrigger, disabled, ...props })=>{
const reactId = useId(); const reactId = useId();
const safeId = reactId.replace(/[^a-zA-Z0-9_-]/g, ''); const safeId = reactId.replace(/[^a-zA-Z0-9_-]/g, '');
const menuId = `${_.kebabCase(groupName)}-${safeId}-menu`; const menuId = `${_.kebabCase(groupName)}-${safeId}-menu`;
@@ -35,6 +35,21 @@ const Dropdown = ({ groupName, className = null, icon, children, color = null, c
const triggerRef = useRef(null); const triggerRef = useRef(null);
const menuRef = useRef(null); const menuRef = useRef(null);
if(disabled){
return (
<li className={['menu-wrapper', className].filter(Boolean).join(' ')} role='none'>
<button
className={['menu-item', color].filter(Boolean).join(' ')}
aria-label={groupName}
role='menuitem'
disabled
>
{trigger(groupName, icon)}
</button>
</li>
);
}
// use setAttribute instead of the React style prop because React strips unknown CSS // use setAttribute instead of the React style prop because React strips unknown CSS
// properties (like anchor-name) from inline styles in browsers that don't support them. // properties (like anchor-name) from inline styles in browsers that don't support them.
// setAttribute writes raw CSS text that the anchor positioning polyfill can read // setAttribute writes raw CSS text that the anchor positioning polyfill can read
@@ -92,7 +107,7 @@ const Dropdown = ({ groupName, className = null, icon, children, color = null, c
}; };
return ( return (
<li className='menu-wrapper' role='none'> <li className={['menu-wrapper', className].filter(Boolean).join(' ')} role='none'>
<button <button
id={`${menuId}-trigger`} id={`${menuId}-trigger`}
className={['menu-item', color].join(' ')} className={['menu-item', color].join(' ')}
+3
View File
@@ -11,6 +11,9 @@
} }
:root { --activeTriggerColor : var(--activeTriggerColor); } :root { --activeTriggerColor : var(--activeTriggerColor); }
.menu-wrapper {
list-style: none;
}
.menu-list { .menu-list {
position : fixed; position : fixed;
top : anchor(bottom); top : anchor(bottom);
@@ -1,6 +1,6 @@
/*eslint max-lines: ["warn", {"max": 350, "skipBlankLines": true, "skipComments": true}]*/ /*eslint max-lines: ["warn", {"max": 350, "skipBlankLines": true, "skipComments": true}]*/
import './snippetbar.less'; import './snippetbar.less';
import React, { useState, useEffect} from 'react'; import React, { useState, useEffect } from 'react';
import { Dropdown } from '@components/dropdown/dropdown.jsx'; import { Dropdown } from '@components/dropdown/dropdown.jsx';
import _ from 'lodash'; import _ from 'lodash';
@@ -49,7 +49,6 @@ const SnippetBar = ({
updateBrew = ()=>{} updateBrew = ()=>{}
})=>{ })=>{
const [snippets, setSnippets] = useState([]); const [snippets, setSnippets] = useState([]);
const [showHistory, setShowHistory] = useState(false);
const [historyExists, setHistoryExists] = useState(false); const [historyExists, setHistoryExists] = useState(false);
const [historyItems, setHistoryItems] = useState([]); const [historyItems, setHistoryItems] = useState([]);
@@ -139,46 +138,76 @@ const SnippetBar = ({
return updateBrew(item); return updateBrew(item);
}; };
const toggleHistoryMenu = ()=>setShowHistory(!showHistory); const renderHistoryMenu = ()=>{
if(!historyExists) return <Dropdown
groupName='History'
icon='fas fa-clock-rotate-left'
className='history'
customTrigger={
<>
<i className='fas fa-clock-rotate-left' />
</>
} disabled></Dropdown>;
const renderHistoryItems = ()=>{ return (
if(!historyExists) return; <Dropdown
groupName='History'
icon='fas fa-clock-rotate-left'
className='history'
customTrigger={
<>
<i className='fas fa-clock-rotate-left' />
</>
}
return <div className='dropdown'> >
{_.map(historyItems, (item, index)=>{ {_.map(historyItems, (item, index)=>{
if(item.noData || !item.savedAt) return; if(item.noData || !item.savedAt) return null;
const saveTime = new Date(item.savedAt); const saveTime = new Date(item.savedAt);
const diffMs = new Date() - saveTime; const diffMs = new Date() - saveTime;
const diffSecs = Math.floor(diffMs / 1000); const diffSecs = Math.floor(diffMs / 1000);
let diffString = `about ${diffSecs} seconds ago`; let diffString = `about ${diffSecs} seconds ago`;
if(diffSecs > 60) diffString = `about ${Math.floor(diffSecs / 60)} minutes ago`; if(diffSecs > 60)
if(diffSecs > (60 * 60)) diffString = `about ${Math.floor(diffSecs / (60 * 60))} hours ago`; diffString = `about ${Math.floor(diffSecs / 60)} minutes ago`;
if(diffSecs > (24 * 60 * 60)) diffString = `about ${Math.floor(diffSecs / (24 * 60 * 60))} days ago`; if(diffSecs > (60 * 60))
if(diffSecs > (7 * 24 * 60 * 60)) diffString = `about ${Math.floor(diffSecs / (7 * 24 * 60 * 60))} weeks ago`; diffString = `about ${Math.floor(diffSecs / (60 * 60))} hours ago`;
if(diffSecs > (24 * 60 * 60))
diffString = `about ${Math.floor(diffSecs / (24 * 60 * 60))} days ago`;
if(diffSecs > (7 * 24 * 60 * 60))
diffString = `about ${Math.floor(diffSecs / (7 * 24 * 60 * 60))} weeks ago`;
return <div className='snippet' key={index} onClick={()=>{replaceContent(item);}} > return (
<i className={`fas fa-${index+1}`} /> <li key={index} role='none'>
<span className='name' title={saveTime.toISOString()}>v{item.version} : {diffString}</span> <button
</div>; className='menu-item'
})} onClick={()=>replaceContent(item)}
</div>; role='menuitem'
>
<i className={`fas fa-${index + 1}`} />
<span
className='name'
title={saveTime.toISOString()}
>
v{item.version} : {diffString}
</span>
</button>
</li>
);
})}
</Dropdown>
);
}; };
const renderEditorButtons =()=>{ const renderEditorButtons =()=>{
if(!showEditButtons) return; if(!showEditButtons) return;
return ( return (
<div className='editors'> <div className='editors'>
{view !== 'meta' && view !== 'settings' && <><div className='historyTools'> {view !== 'meta' && view !== 'settings' && <><div className='historyTools'>
<button className={`editorTool snippetGroup history ${historyExists ? 'active' : ''}`} {renderHistoryMenu()}
onClick={toggleHistoryMenu} >
<i className='fas fa-clock-rotate-left' />
{ showHistory && renderHistoryItems() }
</button>
<button className={`editorTool undo ${historySize.done ? 'active' : ''}`} <button className={`editorTool undo ${historySize.done ? 'active' : ''}`}
onClick={undo} > onClick={undo} >
<i className='fas fa-undo' /> <i className='fas fa-undo' />
@@ -25,7 +25,7 @@
display : flex; display : flex;
justify-content : flex-end; justify-content : flex-end;
min-width : 275px; //must be controlled every time an item is added, must be hardcoded for the wrapping as it is applied min-width : 275px; //must be controlled every time an item is added, must be hardcoded for the wrapping as it is applied
font-size : 0.85rem; font-size:0.85rem;
&:only-child {min-width : unset; margin-left : auto;} &:only-child {min-width : unset; margin-left : auto;}
reading-order : 2; reading-order : 2;
@@ -36,7 +36,7 @@
&:first-child { border-left : none; } &:first-child { border-left : none; }
& > button { & > button, & > li {
position : relative; position : relative;
width : @menuHeight; width : @menuHeight;
height : @menuHeight; height : @menuHeight;
@@ -44,7 +44,7 @@
text-align : center; text-align : center;
cursor : pointer; cursor : pointer;
&.editorTool:not(.active) { cursor : not-allowed; } &.editorTool:not(.active),&.editorTool:disabled { cursor : not-allowed; }
&:hover,&.selected { background-color : var(--hoverMenuColor); } &:hover,&.selected { background-color : var(--hoverMenuColor); }
&.text { &.text {
@@ -85,11 +85,16 @@
&.active { color : inherit; } &.active { color : inherit; }
} }
&.history { &.history {
font-size:.70rem;
i {
min-width:auto;
}
.tooltipLeft('History'); .tooltipLeft('History');
position : relative; position : relative;
color : grey; color : grey;
border : none; border : none;
&.active { color : inherit; } &:not(:disabled) { color : inherit; }
& > .dropdown { & > .dropdown {
right : -1px; right : -1px;
& > .snippet { padding-right : 10px; } & > .snippet { padding-right : 10px; }