
META-INF.resources.js.style-book-editor.UndoHistory.js Maven / Gradle / Ivy
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
import {ClayButtonWithIcon} from '@clayui/button';
import ClayDropDown, {Align} from '@clayui/drop-down';
import {
ReactPortal,
useEventListener,
useIsMounted,
} from '@liferay/frontend-js-react-web';
import {sub} from 'frontend-js-web';
import React, {useState} from 'react';
import {UNDO_TYPES} from './constants/undoTypes';
import {
useMultipleUndo,
useRedoHistory,
useUndoHistory,
} from './contexts/StyleBookEditorContext';
export default function UndoHistory() {
const isMounted = useIsMounted();
const multipleUndo = useMultipleUndo();
const redoHistory = useRedoHistory();
const undoHistory = useUndoHistory();
const [active, setActive] = useState(false);
const [loading, setLoading] = useState(false);
const onHistoryItemClick = (event, numberOfActions, type) => {
event.preventDefault();
setLoading(true);
multipleUndo({
numberOfActions,
type,
}).then(() => {
if (isMounted()) {
setLoading(false);
}
});
};
return (
<>
}
>
{
onHistoryItemClick(
event,
undoHistory.length,
UNDO_TYPES.undo
);
}}
>
{Liferay.Language.get('undo-all')}
{loading && (
)}
>
);
}
const Overlay = () => {
useEventListener(
'keydown',
(event) => {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
},
true,
window
);
return (
{
event.preventDefault();
event.stopPropagation();
}}
>
);
};
const History = ({actions = [], type, onHistoryItemClick}) => {
const isSelectedAction = (index) => type === UNDO_TYPES.undo && index === 0;
const actionList =
type === UNDO_TYPES.undo ? actions : [...actions].reverse();
return actionList.map((action, index) => (
{
const numberOfActions =
type === UNDO_TYPES.undo
? index
: actionList.length - index;
onHistoryItemClick(event, numberOfActions, type);
}}
symbolRight={isSelectedAction(index) ? 'check' : ''}
>
{sub(Liferay.Language.get('update-x'), action.label)}
));
};
© 2015 - 2025 Weber Informatics LLC | Privacy Policy