Skip to content

Commit

Permalink
0.2.3 - Hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Elschnagoo committed Jul 23, 2023
1 parent 2ac2d91 commit 231af52
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change log
All notable changes to this project will be documented in this file.

## [0.2.3]
### Added
- Add i18 interface for components
- Add UIContext to override Component portal root and set Translations
- Extend TabLayout Functions
- Webpack Hotfix
## [0.2.1]
### Added
- Add required field validation to form event
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grandlinex/react-components",
"version": "0.2.2",
"version": "0.2.3",
"private": false,
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
5 changes: 4 additions & 1 deletion src/renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createRoot } from 'react-dom/client';
import { Default as test } from './stories/components/PortalStepper.stories';
import PortalStepper from './components/controlls/PortalStepper/PortalStepper';
import { GLang, UIContext, UIContextData, useUIContext } from './util';
import Tooltip from './components/tooltip/Tooltip';

const root = createRoot(document.getElementById('root')!);

Expand All @@ -16,7 +17,9 @@ const App = () => {

return (
<div>
{ui.translation.get('test.translation')}
<Tooltip text="HelloWorld">
{ui.translation.get('test.translation')}
</Tooltip>
<PortalStepper {...(test.args as any)} />
</div>
);
Expand Down
12 changes: 12 additions & 0 deletions src/util/BuildHelper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Helper function to get the window object. Fix for webpack build.
*/
export default function getSaveWindow() {
return typeof window !== 'undefined'
? window
: ({
document: {
body: {},
},
} as unknown as Window);
}
6 changes: 4 additions & 2 deletions src/util/GLang.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import getSaveWindow from './BuildHelper';

export interface LangDataDataElement {
key: string;
value: string;
Expand All @@ -18,7 +20,7 @@ export class GLang {
if (langDat) {
this.loadLang(langDat);
}
const win = window as any;
const win = getSaveWindow() as any;
if (win && !win.missingTrans) {
win.missingTrans = new Set<string>();
win.getMissingTrans = () => {
Expand All @@ -33,7 +35,7 @@ export class GLang {
}

getMissingSet() {
const win = window as any;
const win = getSaveWindow() as any;
if (win && win.missingTrans) {
return win.missingTrans as Set<string>;
}
Expand Down
3 changes: 2 additions & 1 deletion src/util/MainContext.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useContext } from 'react';
import { GLang } from './GLang';
import getSaveWindow from './BuildHelper';

class UIContextData {
portalRoot: HTMLElement;
Expand All @@ -14,7 +15,7 @@ class UIContextData {

const UIContext = React.createContext(
new UIContextData({
portalRoot: document.body,
portalRoot: getSaveWindow().document.body,
lang: new GLang({
label: 'DefaultEnglish',
code: 'en',
Expand Down
3 changes: 2 additions & 1 deletion src/util/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { ReactNode } from 'react';
import md5 from './MD5';
import copyToClipboard from './Clipboard';
import getSaveWindow from './BuildHelper';

export * from './GLang';
export * from './MainContext';
Expand Down Expand Up @@ -86,4 +87,4 @@ function loop<X = ReactNode>(
return arr;
}

export { md5, copyToClipboard, sGen, loop };
export { md5, copyToClipboard, sGen, loop, getSaveWindow };

0 comments on commit 231af52

Please sign in to comment.