@tcn/ui-layout
Advanced tools
Comparing version 0.3.16 to 0.3.19
@@ -10,3 +10,2 @@ /// <reference types="react" /> | ||
export * from './stacks/z_stack.js'; | ||
export * from './accordion/accordion.js'; | ||
export * from './grid.js'; | ||
@@ -13,0 +12,0 @@ export * from './list.js'; |
@@ -9,3 +9,2 @@ export * from './pad.js'; | ||
export * from './stacks/z_stack.js'; | ||
export * from './accordion/accordion.js'; | ||
export * from './grid.js'; | ||
@@ -12,0 +11,0 @@ export * from './list.js'; |
@@ -14,4 +14,5 @@ import React from 'react'; | ||
private _portals; | ||
readonly platformDiv: HTMLDivElement; | ||
readonly platformRoot: HTMLDivElement; | ||
constructor(win?: Window & typeof globalThis, root?: HTMLElement); | ||
private _getPlatformRoot; | ||
setZIndex(zIndex?: number | string): void; | ||
@@ -18,0 +19,0 @@ setRoot(root: HTMLElement | null): void; |
@@ -31,13 +31,23 @@ import React from 'react'; | ||
_portals = []; | ||
platformDiv; | ||
platformRoot; | ||
constructor(win = window, root = win.document.body) { | ||
this._window = win; | ||
this._root = root; | ||
this.platformDiv = document.createElement('div'); | ||
const reactRoot = ReactDOM.createRoot(this.platformDiv); | ||
this.platformRoot = this._getPlatformRoot(); | ||
this.platformRoot.classList.add('platform-root'); | ||
const reactRoot = ReactDOM.createRoot(this.platformRoot); | ||
reactRoot.render(React.createElement(Platform, null)); | ||
} | ||
_getPlatformRoot() { | ||
const existingPlatformRoot = this._window.document.body.querySelector('.platform-root'); | ||
if (!existingPlatformRoot) { | ||
return this._window.document.createElement('div'); | ||
} | ||
else { | ||
return existingPlatformRoot; | ||
} | ||
} | ||
setZIndex(zIndex = 'auto') { | ||
if (this.platformDiv != null) { | ||
this.platformDiv.style.zIndex = zIndex.toString(); | ||
if (this.platformRoot != null) { | ||
this.platformRoot.style.zIndex = zIndex.toString(); | ||
} | ||
@@ -47,3 +57,3 @@ } | ||
if (root !== this._root) { | ||
this.platformDiv?.parentNode?.removeChild(this.platformDiv); | ||
this.platformRoot?.parentNode?.removeChild(this.platformRoot); | ||
this._root = root == null ? document.body : root; | ||
@@ -56,3 +66,3 @@ this.showPlatform(); | ||
this._portals.push(portal); | ||
this.platformDiv.firstElementChild?.appendChild(portal.div); | ||
this.platformRoot.firstElementChild?.appendChild(portal.div); | ||
this.showPlatform(); | ||
@@ -72,3 +82,3 @@ return portal; | ||
this._portals.splice(index, 1); | ||
this.platformDiv.firstElementChild?.removeChild(portal.div); | ||
this.platformRoot.firstElementChild?.removeChild(portal.div); | ||
this.hidePlatformIfNecessary(); | ||
@@ -78,14 +88,14 @@ } | ||
showPlatform() { | ||
if (this.platformDiv != null && this.platformDiv.parentElement == null) { | ||
this._root.appendChild(this.platformDiv); | ||
if (this.platformRoot != null && this.platformRoot.parentElement == null) { | ||
this._root.appendChild(this.platformRoot); | ||
} | ||
} | ||
hidePlatformIfNecessary() { | ||
if (this._portals.length === 0 && this.platformDiv.parentElement != null) { | ||
this._root.removeChild(this.platformDiv); | ||
if (this._portals.length === 0 && this.platformRoot.parentElement != null) { | ||
this._root.removeChild(this.platformRoot); | ||
} | ||
} | ||
dispose() { | ||
if (this.platformDiv != null && this._root.contains(this.platformDiv)) { | ||
this._root.removeChild(this.platformDiv); | ||
if (this.platformRoot != null && this._root.contains(this.platformRoot)) { | ||
this._root.removeChild(this.platformRoot); | ||
} | ||
@@ -92,0 +102,0 @@ } |
{ | ||
"name": "@tcn/ui-layout", | ||
"version": "0.3.16", | ||
"version": "0.3.19", | ||
"type": "module", | ||
@@ -49,3 +49,2 @@ "description": "TCN Layout.", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"classnames": "^2.5.1", | ||
"concurrently": "^8.2.2", | ||
@@ -66,4 +65,5 @@ "copyfiles": "^2.4.1", | ||
"@tcn/state": "^0.0.3", | ||
"@tcn/ui-core": "^0.4.1" | ||
"@tcn/ui-core": "^0.4.7", | ||
"classnames": "^2.5.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
28
221183
5
168
2935
+ Addedclassnames@^2.5.1
Updated@tcn/ui-core@^0.4.7