From ad05a3cc25412efacf9488dbe7dd0cf67a7f60ab Mon Sep 17 00:00:00 2001 From: mathuo <6710312+mathuo@users.noreply.github.com> Date: Tue, 21 Mar 2023 17:24:06 +0100 Subject: [PATCH] chore: docs --- .../constraints-dockview/src/app.tsx | 121 ++++++++++++------ .../sandboxes/vanilla-dockview/package.json | 22 ++++ .../vanilla-dockview/public/index.html | 43 +++++++ .../sandboxes/vanilla-dockview/src/app.ts | 88 +++++++++++++ .../sandboxes/vanilla-dockview/src/index.ts | 10 ++ .../sandboxes/vanilla-dockview/src/styles.css | 16 +++ .../sandboxes/vanilla-dockview/tsconfig.json | 20 +++ 7 files changed, 283 insertions(+), 37 deletions(-) create mode 100644 packages/docs/sandboxes/vanilla-dockview/package.json create mode 100644 packages/docs/sandboxes/vanilla-dockview/public/index.html create mode 100644 packages/docs/sandboxes/vanilla-dockview/src/app.ts create mode 100644 packages/docs/sandboxes/vanilla-dockview/src/index.ts create mode 100644 packages/docs/sandboxes/vanilla-dockview/src/styles.css create mode 100644 packages/docs/sandboxes/vanilla-dockview/tsconfig.json diff --git a/packages/docs/sandboxes/constraints-dockview/src/app.tsx b/packages/docs/sandboxes/constraints-dockview/src/app.tsx index c8f6d51b4..0eda69d6c 100644 --- a/packages/docs/sandboxes/constraints-dockview/src/app.tsx +++ b/packages/docs/sandboxes/constraints-dockview/src/app.tsx @@ -9,41 +9,16 @@ import { import * as React from 'react'; const components = { - default: (props: IDockviewPanelProps<{ title: string }>) => { + default: (props: IDockviewPanelProps) => { const [contraints, setContraints] = React.useState(null); React.useEffect(() => { - props.api.group.api.setConstraints({ - maximumHeight: 200, - maximumWidth: 200, + props.api.group.api.onDidConstraintsChange((event) => { + setContraints(event); }); }, []); - React.useEffect(() => { - const disposable1 = new DockviewMutableDisposable(); - - const disposable = props.api.onDidGroupChange(() => { - disposable1.value = props.api.group.api.onDidConstraintsChange( - (event) => { - setContraints(event); - } - ); - }); - - setContraints({ - maximumHeight: props.api.group.maximumHeight, - minimumHeight: props.api.group.minimumHeight, - maximumWidth: props.api.group.maximumWidth, - minimumWidth: props.api.group.minimumWidth, - }); - - return () => { - disposable1.dispose(); - disposable.dispose(); - }; - }, []); - return (
- {props.params.title} {contraints && ( -
-
{`minHeight=${contraints.minimumHeight}`}
-
{`maxHeight=${contraints.maximumHeight}`}
-
{`minWidth=${contraints.minimumWidth}`}
-
{`maxWidth=${contraints.maximumWidth}`}
+
+ {typeof contraints.maximumHeight === 'number' && ( +
+ {`Maximum Height: `} + {`${contraints.maximumHeight}px`} +
+ )} + {typeof contraints.minimumHeight === 'number' && ( +
+ {`Minimum Height: `} + {`${contraints.minimumHeight}px`} +
+ )} + {typeof contraints.maximumWidth === 'number' && ( +
+ {`Maximum Width: `} + {`${contraints.maximumWidth}px`} +
+ )} + {typeof contraints.minimumWidth === 'number' && ( +
+ {`Minimum Width: `} + {`${contraints.minimumWidth}px`} +
+ )}
)}
@@ -71,19 +97,40 @@ const App = () => { const [api, setApi] = React.useState(); const onReady = (event: DockviewReadyEvent) => { - const panel = event.api.addPanel({ + const panel1 = event.api.addPanel({ id: 'panel_1', component: 'default', }); - event.api.addPanel({ + const panel2 = event.api.addPanel({ id: 'panel_2', component: 'default', + position: { + referencePanel: panel1, + direction: 'right', + }, }); - event.api.addPanel({ + const panel3 = event.api.addPanel({ id: 'panel_3', component: 'default', + position: { + referencePanel: panel2, + direction: 'right', + }, + }); + + const panel4 = event.api.addPanel({ + id: 'panel_4', + component: 'default', + position: { + direction: 'below', + }, + }); + + panel2.api.group.api.setConstraints({ + maximumWidth: 300, + maximumHeight: 300, }); }; diff --git a/packages/docs/sandboxes/vanilla-dockview/package.json b/packages/docs/sandboxes/vanilla-dockview/package.json new file mode 100644 index 000000000..b6bf01665 --- /dev/null +++ b/packages/docs/sandboxes/vanilla-dockview/package.json @@ -0,0 +1,22 @@ +{ + "name": "vanilla-dockview", + "description": "", + "keywords": [ + "dockview" + ], + "version": "1.0.0", + "main": "src/index.ts", + "dependencies": { + "dockview-core": "*" + }, + "devDependencies": { + "typescript": "^4.9.5" + }, + "scripts": {}, + "browserslist": [ + ">0.2%", + "not dead", + "not ie <= 11", + "not op_mini all" + ] +} \ No newline at end of file diff --git a/packages/docs/sandboxes/vanilla-dockview/public/index.html b/packages/docs/sandboxes/vanilla-dockview/public/index.html new file mode 100644 index 000000000..67c682336 --- /dev/null +++ b/packages/docs/sandboxes/vanilla-dockview/public/index.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + React App + + + + +
+ + + + diff --git a/packages/docs/sandboxes/vanilla-dockview/src/app.ts b/packages/docs/sandboxes/vanilla-dockview/src/app.ts new file mode 100644 index 000000000..b7ffbe53d --- /dev/null +++ b/packages/docs/sandboxes/vanilla-dockview/src/app.ts @@ -0,0 +1,88 @@ +import { + DockviewComponent, + IContentRenderer, + IGroupPanelInitParameters, +} from 'dockview'; + +class DefaultPanel implements IContentRenderer { + private _element: HTMLElement; + + get element(): HTMLElement { + return this._element; + } + + constructor() { + this._element = document.createElement('div'); + } + + init(params: IGroupPanelInitParameters): void { + // + } +} + +export function attach(parent: HTMLElement): { + dispose: () => void; +} { + const element = document.createElement('div'); + element.className = 'dockview-theme-abyss'; + parent.appendChild(element); + + const dockview = new DockviewComponent(element, { + components: { + default: DefaultPanel, + }, + }); + + const observer = new ResizeObserver((entires) => { + const firstEntry = entires[0]; + + const { width, height } = firstEntry.contentRect; + dockview.layout(width, height); + }); + + observer.observe(parent); + + const panel1 = dockview.addPanel({ + id: 'panel_1', + title: 'Panel 1', + component: 'default', + }); + + const panel2 = dockview.addPanel({ + id: 'panel_2', + title: 'Panel 2', + component: 'default', + position: { + referencePanel: panel1, + direction: 'right', + }, + }); + + const panel3 = dockview.addPanel({ + id: 'panel_3', + title: 'Panel 3', + component: 'default', + position: { + referenceGroup: panel2.group, + }, + }); + + const pane4 = dockview.addPanel({ + id: 'panel_4', + title: 'Panel 4', + component: 'default', + position: { + direction: 'below', + }, + }); + + return { + dispose: () => { + observer.unobserve(element); + observer.disconnect(); + + dockview.dispose(); + element.remove(); + }, + }; +} diff --git a/packages/docs/sandboxes/vanilla-dockview/src/index.ts b/packages/docs/sandboxes/vanilla-dockview/src/index.ts new file mode 100644 index 000000000..a1bf270a5 --- /dev/null +++ b/packages/docs/sandboxes/vanilla-dockview/src/index.ts @@ -0,0 +1,10 @@ +import './styles.css'; +import 'dockview/dist/styles/dockview.css'; + +import { attach } from './app'; + +const rootElement = document.getElementById('root'); + +if (rootElement) { + attach(rootElement); +} diff --git a/packages/docs/sandboxes/vanilla-dockview/src/styles.css b/packages/docs/sandboxes/vanilla-dockview/src/styles.css new file mode 100644 index 000000000..92b6a1b36 --- /dev/null +++ b/packages/docs/sandboxes/vanilla-dockview/src/styles.css @@ -0,0 +1,16 @@ +body { + margin: 0px; + color: white; + font-family: sans-serif; + text-align: center; +} + +#root { + height: 100vh; + width: 100vw; +} + +.app { + height: 100%; + +} diff --git a/packages/docs/sandboxes/vanilla-dockview/tsconfig.json b/packages/docs/sandboxes/vanilla-dockview/tsconfig.json new file mode 100644 index 000000000..6e13e47b5 --- /dev/null +++ b/packages/docs/sandboxes/vanilla-dockview/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "outDir": "build/dist", + "module": "esnext", + "target": "es5", + "lib": ["es6", "dom"], + "sourceMap": true, + "allowJs": true, + "jsx": "react-jsx", + "moduleResolution": "node", + "rootDir": "src", + "forceConsistentCasingInFileNames": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noImplicitAny": true, + "strictNullChecks": true, + "suppressImplicitAnyIndexErrors": true, + "noUnusedLocals": true + } +}