mirror of
https://github.com/outline/outline.git
synced 2026-11-20 21:23:06 +03:00
The document container and editor exposed their measured widths as inherited CSS variables, so each frame of a width animation restyled every element in the document. Full width blocks now use a container unit, and media resizing measures the editor content width when it is needed.
21 lines
613 B
TypeScript
21 lines
613 B
TypeScript
/**
|
|
* Returns the width that blocks can fill in the editor that contains the
|
|
* element, which is the editor's width without its own padding.
|
|
*
|
|
* @param element an element in the editor, or the editor element itself.
|
|
* @returns the width in pixels, or Infinity when the element is not in an editor.
|
|
*/
|
|
export function contentWidth(element: Element): number {
|
|
const editor = element.closest(".ProseMirror");
|
|
if (!editor) {
|
|
return Infinity;
|
|
}
|
|
|
|
const style = getComputedStyle(editor);
|
|
return (
|
|
editor.clientWidth -
|
|
parseFloat(style.paddingLeft) -
|
|
parseFloat(style.paddingRight)
|
|
);
|
|
}
|