Refactor usage of EditorState + Add version to editorState + increment editorState to "v2.0.0"
This commit is contained in:
parent
460669987d
commit
afd303f8cb
13 changed files with 136 additions and 179 deletions
|
@ -43,18 +43,11 @@ export const events: IEditorEvent[] = [
|
|||
export function UseCustomEvents(
|
||||
callbackQueue: React.RefObject<CustomEvent[]>,
|
||||
root: Element | Document,
|
||||
history: IHistoryState[],
|
||||
historyCurrentStep: number,
|
||||
configuration: IConfiguration,
|
||||
editorState: IEditorState,
|
||||
editorRef: React.RefObject<HTMLDivElement>,
|
||||
setNewHistory: (newHistory: IHistoryState[], historyCurrentStep?: number) => void
|
||||
): void {
|
||||
useEffect(() => {
|
||||
const editorState: IEditorState = {
|
||||
history,
|
||||
historyCurrentStep,
|
||||
configuration
|
||||
};
|
||||
const current = editorRef.current;
|
||||
|
||||
if (current === null) {
|
||||
|
@ -110,16 +103,9 @@ export function UseCustomEvents(
|
|||
|
||||
export function UseEditorListener(
|
||||
root: Element | Document,
|
||||
history: IHistoryState[],
|
||||
historyCurrentStep: number,
|
||||
configuration: IConfiguration
|
||||
editorState: IEditorState
|
||||
): void {
|
||||
useEffect(() => {
|
||||
const editorState: IEditorState = {
|
||||
history,
|
||||
historyCurrentStep,
|
||||
configuration
|
||||
};
|
||||
const event = new CustomEvent('editorListener', { detail: editorState });
|
||||
root.dispatchEvent(event);
|
||||
});
|
||||
|
@ -209,14 +195,11 @@ function AddContainer({
|
|||
parentId
|
||||
} = eventInitDict?.detail;
|
||||
|
||||
const history = GetCurrentHistory(editorState.history, editorState.historyCurrentStep);
|
||||
const newHistory = AddContainerAction(
|
||||
index,
|
||||
type,
|
||||
parentId,
|
||||
editorState.configuration,
|
||||
history,
|
||||
editorState.historyCurrentStep
|
||||
editorState
|
||||
);
|
||||
setNewHistory(newHistory);
|
||||
|
||||
|
@ -249,9 +232,7 @@ function AppendContainer({
|
|||
parent?.children.length ?? 0,
|
||||
type,
|
||||
parentId,
|
||||
editorState.configuration,
|
||||
history,
|
||||
editorState.historyCurrentStep
|
||||
editorState
|
||||
);
|
||||
setNewHistory(newHistory);
|
||||
|
||||
|
@ -273,13 +254,9 @@ function DeleteContainer({
|
|||
const {
|
||||
containerId
|
||||
} = eventInitDict?.detail;
|
||||
|
||||
const history = GetCurrentHistory(editorState.history, editorState.historyCurrentStep);
|
||||
|
||||
const newHistory = DeleteContainerAction(
|
||||
containerId,
|
||||
history,
|
||||
editorState.historyCurrentStep
|
||||
editorState
|
||||
);
|
||||
setNewHistory(newHistory);
|
||||
|
||||
|
@ -302,13 +279,9 @@ function AddSymbol({
|
|||
name
|
||||
} = eventInitDict?.detail;
|
||||
|
||||
const history = GetCurrentHistory(editorState.history, editorState.historyCurrentStep);
|
||||
|
||||
const newHistory = AddSymbolAction(
|
||||
name,
|
||||
editorState.configuration,
|
||||
history,
|
||||
editorState.historyCurrentStep
|
||||
editorState
|
||||
);
|
||||
setNewHistory(newHistory);
|
||||
|
||||
|
@ -331,11 +304,9 @@ function DeleteSymbol({
|
|||
symbolId
|
||||
} = eventInitDict?.detail;
|
||||
|
||||
const history = GetCurrentHistory(editorState.history, editorState.historyCurrentStep);
|
||||
const newHistory = DeleteSymbolAction(
|
||||
symbolId,
|
||||
history,
|
||||
editorState.historyCurrentStep
|
||||
editorState
|
||||
);
|
||||
setNewHistory(newHistory);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue