Migrate global to globalThis

This commit is contained in:
Paulo Gustavo Veiga 2022-10-30 23:10:39 -07:00
parent e639dd7202
commit dbfed09f3a
7 changed files with 26 additions and 16 deletions

View File

@ -2,3 +2,13 @@ declare module '*.svg' {
const content: any; const content: any;
export default content; export default content;
} }
// @Hack: This should not be here ....
declare global {
const isAuth: boolean;
const mapId: number;
const historyId: number;
const userOptions: { zoom: string | number } | null;
const mindmapLocked: boolean;
const mindmapLockedMsg: string;
const mapTitle: string;
}

View File

@ -133,7 +133,7 @@ class Designer extends Events {
this._clipboard = []; this._clipboard = [];
// Hack: There are static reference to designer variable. Needs to be reviewed. // Hack: There are static reference to designer variable. Needs to be reviewed.
global.designer = this; globalThis.designer = this;
} }
private _registerWheelEvents(): void { private _registerWheelEvents(): void {

View File

@ -29,9 +29,9 @@ globalAny.jQuery = jquery;
// WebComponent registration // WebComponent registration
customElements.define('mindplot-component', MindplotWebComponent); customElements.define('mindplot-component', MindplotWebComponent);
// Configure designer options ... // Configure designer options ...
const historyId = global.historyId ? `${global.historyId}/` : ''; const historyId = globalThis.historyId ? `${globalThis.historyId}/` : '';
const persistence: PersistenceManager = new LocalStorageManager( const persistence: PersistenceManager = new LocalStorageManager(
`/c/restful/maps/{id}/${historyId}document/xml${!global.isAuth ? '-pub' : ''}`, `/c/restful/maps/{id}/${historyId}document/xml${!globalThis.isAuth ? '-pub' : ''}`,
true, true,
); );
@ -39,4 +39,4 @@ const webComponent: MindplotWebComponent = document.getElementById(
'mindmap-comp', 'mindmap-comp',
) as MindplotWebComponent; ) as MindplotWebComponent;
webComponent.buildDesigner(persistence); webComponent.buildDesigner(persistence);
webComponent.loadMap(global.mapId); webComponent.loadMap(globalThis.mapId);

View File

@ -13,12 +13,12 @@ class EditorOptionsBuilder {
if (!AppConfig.isDevelopEnv()) { if (!AppConfig.isDevelopEnv()) {
options = { options = {
zoom: zoom:
global.userOptions?.zoom != undefined globalThis.userOptions?.zoom != undefined
? Number.parseFloat(global?.userOptions?.zoom as string) ? Number.parseFloat(globalThis?.userOptions?.zoom as string)
: 0.8, : 0.8,
locked: global.mindmapLocked, locked: globalThis.mindmapLocked,
lockedMsg: global.mindmapLockedMsg, lockedMsg: globalThis.mindmapLockedMsg,
mapTitle: global.mapTitle, mapTitle: globalThis.mapTitle,
...options, ...options,
}; };
} else { } else {
@ -35,10 +35,10 @@ class EditorOptionsBuilder {
} }
static loadMapId(): number { static loadMapId(): number {
const result = !AppConfig.isDevelopEnv() ? global.mapId : 11; const result = !AppConfig.isDevelopEnv() ? globalThis.mapId : 11;
if (result === undefined) { if (result === undefined) {
throw Error( throw Error(
`Could not resolve mapId. Map Id: global.mapId: ${result} , global.mapTitle: ${global.mapTitle}, global.lockSession: ${global.lockSession}`, `Could not resolve mapId. Map Id: globalThis.mapId: ${result} , globalThis.mapTitle: ${globalThis.mapTitle}, globalThis.lockSession: ${globalThis.lockSession}`,
); );
} }
return result; return result;

View File

@ -20,9 +20,9 @@ export const buildPersistenceManagerForEditor = (mode: string): PersistenceManag
}); });
} else { } else {
persistenceManager = new LocalStorageManager( persistenceManager = new LocalStorageManager(
`/c/restful/maps/{id}/${global.historyId ? `${global.historyId}/` : ''}document/xml${ `/c/restful/maps/{id}/${
mode === 'showcase' ? '-pub' : '' globalThis.historyId ? `${globalThis.historyId}/` : ''
}`, }document/xml${mode === 'showcase' ? '-pub' : ''}`,
true, true,
); );
} }

View File

@ -54,7 +54,7 @@ const EditorPage = ({ isTryMode }: EditorPropsType): React.ReactElement => {
let result: EditorRenderMode = null; let result: EditorRenderMode = null;
if (isTryMode) { if (isTryMode) {
result = 'showcase'; result = 'showcase';
} else if (global.mindmapLocked) { } else if (globalThis.mindmapLocked) {
result = 'viewonly'; result = 'viewonly';
} else { } else {
const fetchResult = useFetchMapById(mapId); const fetchResult = useFetchMapById(mapId);

View File

@ -92,7 +92,7 @@ const ExportDialog = ({
let size: SizeType; let size: SizeType;
let mindmap: Mindmap; let mindmap: Mindmap;
const designer: Designer = global.designer; const designer: Designer = globalThis.designer;
// exporting from editor toolbar action // exporting from editor toolbar action
if (designer != null) { if (designer != null) {
// Depending on the type of export. It will require differt POST. // Depending on the type of export. It will require differt POST.