Merged PR 194: Added option to disable any API call
Added option to disable any API call Fix http.js and node-http.js Fix MainContainer not using IAvailableContainer from MainContainer Fix generate_dts.py script More docs Fix MainContainer default style. Extend config will now be taken into account. But Main container can still have its own type.
This commit is contained in:
parent
8ba19cc96b
commit
3ecff4cf01
10 changed files with 648 additions and 570 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
export class SVGLayoutDesigner extends Components.ComponentBase {
|
export class SVGLayoutDesigner extends Components.ComponentBase {
|
||||||
|
|
||||||
|
private _hooks: Record<string, (e: CustomEvent) => void>;
|
||||||
public App: AppController;
|
public App: AppController;
|
||||||
public Editor: EditorController;
|
public Editor: EditorController;
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@
|
||||||
super(componentInfo, params);
|
super(componentInfo, params);
|
||||||
this.App = new AppController(this, this.$component);
|
this.App = new AppController(this, this.$component);
|
||||||
this.Editor = new EditorController(this, this.$component);
|
this.Editor = new EditorController(this, this.$component);
|
||||||
|
this._hooks = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +34,7 @@
|
||||||
* @param callback Callback function to call in the event listener
|
* @param callback Callback function to call in the event listener
|
||||||
* @param eventType Event type for the listener to listen to
|
* @param eventType Event type for the listener to listen to
|
||||||
*/
|
*/
|
||||||
public AddEventListener(callback: ((...args: any[]) => void) | undefined, eventType: string) {
|
public AddEventListener(eventType: string, callback: ((...args: any[]) => void) | undefined) {
|
||||||
const root = this.GetRootComponent();
|
const root = this.GetRootComponent();
|
||||||
const listener = (e: CustomEvent) => {
|
const listener = (e: CustomEvent) => {
|
||||||
e.target.removeEventListener(e.type, listener);
|
e.target.removeEventListener(e.type, listener);
|
||||||
|
@ -41,6 +43,40 @@
|
||||||
root.addEventListener(eventType, listener);
|
root.addEventListener(eventType, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Hooks ///
|
||||||
|
|
||||||
|
private static EDITOR_LISTENER_TYPE = 'editorListener';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a hook to the editor state change.
|
||||||
|
* After every time an action is perform on the editor, the callback will be called
|
||||||
|
* @param callback Callback to add that listen to the event
|
||||||
|
*/
|
||||||
|
public AddEditorListenerHook(hookId: string, callback: (state: IEditorState) => void): void {
|
||||||
|
const root = this.GetRootComponent();
|
||||||
|
const customEvent = (e: CustomEvent) => {
|
||||||
|
callback(e.detail);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._hooks[hookId] !== undefined) {
|
||||||
|
console.error(`HookId is already occupied. Please use a different HookId: ${hookId}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._hooks[hookId] = customEvent;
|
||||||
|
root.addEventListener(SVGLayoutDesigner.EDITOR_LISTENER_TYPE, customEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a hook to the editor state change.
|
||||||
|
* @param callback Callback to remove that listen to the event
|
||||||
|
*/
|
||||||
|
public RemoveEditorListenerHook(hookId): void {
|
||||||
|
const root = this.GetRootComponent();
|
||||||
|
root.removeEventListener(SVGLayoutDesigner.EDITOR_LISTENER_TYPE, this._hooks[hookId]);
|
||||||
|
delete this._hooks[hookId];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Macros ///
|
/// Macros ///
|
||||||
|
|
||||||
|
@ -99,7 +135,7 @@
|
||||||
*/
|
*/
|
||||||
public SetEditor(newEditor: IEditorState, callback?: (state: IEditorState) => void) {
|
public SetEditor(newEditor: IEditorState, callback?: (state: IEditorState) => void) {
|
||||||
const eventType = 'setEditor';
|
const eventType = 'setEditor';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const component = this.GetAppComponent();
|
const component = this.GetAppComponent();
|
||||||
component.dispatchEvent(new CustomEvent(eventType, { detail: newEditor }))
|
component.dispatchEvent(new CustomEvent(eventType, { detail: newEditor }))
|
||||||
}
|
}
|
||||||
|
@ -112,7 +148,7 @@
|
||||||
*/
|
*/
|
||||||
public SetLoaded(isLoaded: boolean, callback?: (state: IEditorState) => void) {
|
public SetLoaded(isLoaded: boolean, callback?: (state: IEditorState) => void) {
|
||||||
const eventType = 'setLoaded';
|
const eventType = 'setLoaded';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const component = this.GetAppComponent();
|
const component = this.GetAppComponent();
|
||||||
component.dispatchEvent(new CustomEvent(eventType, { detail: isLoaded }))
|
component.dispatchEvent(new CustomEvent(eventType, { detail: isLoaded }))
|
||||||
}
|
}
|
||||||
|
@ -122,12 +158,10 @@
|
||||||
class EditorController {
|
class EditorController {
|
||||||
app: SVGLayoutDesigner;
|
app: SVGLayoutDesigner;
|
||||||
$component: JQuery;
|
$component: JQuery;
|
||||||
private _hooks: Record<string, (e: CustomEvent) => void>;
|
|
||||||
|
|
||||||
constructor(app: SVGLayoutDesigner, $component: JQuery) {
|
constructor(app: SVGLayoutDesigner, $component: JQuery) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.$component = $component;
|
this.$component = $component;
|
||||||
this._hooks = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,7 +188,7 @@
|
||||||
*/
|
*/
|
||||||
public GetCurrentHistoryState(callback: (state: IHistoryState) => void) {
|
public GetCurrentHistoryState(callback: (state: IHistoryState) => void) {
|
||||||
const eventType = 'getCurrentHistoryState';
|
const eventType = 'getCurrentHistoryState';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const component = this.GetEditorComponent();
|
const component = this.GetEditorComponent();
|
||||||
component.dispatchEvent(new CustomEvent(eventType));
|
component.dispatchEvent(new CustomEvent(eventType));
|
||||||
}
|
}
|
||||||
|
@ -165,7 +199,7 @@
|
||||||
*/
|
*/
|
||||||
public GetEditorState(callback: (state: IEditorState) => void) {
|
public GetEditorState(callback: (state: IEditorState) => void) {
|
||||||
const eventType = 'getEditorState';
|
const eventType = 'getEditorState';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const component = this.GetEditorComponent();
|
const component = this.GetEditorComponent();
|
||||||
component.dispatchEvent(new CustomEvent(eventType));
|
component.dispatchEvent(new CustomEvent(eventType));
|
||||||
}
|
}
|
||||||
|
@ -177,7 +211,7 @@
|
||||||
*/
|
*/
|
||||||
public SetHistory(history: IHistoryState[], callback?: (state: IEditorState) => void) {
|
public SetHistory(history: IHistoryState[], callback?: (state: IEditorState) => void) {
|
||||||
const eventType = 'setHistory';
|
const eventType = 'setHistory';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const component = this.GetEditorComponent();
|
const component = this.GetEditorComponent();
|
||||||
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
|
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
|
||||||
}
|
}
|
||||||
|
@ -190,7 +224,7 @@
|
||||||
*/
|
*/
|
||||||
public ReviveEditorState(editorState: IEditorState, callback: (state: IEditorState) => void) {
|
public ReviveEditorState(editorState: IEditorState, callback: (state: IEditorState) => void) {
|
||||||
const eventType = 'reviveEditorState';
|
const eventType = 'reviveEditorState';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const component = this.GetEditorComponent();
|
const component = this.GetEditorComponent();
|
||||||
component.dispatchEvent(new CustomEvent(eventType, { detail: editorState }));
|
component.dispatchEvent(new CustomEvent(eventType, { detail: editorState }));
|
||||||
}
|
}
|
||||||
|
@ -203,7 +237,7 @@
|
||||||
*/
|
*/
|
||||||
public ReviveHistory(history: IHistoryState[], callback: (state: IHistoryState[]) => void) {
|
public ReviveHistory(history: IHistoryState[], callback: (state: IHistoryState[]) => void) {
|
||||||
const eventType = 'reviveHistory';
|
const eventType = 'reviveHistory';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const component = this.GetEditorComponent();
|
const component = this.GetEditorComponent();
|
||||||
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
|
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
|
||||||
}
|
}
|
||||||
|
@ -215,7 +249,7 @@
|
||||||
*/
|
*/
|
||||||
public AppendNewHistoryState(historyState: IHistoryState, callback?: (state: IEditorState) => void) {
|
public AppendNewHistoryState(historyState: IHistoryState, callback?: (state: IEditorState) => void) {
|
||||||
const eventType = 'appendNewState';
|
const eventType = 'appendNewState';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail: historyState }));
|
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail: historyState }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +262,7 @@
|
||||||
*/
|
*/
|
||||||
public AddContainer(index: number, type: string, parentId: string, callback?: (state: IEditorState) => void) {
|
public AddContainer(index: number, type: string, parentId: string, callback?: (state: IEditorState) => void) {
|
||||||
const eventType = 'addContainer';
|
const eventType = 'addContainer';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const detail = {
|
const detail = {
|
||||||
index,
|
index,
|
||||||
type,
|
type,
|
||||||
|
@ -245,7 +279,7 @@
|
||||||
*/
|
*/
|
||||||
public AddContainerToSelectedContainer(index: number, type: string, callback?: (state: IEditorState) => void) {
|
public AddContainerToSelectedContainer(index: number, type: string, callback?: (state: IEditorState) => void) {
|
||||||
const eventType = 'addContainerToSelectedContainer';
|
const eventType = 'addContainerToSelectedContainer';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const detail = {
|
const detail = {
|
||||||
index,
|
index,
|
||||||
type
|
type
|
||||||
|
@ -261,7 +295,7 @@
|
||||||
*/
|
*/
|
||||||
public AppendContainer(type: string, parentId: string, callback?: (state: IEditorState) => void) {
|
public AppendContainer(type: string, parentId: string, callback?: (state: IEditorState) => void) {
|
||||||
const eventType = 'appendContainer';
|
const eventType = 'appendContainer';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const detail = {
|
const detail = {
|
||||||
type,
|
type,
|
||||||
parentId
|
parentId
|
||||||
|
@ -277,7 +311,7 @@
|
||||||
*/
|
*/
|
||||||
public AppendContainerToSelectedContainer(type: string, callback?: (state: IEditorState) => void) {
|
public AppendContainerToSelectedContainer(type: string, callback?: (state: IEditorState) => void) {
|
||||||
const eventType = 'appendContainerToSelectedContainer';
|
const eventType = 'appendContainerToSelectedContainer';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const detail = {
|
const detail = {
|
||||||
type
|
type
|
||||||
}
|
}
|
||||||
|
@ -291,7 +325,7 @@
|
||||||
*/
|
*/
|
||||||
public SelectContainer(containerId: string, callback?: (state: IEditorState) => void) {
|
public SelectContainer(containerId: string, callback?: (state: IEditorState) => void) {
|
||||||
const eventType = 'selectContainer';
|
const eventType = 'selectContainer';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const detail = {
|
const detail = {
|
||||||
containerId
|
containerId
|
||||||
}
|
}
|
||||||
|
@ -305,7 +339,7 @@
|
||||||
*/
|
*/
|
||||||
public DeleteContainer(containerId: string, callback?: (state: IEditorState) => void) {
|
public DeleteContainer(containerId: string, callback?: (state: IEditorState) => void) {
|
||||||
const eventType = 'deleteContainer';
|
const eventType = 'deleteContainer';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const detail = {
|
const detail = {
|
||||||
containerId
|
containerId
|
||||||
}
|
}
|
||||||
|
@ -320,7 +354,7 @@
|
||||||
*/
|
*/
|
||||||
public AddSymbol(name: string, callback?: (state: IEditorState) => void) {
|
public AddSymbol(name: string, callback?: (state: IEditorState) => void) {
|
||||||
const eventType = 'addSymbol';
|
const eventType = 'addSymbol';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const detail = {
|
const detail = {
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
|
@ -334,7 +368,7 @@
|
||||||
*/
|
*/
|
||||||
public SelectSymbol(symbolId: string, callback?: (state: IEditorState) => void) {
|
public SelectSymbol(symbolId: string, callback?: (state: IEditorState) => void) {
|
||||||
const eventType = 'selectSymbol';
|
const eventType = 'selectSymbol';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const detail = {
|
const detail = {
|
||||||
symbolId
|
symbolId
|
||||||
}
|
}
|
||||||
|
@ -348,49 +382,12 @@
|
||||||
*/
|
*/
|
||||||
public DeleteSymbol(symbolId: string, callback?: (state: IEditorState) => void) {
|
public DeleteSymbol(symbolId: string, callback?: (state: IEditorState) => void) {
|
||||||
const eventType = 'deleteSymbol';
|
const eventType = 'deleteSymbol';
|
||||||
this.app.AddEventListener(callback, eventType);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const detail = {
|
const detail = {
|
||||||
symbolId
|
symbolId
|
||||||
}
|
}
|
||||||
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail }));
|
this.GetEditorComponent().dispatchEvent(new CustomEvent(eventType, { detail }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Hooks ///
|
|
||||||
|
|
||||||
private static EDITOR_LISTENER_TYPE = 'editorListener';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a hook to the editor state change.
|
|
||||||
* After every time an action is perform on the editor, the callback will be called
|
|
||||||
* @param callback Callback to add that listen to the event
|
|
||||||
*/
|
|
||||||
public AddEditorListenerHook(hookId: string, callback: (state: IEditorState) => void): void {
|
|
||||||
const root = this.app.GetRootComponent();
|
|
||||||
const customEvent = (e: CustomEvent) => {
|
|
||||||
callback(e.detail);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._hooks[hookId] !== undefined) {
|
|
||||||
console.error(`HookId is already occupied. Please use a different HookId: ${hookId}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._hooks[hookId] = customEvent;
|
|
||||||
root.addEventListener(EditorController.EDITOR_LISTENER_TYPE, customEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove a hook to the editor state change.
|
|
||||||
* @param callback Callback to remove that listen to the event
|
|
||||||
*/
|
|
||||||
public RemoveEditorListenerHook(hookId): void {
|
|
||||||
const root = this.app.GetRootComponent();
|
|
||||||
root.removeEventListener(EditorController.EDITOR_LISTENER_TYPE, this._hooks[hookId]);
|
|
||||||
delete this._hooks[hookId];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ko.components.register('svg-layout-designer', {
|
ko.components.register('svg-layout-designer', {
|
||||||
|
|
|
@ -3,12 +3,17 @@ import { IConfiguration } from '../../../Interfaces/IConfiguration';
|
||||||
import { FetchConfiguration } from '../../API/api';
|
import { FetchConfiguration } from '../../API/api';
|
||||||
import { IEditorState } from '../../../Interfaces/IEditorState';
|
import { IEditorState } from '../../../Interfaces/IEditorState';
|
||||||
import { LoadState } from './Load';
|
import { LoadState } from './Load';
|
||||||
import { GetDefaultEditorState } from '../../../utils/default';
|
import { DISABLE_API, GetDefaultEditorState } from '../../../utils/default';
|
||||||
|
|
||||||
export function NewEditor(
|
export function NewEditor(
|
||||||
setEditorState: Dispatch<SetStateAction<IEditorState>>,
|
setEditorState: Dispatch<SetStateAction<IEditorState>>,
|
||||||
setLoaded: Dispatch<SetStateAction<boolean>>
|
setLoaded: Dispatch<SetStateAction<boolean>>
|
||||||
): void {
|
): void {
|
||||||
|
if (DISABLE_API) {
|
||||||
|
setLoaded(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch the configuration from the API
|
// Fetch the configuration from the API
|
||||||
FetchConfiguration()
|
FetchConfiguration()
|
||||||
.then((configuration: IConfiguration) => {
|
.then((configuration: IConfiguration) => {
|
||||||
|
|
|
@ -33,20 +33,7 @@ export function GetAction(
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/naming-convention */
|
/* eslint-disable @typescript-eslint/naming-convention */
|
||||||
let prev;
|
const { prev, next } = GetPreviousAndNextSiblings(container);
|
||||||
let next;
|
|
||||||
if (container.parent !== undefined &&
|
|
||||||
container.parent !== null &&
|
|
||||||
container.parent.children.length > 1
|
|
||||||
) {
|
|
||||||
const index = container.parent.children.indexOf(container);
|
|
||||||
if (index > 0) {
|
|
||||||
prev = container.parent.children[index - 1];
|
|
||||||
}
|
|
||||||
if (index < container.parent.children.length - 1) {
|
|
||||||
next = container.parent.children[index + 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const request: ISetContainerListRequest = {
|
const request: ISetContainerListRequest = {
|
||||||
Container: container,
|
Container: container,
|
||||||
|
@ -72,6 +59,23 @@ export function GetAction(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function GetPreviousAndNextSiblings(container: IContainerModel): { prev: IContainerModel | undefined; next: IContainerModel | undefined; } {
|
||||||
|
let prev;
|
||||||
|
let next;
|
||||||
|
if (container.parent !== undefined &&
|
||||||
|
container.parent !== null &&
|
||||||
|
container.parent.children.length > 1) {
|
||||||
|
const index = container.parent.children.indexOf(container);
|
||||||
|
if (index > 0) {
|
||||||
|
prev = container.parent.children[index - 1];
|
||||||
|
}
|
||||||
|
if (index < container.parent.children.length - 1) {
|
||||||
|
next = container.parent.children[index + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { prev, next };
|
||||||
|
}
|
||||||
|
|
||||||
function HandleSetContainerList(
|
function HandleSetContainerList(
|
||||||
action: IAction,
|
action: IAction,
|
||||||
selectedContainer: IContainerModel,
|
selectedContainer: IContainerModel,
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { SaveEditorAsJSON, SaveEditorAsSVG } from './Actions/Save';
|
||||||
import { OnKey } from './Actions/Shortcuts';
|
import { OnKey } from './Actions/Shortcuts';
|
||||||
import { events as EVENTS } from '../../Events/EditorEvents';
|
import { events as EVENTS } from '../../Events/EditorEvents';
|
||||||
import { IEditorState } from '../../Interfaces/IEditorState';
|
import { IEditorState } from '../../Interfaces/IEditorState';
|
||||||
import { MAX_HISTORY } from '../../utils/default';
|
import { DISABLE_API, MAX_HISTORY } from '../../utils/default';
|
||||||
import { AddSymbol, OnPropertyChange as OnSymbolPropertyChange, DeleteSymbol, SelectSymbol } from './Actions/SymbolOperations';
|
import { AddSymbol, OnPropertyChange as OnSymbolPropertyChange, DeleteSymbol, SelectSymbol } from './Actions/SymbolOperations';
|
||||||
import { FindContainerById } from '../../utils/itertools';
|
import { FindContainerById } from '../../utils/itertools';
|
||||||
import { IMenuAction, Menu } from '../Menu/Menu';
|
import { IMenuAction, Menu } from '../Menu/Menu';
|
||||||
|
@ -62,6 +62,10 @@ function InitActions(
|
||||||
);
|
);
|
||||||
|
|
||||||
// API Actions
|
// API Actions
|
||||||
|
if (DISABLE_API) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (const availableContainer of configuration.AvailableContainers) {
|
for (const availableContainer of configuration.AvailableContainers) {
|
||||||
if (availableContainer.Actions === undefined || availableContainer.Actions === null) {
|
if (availableContainer.Actions === undefined || availableContainer.Actions === null) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { IGetFeedbackRequest } from '../../Interfaces/IGetFeedbackRequest';
|
||||||
import { IGetFeedbackResponse } from '../../Interfaces/IGetFeedbackResponse';
|
import { IGetFeedbackResponse } from '../../Interfaces/IGetFeedbackResponse';
|
||||||
import { IHistoryState } from '../../Interfaces/IHistoryState';
|
import { IHistoryState } from '../../Interfaces/IHistoryState';
|
||||||
import { IMessage } from '../../Interfaces/IMessage';
|
import { IMessage } from '../../Interfaces/IMessage';
|
||||||
|
import { DISABLE_API } from '../../utils/default';
|
||||||
import { GetCircularReplacerKeepDataStructure } from '../../utils/saveload';
|
import { GetCircularReplacerKeepDataStructure } from '../../utils/saveload';
|
||||||
|
|
||||||
interface IMessagesSidebarProps {
|
interface IMessagesSidebarProps {
|
||||||
|
@ -68,12 +69,12 @@ export function MessagesSidebar(props: IMessagesSidebarProps): JSX.Element {
|
||||||
const [messages, setMessages] = React.useState<IMessage[]>([]);
|
const [messages, setMessages] = React.useState<IMessage[]>([]);
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
|
||||||
if (window.Worker) {
|
if (window.Worker && !DISABLE_API) {
|
||||||
UseWorker(
|
UseWorker(
|
||||||
props.historyState,
|
props.historyState,
|
||||||
setMessages
|
setMessages
|
||||||
);
|
);
|
||||||
} else {
|
} else if (!DISABLE_API) {
|
||||||
UseAsync(
|
UseAsync(
|
||||||
props.historyState,
|
props.historyState,
|
||||||
setMessages
|
setMessages
|
||||||
|
|
|
@ -27,7 +27,7 @@ export_pattern = re.compile(
|
||||||
r"export ([*] from [\"'\s].*[\"'\s]|{.*}(?: from [\"'\s].*[\"'\s])?);"
|
r"export ([*] from [\"'\s].*[\"'\s]|{.*}(?: from [\"'\s].*[\"'\s])?);"
|
||||||
)
|
)
|
||||||
|
|
||||||
filter_directories = ["./Enums", "./Interfaces"]
|
filter_directories = ["./dist\Enums", "./dist\Interfaces"]
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
'''
|
'''
|
||||||
|
@ -37,6 +37,7 @@ def main():
|
||||||
output_file.write(('declare namespace {} {{\n'.format(namespace)))
|
output_file.write(('declare namespace {} {{\n'.format(namespace)))
|
||||||
for root, subdirs, files in os.walk('./'):
|
for root, subdirs, files in os.walk('./'):
|
||||||
if root not in filter_directories:
|
if root not in filter_directories:
|
||||||
|
print('SKIP ' + root)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print('--\nroot = ' + root)
|
print('--\nroot = ' + root)
|
||||||
|
|
4
src/dts/svgld.d.ts
vendored
4
src/dts/svgld.d.ts
vendored
|
@ -135,6 +135,8 @@ export interface IAvailableContainer {
|
||||||
* DefaultChildType will be disabled for this container and the children
|
* DefaultChildType will be disabled for this container and the children
|
||||||
*/
|
*/
|
||||||
Pattern?: string;
|
Pattern?: string;
|
||||||
|
/** Hide the children in the treeview */
|
||||||
|
HideChildrenInTreeview?: boolean;
|
||||||
/** if true, show the dimension of the container */
|
/** if true, show the dimension of the container */
|
||||||
ShowSelfDimensions?: boolean;
|
ShowSelfDimensions?: boolean;
|
||||||
/** if true show the overall dimensions of its children */
|
/** if true show the overall dimensions of its children */
|
||||||
|
@ -270,6 +272,8 @@ export interface IContainerProperties {
|
||||||
isFlex: boolean;
|
isFlex: boolean;
|
||||||
/** Horizontal alignment, also determines the visual location of x {Left = 0, Center, Right } */
|
/** Horizontal alignment, also determines the visual location of x {Left = 0, Center, Right } */
|
||||||
xPositionReference: XPositionReference;
|
xPositionReference: XPositionReference;
|
||||||
|
/** Hide the children in the treeview */
|
||||||
|
hideChildrenInTreeview: boolean;
|
||||||
/** if true, show the dimension of the container */
|
/** if true, show the dimension of the container */
|
||||||
showSelfDimensions: boolean;
|
showSelfDimensions: boolean;
|
||||||
/** if true show the overall dimensions of its children */
|
/** if true show the overall dimensions of its children */
|
||||||
|
|
|
@ -9,10 +9,22 @@ import { ISymbolModel } from '../Interfaces/ISymbolModel';
|
||||||
|
|
||||||
/// EDITOR DEFAULTS ///
|
/// EDITOR DEFAULTS ///
|
||||||
|
|
||||||
export const FAST_BOOT = import.meta.env.PROD;
|
/** Enable fast boot and disable main menu */
|
||||||
|
export const FAST_BOOT = false;
|
||||||
|
|
||||||
|
/** Disable any call to the API */
|
||||||
|
export const DISABLE_API = false;
|
||||||
|
|
||||||
|
/** Enable keyboard shortcuts */
|
||||||
export const ENABLE_SHORTCUTS = true;
|
export const ENABLE_SHORTCUTS = true;
|
||||||
|
|
||||||
|
/** Size of the history */
|
||||||
export const MAX_HISTORY = 200;
|
export const MAX_HISTORY = 200;
|
||||||
|
|
||||||
|
/** Apply beheviors on children */
|
||||||
export const APPLY_BEHAVIORS_ON_CHILDREN = true;
|
export const APPLY_BEHAVIORS_ON_CHILDREN = true;
|
||||||
|
|
||||||
|
/** Framerate of the svg controller */
|
||||||
export const MAX_FRAMERATE = 60;
|
export const MAX_FRAMERATE = 60;
|
||||||
|
|
||||||
/// CONTAINER DEFAULTS ///
|
/// CONTAINER DEFAULTS ///
|
||||||
|
@ -53,15 +65,58 @@ export const DEFAULT_SYMBOL_HEIGHT = 32;
|
||||||
* Returns the default editor state given the configuration
|
* Returns the default editor state given the configuration
|
||||||
*/
|
*/
|
||||||
export function GetDefaultEditorState(configuration: IConfiguration): IEditorState {
|
export function GetDefaultEditorState(configuration: IConfiguration): IEditorState {
|
||||||
|
if (configuration.MainContainer.Width === undefined ||
|
||||||
|
configuration.MainContainer.Height === undefined) {
|
||||||
|
throw new Error('Cannot initialize project! Main container has an undefined size');
|
||||||
|
}
|
||||||
|
|
||||||
|
const containerConfig = configuration.AvailableContainers.find(config => config.Type === configuration.MainContainer.Type);
|
||||||
|
|
||||||
|
let mainContainerConfig: IContainerProperties;
|
||||||
|
if (containerConfig !== undefined) {
|
||||||
|
const clone = structuredClone(containerConfig);
|
||||||
|
const extendedContainerConfig = Object.assign(clone, configuration.MainContainer);
|
||||||
|
|
||||||
|
if (containerConfig.Style !== undefined) {
|
||||||
|
const styleClone = structuredClone(containerConfig.Style);
|
||||||
|
extendedContainerConfig.Style = Object.assign(styleClone, configuration.MainContainer.Style);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extendedContainerConfig.Width === undefined ||
|
||||||
|
extendedContainerConfig.Height === undefined) {
|
||||||
|
throw new Error('Cannot initialize project! Main container has an undefined size');
|
||||||
|
}
|
||||||
|
|
||||||
|
mainContainerConfig = GetDefaultContainerProps(
|
||||||
|
extendedContainerConfig.Type,
|
||||||
|
0,
|
||||||
|
null,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
extendedContainerConfig.Width,
|
||||||
|
extendedContainerConfig.Height,
|
||||||
|
extendedContainerConfig
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
mainContainerConfig = GetDefaultContainerProps(
|
||||||
|
configuration.MainContainer.Type,
|
||||||
|
0,
|
||||||
|
null,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
configuration.MainContainer.Width,
|
||||||
|
configuration.MainContainer.Height,
|
||||||
|
configuration.MainContainer
|
||||||
|
);
|
||||||
|
}
|
||||||
const mainContainer = new ContainerModel(
|
const mainContainer = new ContainerModel(
|
||||||
null,
|
null,
|
||||||
{
|
mainContainerConfig
|
||||||
...DEFAULT_MAINCONTAINER_PROPS,
|
|
||||||
width: Number(configuration.MainContainer.Width),
|
|
||||||
height: Number(configuration.MainContainer.Height)
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const typeCounters = {};
|
||||||
|
(typeCounters as any)[mainContainer.properties.type] = 0;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
configuration,
|
configuration,
|
||||||
history: [
|
history: [
|
||||||
|
@ -69,7 +124,7 @@ export function GetDefaultEditorState(configuration: IConfiguration): IEditorSta
|
||||||
lastAction: '',
|
lastAction: '',
|
||||||
mainContainer,
|
mainContainer,
|
||||||
selectedContainerId: mainContainer.properties.id,
|
selectedContainerId: mainContainer.properties.id,
|
||||||
typeCounters: {},
|
typeCounters,
|
||||||
symbols: new Map(),
|
symbols: new Map(),
|
||||||
selectedSymbolId: ''
|
selectedSymbolId: ''
|
||||||
}
|
}
|
||||||
|
@ -152,7 +207,7 @@ export const DEFAULT_MAINCONTAINER_PROPS: IContainerProperties = {
|
||||||
*/
|
*/
|
||||||
export function GetDefaultContainerProps(type: string,
|
export function GetDefaultContainerProps(type: string,
|
||||||
typeCount: number,
|
typeCount: number,
|
||||||
parent: IContainerModel,
|
parent: IContainerModel | undefined | null,
|
||||||
x: number,
|
x: number,
|
||||||
y: number,
|
y: number,
|
||||||
width: number,
|
width: number,
|
||||||
|
@ -161,7 +216,7 @@ export function GetDefaultContainerProps(type: string,
|
||||||
return ({
|
return ({
|
||||||
id: `${type}-${typeCount}`,
|
id: `${type}-${typeCount}`,
|
||||||
type,
|
type,
|
||||||
parentId: parent.properties.id,
|
parentId: parent?.properties.id ?? '',
|
||||||
linkedSymbolId: '',
|
linkedSymbolId: '',
|
||||||
displayedText: `${containerConfig.DisplayedText ?? type}-${typeCount}`,
|
displayedText: `${containerConfig.DisplayedText ?? type}-${typeCount}`,
|
||||||
x,
|
x,
|
||||||
|
|
|
@ -83,8 +83,6 @@ const GetSVGLayoutConfiguration = () => {
|
||||||
{
|
{
|
||||||
Type: 'Trou',
|
Type: 'Trou',
|
||||||
Blacklist: ["Chassis"],
|
Blacklist: ["Chassis"],
|
||||||
DefaultX: 0,
|
|
||||||
DefaultY: 0,
|
|
||||||
Margin: {
|
Margin: {
|
||||||
left: 10,
|
left: 10,
|
||||||
bottom: 10,
|
bottom: 10,
|
||||||
|
@ -112,10 +110,14 @@ const GetSVGLayoutConfiguration = () => {
|
||||||
,
|
,
|
||||||
Actions: [
|
Actions: [
|
||||||
{
|
{
|
||||||
|
Id: "SplitRemplissage",
|
||||||
Action: "SplitRemplissage",
|
Action: "SplitRemplissage",
|
||||||
Label: "Diviser le remplissage",
|
Label: "Diviser le remplissage",
|
||||||
Description: "Diviser le remplissage en insérant un montant",
|
Description: "Diviser le remplissage en insérant un montant",
|
||||||
CustomLogo: {
|
CustomLogo: {
|
||||||
|
Base64Image: null,
|
||||||
|
Name: 'Image1',
|
||||||
|
Svg: null,
|
||||||
Url: ""
|
Url: ""
|
||||||
},
|
},
|
||||||
AddingBehavior: 2
|
AddingBehavior: 2
|
||||||
|
@ -186,7 +188,7 @@ const GetSVGLayoutConfiguration = () => {
|
||||||
Height: 32,
|
Height: 32,
|
||||||
Image: {
|
Image: {
|
||||||
Base64Image: null,
|
Base64Image: null,
|
||||||
Name: null,
|
Name: 'Image1',
|
||||||
Svg: null,
|
Svg: null,
|
||||||
Url: 'https://www.manutan.fr/img/S/GRP/ST/AIG3930272.jpg'
|
Url: 'https://www.manutan.fr/img/S/GRP/ST/AIG3930272.jpg'
|
||||||
},
|
},
|
||||||
|
@ -198,7 +200,7 @@ const GetSVGLayoutConfiguration = () => {
|
||||||
Height: 32,
|
Height: 32,
|
||||||
Image: {
|
Image: {
|
||||||
Base64Image: null,
|
Base64Image: null,
|
||||||
Name: null,
|
Name: 'Image2',
|
||||||
Svg: null,
|
Svg: null,
|
||||||
Url: 'https://e7.pngegg.com/pngimages/647/127/png-clipart-svg-working-group-information-world-wide-web-internet-structure.png'
|
Url: 'https://e7.pngegg.com/pngimages/647/127/png-clipart-svg-working-group-information-world-wide-web-internet-structure.png'
|
||||||
},
|
},
|
||||||
|
@ -216,11 +218,13 @@ const GetSVGLayoutConfiguration = () => {
|
||||||
DisplayedText: "Stuff not made here"
|
DisplayedText: "Stuff not made here"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
Patterns: [],
|
||||||
MainContainer: {
|
MainContainer: {
|
||||||
Height: 200,
|
Type: 'main',
|
||||||
Width: 800
|
Width: 800,
|
||||||
|
Height: 200
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const FillHoleWithChassis = (request) => {
|
const FillHoleWithChassis = (request) => {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import http from 'http';
|
||||||
const host = 'localhost';
|
const host = 'localhost';
|
||||||
const port = 5000;
|
const port = 5000;
|
||||||
|
|
||||||
const requestListener = async(request, response) => {
|
const requestListener = async (request, response) => {
|
||||||
response.setHeader('Access-Control-Allow-Origin', '*');
|
response.setHeader('Access-Control-Allow-Origin', '*');
|
||||||
response.setHeader('Access-Control-Allow-Headers', '*');
|
response.setHeader('Access-Control-Allow-Headers', '*');
|
||||||
response.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
response.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
||||||
|
@ -81,7 +81,6 @@ const GetSVGLayoutConfiguration = () => {
|
||||||
stroke: 'red',
|
stroke: 'red',
|
||||||
fill: '#d3c9b7',
|
fill: '#d3c9b7',
|
||||||
},
|
},
|
||||||
HideChildrenInTreeview: true,
|
|
||||||
ShowSelfDimensions: true,
|
ShowSelfDimensions: true,
|
||||||
IsDimensionBorrower: true,
|
IsDimensionBorrower: true,
|
||||||
Category: "Stuff"
|
Category: "Stuff"
|
||||||
|
@ -89,8 +88,6 @@ const GetSVGLayoutConfiguration = () => {
|
||||||
{
|
{
|
||||||
Type: 'Trou',
|
Type: 'Trou',
|
||||||
Blacklist: ["Chassis"],
|
Blacklist: ["Chassis"],
|
||||||
DefaultX: 0,
|
|
||||||
DefaultY: 0,
|
|
||||||
Margin: {
|
Margin: {
|
||||||
left: 10,
|
left: 10,
|
||||||
bottom: 10,
|
bottom: 10,
|
||||||
|
@ -118,10 +115,14 @@ const GetSVGLayoutConfiguration = () => {
|
||||||
,
|
,
|
||||||
Actions: [
|
Actions: [
|
||||||
{
|
{
|
||||||
|
Id: "SplitRemplissage",
|
||||||
Action: "SplitRemplissage",
|
Action: "SplitRemplissage",
|
||||||
Label: "Diviser le remplissage",
|
Label: "Diviser le remplissage",
|
||||||
Description: "Diviser le remplissage en insérant un montant",
|
Description: "Diviser le remplissage en insérant un montant",
|
||||||
CustomLogo: {
|
CustomLogo: {
|
||||||
|
Base64Image: null,
|
||||||
|
Name: 'Image1',
|
||||||
|
Svg: null,
|
||||||
Url: ""
|
Url: ""
|
||||||
},
|
},
|
||||||
AddingBehavior: 2
|
AddingBehavior: 2
|
||||||
|
@ -192,7 +193,7 @@ const GetSVGLayoutConfiguration = () => {
|
||||||
Height: 32,
|
Height: 32,
|
||||||
Image: {
|
Image: {
|
||||||
Base64Image: null,
|
Base64Image: null,
|
||||||
Name: null,
|
Name: 'Image1',
|
||||||
Svg: null,
|
Svg: null,
|
||||||
Url: 'https://www.manutan.fr/img/S/GRP/ST/AIG3930272.jpg'
|
Url: 'https://www.manutan.fr/img/S/GRP/ST/AIG3930272.jpg'
|
||||||
},
|
},
|
||||||
|
@ -204,7 +205,7 @@ const GetSVGLayoutConfiguration = () => {
|
||||||
Height: 32,
|
Height: 32,
|
||||||
Image: {
|
Image: {
|
||||||
Base64Image: null,
|
Base64Image: null,
|
||||||
Name: null,
|
Name: 'Image2',
|
||||||
Svg: null,
|
Svg: null,
|
||||||
Url: 'https://e7.pngegg.com/pngimages/647/127/png-clipart-svg-working-group-information-world-wide-web-internet-structure.png'
|
Url: 'https://e7.pngegg.com/pngimages/647/127/png-clipart-svg-working-group-information-world-wide-web-internet-structure.png'
|
||||||
},
|
},
|
||||||
|
@ -222,11 +223,13 @@ const GetSVGLayoutConfiguration = () => {
|
||||||
DisplayedText: "Stuff not made here"
|
DisplayedText: "Stuff not made here"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
Patterns: [],
|
||||||
MainContainer: {
|
MainContainer: {
|
||||||
Height: 200,
|
Type: 'main',
|
||||||
Width: 800
|
Width: 800,
|
||||||
|
Height: 200
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const FillHoleWithChassis = (request) => {
|
const FillHoleWithChassis = (request) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue