Note: The branch name does not fit the new features. - Implement Flex with simplex - Enable rigid body by default (removed IsRigidBody property) <=== possibly a bad idea - Sort children in add and update properties - Implement MaxWidth - Add more docs Fixes : - .env.production url - Symbols: not blocking the linked container when the parent is moving
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import { Dispatch, SetStateAction } from 'react';
|
|
import { getCurrentHistory } from '../Components/Editor/Editor';
|
|
import { IConfiguration } from '../Interfaces/IConfiguration';
|
|
import { IEditorState } from '../Interfaces/IEditorState';
|
|
import { IHistoryState } from '../Interfaces/IHistoryState';
|
|
import { ReviveState } from '../utils/saveload';
|
|
|
|
|
|
const initEditor = (configuration: IConfiguration): void => {
|
|
// faire comme la callback de fetch
|
|
|
|
}
|
|
|
|
const getEditorState = (editorState: IEditorState): void => {
|
|
const customEvent = new CustomEvent<IEditorState>('getEditorState', { detail: editorState });
|
|
document.dispatchEvent(customEvent);
|
|
};
|
|
|
|
const getCurrentHistoryState = (editorState: IEditorState): void => {
|
|
const customEvent = new CustomEvent<IHistoryState>(
|
|
'getCurrentHistoryState',
|
|
{ detail: editorState.history[editorState.historyCurrentStep] });
|
|
document.dispatchEvent(customEvent);
|
|
};
|
|
|
|
const appendNewState = (
|
|
editorState: IEditorState,
|
|
setHistory: Dispatch<SetStateAction<IHistoryState[]>>,
|
|
setHistoryCurrentStep: Dispatch<SetStateAction<number>>,
|
|
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);
|
|
};
|
|
|
|
export interface IEditorEvent {
|
|
name: string
|
|
func: (
|
|
editorState: IEditorState,
|
|
setHistory: Dispatch<SetStateAction<IHistoryState[]>>,
|
|
setHistoryCurrentStep: Dispatch<SetStateAction<number>>,
|
|
eventInitDict?: CustomEventInit
|
|
) => void
|
|
}
|
|
|
|
const events: IEditorEvent[] = [
|
|
{ name: 'getEditorState', func: getEditorState },
|
|
{ name: 'getCurrentHistoryState', func: getCurrentHistoryState },
|
|
{ name: 'appendNewState', func: appendNewState }
|
|
];
|
|
|
|
export default events;
|