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>;
canUnmount: TLShapeUtilFlag<Shape>;
abstract component(shape: Shape): any;
// @internal
doesAutoSnap: TLShapeUtilFlag<Shape>;
// (undocumented)
editor: Editor;
// @internal (undocumented)

Wyświetl plik

@ -131,6 +131,13 @@ export abstract class ShapeUtil<Shape extends TLUnknownShape = TLUnknownShape> {
*/
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,
* then any children with a `renderBackground` method will have their

Wyświetl plik

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

Wyświetl plik

@ -12239,6 +12239,36 @@
"isAbstract": false,
"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",
"canonicalReference": "tldraw!NoteShapeUtil#getDefaultProps:member(1)",

Wyświetl plik

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

Wyświetl plik

@ -234,7 +234,14 @@ export class Resizing extends StateNode {
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) {
const { nudge } = this.editor.snaps.shapeBounds.snapResizeShapes({

Wyświetl plik

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