mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-11 15:34:37 +08:00
Amplify Output button increases vertical size
This commit is contained in:
parent
24efee3b82
commit
68f57c00fe
3 changed files with 46 additions and 1 deletions
|
@ -2,6 +2,7 @@ import HyperList from "hyperlist";
|
||||||
import { parseHookProps } from "../lib/attribute";
|
import { parseHookProps } from "../lib/attribute";
|
||||||
import {
|
import {
|
||||||
findChildOrThrow,
|
findChildOrThrow,
|
||||||
|
findClosestOrThrow,
|
||||||
getLineHeight,
|
getLineHeight,
|
||||||
isScrolledToEnd,
|
isScrolledToEnd,
|
||||||
scrollToEnd,
|
scrollToEnd,
|
||||||
|
@ -16,6 +17,10 @@ import {
|
||||||
* * `max-height` - the maximum height of the element, exceeding
|
* * `max-height` - the maximum height of the element, exceeding
|
||||||
* this height enables scrolling
|
* this height enables scrolling
|
||||||
*
|
*
|
||||||
|
* * `max-height-amplified` - the maximum height of the element
|
||||||
|
* when "Amplify Output" is selected in the UI, exceeding this
|
||||||
|
* height enables scrolling when selected
|
||||||
|
*
|
||||||
* * `follow` - whether to automatically scroll to the bottom as
|
* * `follow` - whether to automatically scroll to the bottom as
|
||||||
* new lines appear
|
* new lines appear
|
||||||
*
|
*
|
||||||
|
@ -40,6 +45,9 @@ const VirtualizedLines = {
|
||||||
this.lineHeight = getLineHeight(this.el);
|
this.lineHeight = getLineHeight(this.el);
|
||||||
this.templateEl = findChildOrThrow(this.el, "[data-template]");
|
this.templateEl = findChildOrThrow(this.el, "[data-template]");
|
||||||
this.contentEl = findChildOrThrow(this.el, "[data-content]");
|
this.contentEl = findChildOrThrow(this.el, "[data-content]");
|
||||||
|
this.cellEl = findClosestOrThrow(this.el, "[data-el-cell]");
|
||||||
|
this.amplifyOutput = this.isAmplifyOutput();
|
||||||
|
this.amplifyObserver = this.newAmplifyObserver();
|
||||||
|
|
||||||
this.capLines();
|
this.capLines();
|
||||||
|
|
||||||
|
@ -67,9 +75,14 @@ const VirtualizedLines = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
destroyed() {
|
||||||
|
this.amplifyObserver.disconnect();
|
||||||
|
},
|
||||||
|
|
||||||
getProps() {
|
getProps() {
|
||||||
return parseHookProps(this.el, [
|
return parseHookProps(this.el, [
|
||||||
"max-height",
|
"max-height",
|
||||||
|
"max-height-amplified",
|
||||||
"follow",
|
"follow",
|
||||||
"max-lines",
|
"max-lines",
|
||||||
"ignore-trailing-empty-line",
|
"ignore-trailing-empty-line",
|
||||||
|
@ -81,7 +94,7 @@ const VirtualizedLines = {
|
||||||
const numberOfLines = lineEls.length;
|
const numberOfLines = lineEls.length;
|
||||||
|
|
||||||
const height = Math.min(
|
const height = Math.min(
|
||||||
this.props.maxHeight,
|
this.amplifyOutput ? this.props.maxHeightAmplified : this.props.maxHeight,
|
||||||
this.lineHeight * numberOfLines,
|
this.lineHeight * numberOfLines,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -139,6 +152,25 @@ const VirtualizedLines = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
newAmplifyObserver() {
|
||||||
|
const observer = new MutationObserver((mutationRecords) => {
|
||||||
|
if (
|
||||||
|
mutationRecords.length != 1 ||
|
||||||
|
mutationRecords[0].target != this.cellEl ||
|
||||||
|
mutationRecords[0].attributeName != "data-js-amplified"
|
||||||
|
) { throw new Error("unexpected mutation changing Amplify Output"); }
|
||||||
|
|
||||||
|
this.amplifyOutput = this.isAmplifyOutput();
|
||||||
|
this.updated();
|
||||||
|
});
|
||||||
|
observer.observe(this.cellEl, {attributeFilter: ["data-js-amplified"]});
|
||||||
|
return observer;
|
||||||
|
},
|
||||||
|
|
||||||
|
isAmplifyOutput() {
|
||||||
|
return (this.cellEl.getAttribute("data-js-amplified") != null);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default VirtualizedLines;
|
export default VirtualizedLines;
|
||||||
|
|
|
@ -241,6 +241,18 @@ export function findChildOrThrow(element, selector) {
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function findClosestOrThrow(element, selector) {
|
||||||
|
const closest = element.closest(selector);
|
||||||
|
|
||||||
|
if (!closest) {
|
||||||
|
throw new Error(
|
||||||
|
`expected closest matching ${selector}, but none was found`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return closest;
|
||||||
|
}
|
||||||
|
|
||||||
export function cancelEvent(event) {
|
export function cancelEvent(event) {
|
||||||
// Cancel any default browser behavior.
|
// Cancel any default browser behavior.
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
|
@ -64,6 +64,7 @@ defmodule LivebookWeb.Output.TerminalTextComponent do
|
||||||
class="relative group/root"
|
class="relative group/root"
|
||||||
phx-hook="VirtualizedLines"
|
phx-hook="VirtualizedLines"
|
||||||
data-p-max-height={hook_prop(300)}
|
data-p-max-height={hook_prop(300)}
|
||||||
|
data-p-max-height-amplified={hook_prop(600)}
|
||||||
data-p-follow={hook_prop(true)}
|
data-p-follow={hook_prop(true)}
|
||||||
data-p-max-lines={hook_prop(Livebook.Notebook.max_terminal_lines())}
|
data-p-max-lines={hook_prop(Livebook.Notebook.max_terminal_lines())}
|
||||||
data-p-ignore-trailing-empty-line={hook_prop(true)}
|
data-p-ignore-trailing-empty-line={hook_prop(true)}
|
||||||
|
|
Loading…
Add table
Reference in a new issue