mirror of
https://github.com/outline/outline.git
synced 2026-11-26 07:33:19 +03:00
* fix: Allow PDF embed width and height to change independently Adds an aspect ratio lock toggle to the media dimension toolbar for PDF embeds, renders PDFs at their stored aspect ratio, and keeps that ratio when drag resizing. * feat: Add corner resize handles to PDF embeds and persist aspect ratio lock Stores the lock as an optional attachment attribute, where unset means locked, so side handles change only the width of unlocked PDFs. * feat: Consistent resize handles for images, videos, PDFs and embeds All media get side, bottom and corner handles driven by one lock rule. Images and videos stay locked. PDFs and embeds can be unlocked to resize each axis independently. * feat: Show width, height and lock in the embed toolbar * feat: Start embeds unlocked and step media dimensions with arrow keys Embeds start with an unlocked aspect ratio so full-width embeds can still be made taller, while PDFs start locked. Up and down arrows step the dimension inputs by 1, or 10 with shift. * fix: Align the aspect ratio padlock with the dimension digits * fix: Move the aspect ratio lock closer to the dimension inputs * fix: Show the aspect ratio lock state in its tooltip
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import type { NodeType } from "prosemirror-model";
|
|
import type { Command } from "prosemirror-state";
|
|
import { NodeSelection } from "prosemirror-state";
|
|
import {
|
|
isAspectRatioLocked,
|
|
isAspectRatioLockedByDefault,
|
|
} from "../queries/isAspectRatioLocked";
|
|
|
|
/**
|
|
* Toggles whether a selected node of the given type keeps its aspect ratio when
|
|
* resized. The attribute is cleared when the new state is the type default.
|
|
*
|
|
* @param type - the node type that stores the lock.
|
|
* @returns the command.
|
|
*/
|
|
export function toggleAspectRatioLock(type: NodeType): Command {
|
|
return (state, dispatch) => {
|
|
const { selection } = state;
|
|
if (!(selection instanceof NodeSelection) || selection.node.type !== type) {
|
|
return false;
|
|
}
|
|
|
|
const isLocked = !isAspectRatioLocked(selection.node);
|
|
const transaction = state.tr
|
|
.setNodeMarkup(selection.from, undefined, {
|
|
...selection.node.attrs,
|
|
lockAspectRatio:
|
|
isLocked === isAspectRatioLockedByDefault(type) ? null : isLocked,
|
|
})
|
|
.setMeta("addToHistory", true);
|
|
const $pos = transaction.doc.resolve(selection.from);
|
|
dispatch?.(transaction.setSelection(new NodeSelection($pos)));
|
|
return true;
|
|
};
|
|
}
|