Merged PR 173: Implements API methods through right click + more (read desc)

- Implements API methods through right click
- Refactor events
- Refactor usage of setHistory and setHistoryCurrentStep into a single function
- Update ContainerOperations documentations
- Added AddContainers in order to add multiple containers + refactor AddContainer to use it
- Fix regression
- Fix AddContainer at index
This commit is contained in:
Eric Nguyen 2022-08-30 14:45:29 +00:00
parent 79c6874240
commit 57e6c9a156
20 changed files with 652 additions and 291 deletions

View file

@ -5,61 +5,48 @@ import { IEditorState } from '../Interfaces/IEditorState';
import { IHistoryState } from '../Interfaces/IHistoryState';
import { ReviveState } from '../utils/saveload';
const initEditor = (configuration: IConfiguration): void => {
function InitEditor(configuration: IConfiguration): void {
// faire comme la callback de fetch
}
const getEditorState = (
root: Element | Document,
editorState: IEditorState
): void => {
function GetEditorState(root: Element | Document,
editorState: IEditorState): void {
const customEvent = new CustomEvent<IEditorState>('getEditorState', { detail: editorState });
root.dispatchEvent(customEvent);
};
}
const getCurrentHistoryState = (
root: Element | Document,
editorState: IEditorState
): void => {
function GetCurrentHistoryState(root: Element | Document,
editorState: IEditorState): void {
const customEvent = new CustomEvent<IHistoryState>(
'getCurrentHistoryState',
{ detail: editorState.history[editorState.historyCurrentStep] });
root.dispatchEvent(customEvent);
};
}
const appendNewState = (
root: Element | Document,
function AppendNewState(root: Element | Document,
editorState: IEditorState,
setHistory: Dispatch<SetStateAction<IHistoryState[]>>,
setHistoryCurrentStep: Dispatch<SetStateAction<number>>,
eventInitDict?: CustomEventInit
): void => {
setNewHistory: (newHistory: IHistoryState[]) => void,
eventInitDict?: CustomEventInit): void {
const state: IHistoryState = JSON.parse(eventInitDict?.detail.state);
ReviveState(state);
const history = GetCurrentHistory(editorState.history, editorState.historyCurrentStep);
history.push(state);
setHistory(history);
setHistoryCurrentStep(history.length - 1);
};
setNewHistory(history);
}
export interface IEditorEvent {
name: string
func: (
root: Element | Document,
editorState: IEditorState,
setHistory: Dispatch<SetStateAction<IHistoryState[]>>,
setHistoryCurrentStep: Dispatch<SetStateAction<number>>,
setNewHistory: (newHistory: IHistoryState[]) => void,
eventInitDict?: CustomEventInit
) => void
}
const events: IEditorEvent[] = [
{ name: 'getEditorState', func: getEditorState },
{ name: 'getCurrentHistoryState', func: getCurrentHistoryState },
{ name: 'appendNewState', func: appendNewState }
export const events: IEditorEvent[] = [
{ name: 'getEditorState', func: GetEditorState },
{ name: 'getCurrentHistoryState', func: GetCurrentHistoryState },
{ name: 'appendNewState', func: AppendNewState }
];
export default events;