checkpoint, simplerender should send onHeightChange events

This commit is contained in:
sawka 2023-03-17 10:11:38 -07:00
parent 7a1166b2fa
commit ac1bba94d9
3 changed files with 33 additions and 25 deletions

View File

@ -531,7 +531,7 @@ class LineCmd extends React.Component<{screen : LineContainerModel, line : LineT
<TerminalRenderer screen={screen} line={line} width={width} staticRender={staticRender} visible={visible} onHeightChange={this.handleHeightChange} collapsed={isCollapsed}/>
</If>
<If condition={rendererPlugin != null}>
<SimpleBlobRenderer lcm={screen} line={line} cmd={cmd} plugin={rendererPlugin}/>
<SimpleBlobRenderer lcm={screen} line={line} cmd={cmd} plugin={rendererPlugin} onHeightChange={this.handleHeightChange}/>
</If>
<If condition={!isCollapsed && cmd.getRtnState()}>
<div key="rtnstate" className="cmd-rtnstate" style={{visibility: ((cmd.getStatus() == "done") ? "visible" : "hidden")}}>

View File

@ -52,6 +52,7 @@ class SimpleBlobRendererModel {
if (this.savedHeight != newHeight) {
this.savedHeight = newHeight;
this.api.saveHeight(newHeight);
console.log("saveheight", sprintf("[%d]", this.context.lineNum), newHeight);
}
}
@ -118,9 +119,10 @@ function apiAdapter(lcm : LineContainerModel, line : LineType, cmd : Cmd) : Rend
}
@mobxReact.observer
class SimpleBlobRenderer extends React.Component<{lcm : LineContainerModel, line : LineType, cmd : Cmd, plugin : RendererPluginType}, {}> {
class SimpleBlobRenderer extends React.Component<{lcm : LineContainerModel, line : LineType, cmd : Cmd, plugin : RendererPluginType, onHeightChange : () => void}, {}> {
model : SimpleBlobRendererModel;
wrapperDivRef : React.RefObject<any> = React.createRef();
rszObs : ResizeObserver;
constructor(props : any) {
super(props);
@ -151,27 +153,44 @@ class SimpleBlobRenderer extends React.Component<{lcm : LineContainerModel, line
this.model.initialize(initOpts);
lcm.registerRenderer(line.cmdid, this.model);
}
handleResize(entries : ResizeObserverEntry[]) : void {
console.log("simplerender resize", sprintf("[%d]", this.model.context.lineNum), entries);
if (this.props.onHeightChange) {
this.props.onHeightChange();
}
if (!this.model.loading.get() && this.wrapperDivRef.current != null) {
let height = this.wrapperDivRef.current.offsetHeight;
this.model.updateHeight(height);
}
}
checkRszObs() {
if (this.rszObs != null) {
return;
}
if (this.wrapperDivRef.current == null) {
return;
}
this.rszObs = new ResizeObserver(this.handleResize.bind(this));
this.rszObs.observe(this.wrapperDivRef.current);
}
componentDidMount() {
this.checkHeight();
this.checkRszObs();
}
componentWillUnmount() {
let {lcm, line} = this.props;
lcm.unloadRenderer(line.cmdid);
if (this.rszObs != null) {
this.rszObs.disconnect();
this.rszObs = null;
}
}
componentDidUpdate() {
this.checkHeight();
}
checkHeight() : void {
// TODO: use resizeobserver instead of ref.
if (this.wrapperDivRef.current == null) {
return;
}
let height = this.wrapperDivRef.current.offsetHeight;
this.model.updateHeight(height);
this.checkRszObs();
}
render() {
@ -179,7 +198,7 @@ class SimpleBlobRenderer extends React.Component<{lcm : LineContainerModel, line
let model = this.model;
if (model.loading.get()) {
let height = this.model.savedHeight;
return (<div style={{minHeight: height}}>...</div>);
return (<div ref={this.wrapperDivRef} style={{minHeight: height}}>...</div>);
}
let Comp = plugin.component;
let dataBlob = new Blob([model.ptyData.data]);

View File

@ -405,17 +405,6 @@ type SimpleBlobRendererComponent = React.ComponentType<{data : Blob, context : R
type SimpleJsonRendererComponent = React.ComponentType<{data : any, context : RendererContext, opts : RendererOpts}>;
type FullRendererComponent = React.ComponentType<{model : any}>;
type OldRendererModel = {
dispose : () => void,
reload : (delayMs : number) => void,
receiveData : (pos : number, data : Uint8Array, reason? : string) => void,
cmdDone : () => void,
resizeWindow : (size : WindowSize) => void,
resizeCols : (cols : number) => void,
giveFocus : () => void,
getUsedRows : () => number,
};
type WindowSize = {
height : number,
width: number,