stickies: snap to grid experiment

pull/3133/head
Mime Čuvalo 2024-03-12 17:08:50 +00:00
rodzic b9547c2e6b
commit a200b16a8f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: BA84499022AC984D
7 zmienionych plików z 55 dodań i 3 usunięć

Wyświetl plik

@ -1602,6 +1602,8 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
canSnap: TLShapeUtilFlag<Shape>; canSnap: TLShapeUtilFlag<Shape>;
canUnmount: TLShapeUtilFlag<Shape>; canUnmount: TLShapeUtilFlag<Shape>;
abstract component(shape: Shape): any; abstract component(shape: Shape): any;
// @internal
doesAutoSnap: TLShapeUtilFlag<Shape>;
// (undocumented) // (undocumented)
editor: Editor; editor: Editor;
// @internal (undocumented) // @internal (undocumented)

Wyświetl plik

@ -131,6 +131,13 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
*/ */
canCrop: TLShapeUtilFlag<Shape> = () => false canCrop: TLShapeUtilFlag<Shape> = () => false
/**
* Whether the shape auto-snaps when translated or resized.
*
* @internal
*/
doesAutoSnap: TLShapeUtilFlag<Shape> = () => false
/** /**
* Does this shape provide a background for its children? If this is true, * Does this shape provide a background for its children? If this is true,
* then any children with a `renderBackground` method will have their * then any children with a `renderBackground` method will have their

Wyświetl plik

@ -1028,6 +1028,8 @@ export class NoteShapeUtil extends ShapeUtil<TLNoteShape> {
// (undocumented) // (undocumented)
component(shape: TLNoteShape): JSX_2.Element; component(shape: TLNoteShape): JSX_2.Element;
// (undocumented) // (undocumented)
doesAutoSnap: () => boolean;
// (undocumented)
getDefaultProps(): TLNoteShape['props']; getDefaultProps(): TLNoteShape['props'];
// (undocumented) // (undocumented)
getGeometry(shape: TLNoteShape): Rectangle2d; getGeometry(shape: TLNoteShape): Rectangle2d;

Wyświetl plik

@ -12239,6 +12239,36 @@
"isAbstract": false, "isAbstract": false,
"name": "component" "name": "component"
}, },
{
"kind": "Property",
"canonicalReference": "tldraw!NoteShapeUtil#doesAutoSnap:member",
"docComment": "",
"excerptTokens": [
{
"kind": "Content",
"text": "doesAutoSnap: "
},
{
"kind": "Content",
"text": "() => boolean"
},
{
"kind": "Content",
"text": ";"
}
],
"isReadonly": false,
"isOptional": false,
"releaseTag": "Public",
"name": "doesAutoSnap",
"propertyTypeTokenRange": {
"startIndex": 1,
"endIndex": 2
},
"isStatic": false,
"isProtected": false,
"isAbstract": false
},
{ {
"kind": "Method", "kind": "Method",
"canonicalReference": "tldraw!NoteShapeUtil#getDefaultProps:member(1)", "canonicalReference": "tldraw!NoteShapeUtil#getDefaultProps:member(1)",

Wyświetl plik

@ -27,6 +27,7 @@ export class NoteShapeUtil extends ShapeUtil<TLNoteShape> {
static override migrations = noteShapeMigrations static override migrations = noteShapeMigrations
override canEdit = () => true override canEdit = () => true
override doesAutoSnap = () => true
override hideResizeHandles = () => true override hideResizeHandles = () => true
override hideSelectionBoundsFg = () => true override hideSelectionBoundsFg = () => true

Wyświetl plik

@ -234,7 +234,14 @@ export class Resizing extends StateNode {
this.editor.snaps.clearIndicators() this.editor.snaps.clearIndicators()
const shouldSnap = this.editor.user.getIsSnapMode() ? !ctrlKey : ctrlKey const onlySelectedShape = this.editor.getOnlySelectedShape()
const shouldSnap =
this.editor.user.getIsSnapMode() ||
(onlySelectedShape && this.editor.getShapeUtil(onlySelectedShape))?.doesAutoSnap(
onlySelectedShape
)
? !ctrlKey
: ctrlKey
if (shouldSnap && selectionRotation % HALF_PI === 0) { if (shouldSnap && selectionRotation % HALF_PI === 0) {
const { nudge } = this.editor.snaps.shapeBounds.snapResizeShapes({ const { nudge } = this.editor.snaps.shapeBounds.snapResizeShapes({

Wyświetl plik

@ -398,10 +398,13 @@ export function moveShapesToPoint({
// Provisional snapping // Provisional snapping
editor.snaps.clearIndicators() editor.snaps.clearIndicators()
const onlySelectedShape = editor.getOnlySelectedShape()
const shouldSnap = const shouldSnap =
(editor.user.getIsSnapMode() ? !inputs.ctrlKey : inputs.ctrlKey) && (editor.user.getIsSnapMode() ||
editor.inputs.pointerVelocity.len() < 0.5 // ...and if the user is not dragging fast (onlySelectedShape && editor.getShapeUtil(onlySelectedShape))?.doesAutoSnap(onlySelectedShape)
? !inputs.ctrlKey
: inputs.ctrlKey) && editor.inputs.pointerVelocity.len() < 0.5 // ...and if the user is not dragging fast
if (shouldSnap) { if (shouldSnap) {
const { nudge } = editor.snaps.shapeBounds.snapTranslateShapes({ const { nudge } = editor.snaps.shapeBounds.snapTranslateShapes({