([]);
const setNewHistory = UseNewHistoryState(setHistory, setHistoryCurrentStep);
+ const editorState: IEditorState = {
+ configuration: props.editorState.configuration,
+ history,
+ historyCurrentStep,
+ version: props.editorState.version
+ };
+
function ResetState(): void {
setReplaceContainer({ isReplacing: false, id: undefined, category: undefined });
}
@@ -96,51 +101,40 @@ export function Editor(props: IEditorProps): JSX.Element {
historyCurrentStep,
setHistoryCurrentStep,
() => {
- setNewHistory(DeleteContainer(selectedContainerId, history, historyCurrentStep));
+ setNewHistory(DeleteContainer(selectedContainerId, editorState));
},
ResetState
);
UseCustomEvents(
eventCallbackQueue,
props.root,
- history,
- historyCurrentStep,
- props.configuration,
+ editorState,
editorRef,
setNewHistory
);
UseEditorListener(
props.root,
- history,
- historyCurrentStep,
- props.configuration
+ editorState
);
// Context Menu
const menuActions = new Map();
InitActions(
menuActions,
- props.configuration,
- history,
- historyCurrentStep,
+ editorState,
setNewHistory,
setHistoryCurrentStep,
setReplaceContainer
);
// Render
- const configuration = props.configuration;
const current = GetCurrentHistoryState(history, historyCurrentStep);
const selected = FindContainerById(current.containers, selectedContainerId);
return (
{
setNewHistory(DeleteContainer(
containerId,
- history,
- historyCurrentStep
+ editorState
));
}}
onPropertyChange={(key, value, type) => {
@@ -160,8 +153,7 @@ export function Editor(props: IEditorProps): JSX.Element {
value,
type,
selected,
- history,
- historyCurrentStep
+ editorState
));
}}
addOrReplaceContainer={(type) => {
@@ -172,9 +164,7 @@ export function Editor(props: IEditorProps): JSX.Element {
const newHistory = ReplaceByContainer(
replaceContainer.id,
type,
- configuration,
- history,
- historyCurrentStep
+ editorState
);
setReplaceContainer({ isReplacing: false, id: undefined, category: undefined });
setNewHistory(newHistory);
@@ -182,9 +172,7 @@ export function Editor(props: IEditorProps): JSX.Element {
setNewHistory(AddContainerToSelectedContainer(
type,
selected,
- configuration,
- history,
- historyCurrentStep
+ editorState
));
}
}}
@@ -193,17 +181,13 @@ export function Editor(props: IEditorProps): JSX.Element {
index,
type,
parent,
- configuration,
- history,
- historyCurrentStep
+ editorState
));
}}
addSymbol={(type) => {
setNewHistory(AddSymbol(
type,
- configuration,
- history,
- historyCurrentStep
+ editorState
));
}}
onSymbolPropertyChange={(key, value) => {
@@ -211,8 +195,7 @@ export function Editor(props: IEditorProps): JSX.Element {
key,
value,
selectedSymbolId,
- history,
- historyCurrentStep
+ editorState
));
}}
selectSymbol={(symbolId) => {
@@ -221,16 +204,11 @@ export function Editor(props: IEditorProps): JSX.Element {
deleteSymbol={(symbolId) => {
setNewHistory(DeleteSymbol(
symbolId,
- history,
- historyCurrentStep
+ editorState
));
}}
saveEditorAsJSON={() => {
- SaveEditorAsJSON(
- history,
- historyCurrentStep,
- configuration
- );
+ SaveEditorAsJSON(editorState);
}}
saveEditorAsSVG={() => { SaveEditorAsSVG(); }}
loadState={(move) => { setHistoryCurrentStep(move); }}
diff --git a/src/Events/EditorEvents.ts b/src/Events/EditorEvents.ts
index 7bca82a..42f2deb 100644
--- a/src/Events/EditorEvents.ts
+++ b/src/Events/EditorEvents.ts
@@ -43,18 +43,11 @@ export const events: IEditorEvent[] = [
export function UseCustomEvents(
callbackQueue: React.RefObject,
root: Element | Document,
- history: IHistoryState[],
- historyCurrentStep: number,
- configuration: IConfiguration,
+ editorState: IEditorState,
editorRef: React.RefObject,
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);
diff --git a/src/Interfaces/IEditorState.ts b/src/Interfaces/IEditorState.ts
index 90d01ae..870d9a4 100644
--- a/src/Interfaces/IEditorState.ts
+++ b/src/Interfaces/IEditorState.ts
@@ -5,4 +5,5 @@ export interface IEditorState {
history: IHistoryState[]
historyCurrentStep: number
configuration: IConfiguration
+ version: string
}
diff --git a/src/utils/default.ts b/src/utils/default.ts
index d9c95cc..d1d11d3 100644
--- a/src/utils/default.ts
+++ b/src/utils/default.ts
@@ -10,6 +10,7 @@ import { Orientation } from '../Enums/Orientation';
import { AppState } from '../Enums/AppState';
import { type IDimensionOptions } from '../Interfaces/IDimensionOptions';
import { type IDimensionStyle } from '../Components/SVG/Elements/Dimension';
+import { version } from 'react';
/// EDITOR DEFAULTS ///
@@ -151,7 +152,8 @@ export function GetDefaultEditorState(configuration: IConfiguration): IEditorSta
symbols: new Map()
}
],
- historyCurrentStep: 0
+ historyCurrentStep: 0,
+ version: APP_VERSION
};
}
diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts
index 1430cee..52a1895 100644
--- a/src/vite-env.d.ts
+++ b/src/vite-env.d.ts
@@ -11,3 +11,5 @@ interface ImportMetaEnv {
interface ImportMeta {
readonly env: ImportMetaEnv
}
+
+declare const APP_VERSION: string;
diff --git a/vite.config.ts b/vite.config.ts
index 5a4dc91..d6fa774 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -6,5 +6,8 @@ export default defineConfig({
plugins: [
react()
],
- base: './'
+ base: './',
+ define: {
+ APP_VERSION: JSON.stringify(process.env.npm_package_version)
+ }
});