[fix] remove findLast calls (#2081)
This PR removes some calls to `findLast`, as this is not in all browsers yet. ### Change Type - [x] `patch` — Bug fix ### Test Plan 1. Drag and drop. 2. Create a shape inside of a frame - [x] Unit Tests
This commit is contained in:
parent
c377c98902
commit
59129e269d
3 changed files with 57 additions and 41 deletions
|
@ -672,7 +672,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
getAssetForExternalContent(info: TLExternalAssetContent): Promise<TLAsset | undefined>;
|
||||
getContainer: () => HTMLElement;
|
||||
getContentFromCurrentPage(shapes: TLShape[] | TLShapeId[]): TLContent | undefined;
|
||||
getDroppingOverShape(point: VecLike, droppingShapes?: TLShape[]): TLShape | undefined;
|
||||
getDroppingOverShape(point: VecLike, droppingShapes?: TLShape[]): TLUnknownShape | undefined;
|
||||
getHighestIndexForParent(parent: TLPage | TLParentId | TLShape): string;
|
||||
getInitialMetaForShape(_shape: TLShape): JsonObject;
|
||||
getOutermostSelectableShape(shape: TLShape | TLShapeId, filter?: (shape: TLShape) => boolean): TLShape;
|
||||
|
|
|
@ -10102,8 +10102,8 @@
|
|||
},
|
||||
{
|
||||
"kind": "Reference",
|
||||
"text": "TLShape",
|
||||
"canonicalReference": "@tldraw/tlschema!TLShape:type"
|
||||
"text": "TLUnknownShape",
|
||||
"canonicalReference": "@tldraw/tlschema!TLUnknownShape:type"
|
||||
},
|
||||
{
|
||||
"kind": "Content",
|
||||
|
|
|
@ -4938,14 +4938,17 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
*/
|
||||
getDroppingOverShape(point: VecLike, droppingShapes: TLShape[] = []) {
|
||||
// starting from the top...
|
||||
return this.currentPageShapesSorted.findLast((shape) => {
|
||||
const { currentPageShapesSorted } = this
|
||||
for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
|
||||
const shape = currentPageShapesSorted[i]
|
||||
|
||||
if (
|
||||
// only allow shapes that can receive children
|
||||
!this.getShapeUtil(shape).canDropShapes(shape, droppingShapes) ||
|
||||
// don't allow dropping a shape on itself or one of it's children
|
||||
droppingShapes.find((s) => s.id === shape.id || this.hasAncestor(shape, s.id))
|
||||
) {
|
||||
return false
|
||||
continue
|
||||
}
|
||||
|
||||
// Only allow dropping into the masked page bounds of the shape, e.g. when a frame is
|
||||
|
@ -4957,9 +4960,9 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
maskedPageBounds.containsPoint(point) &&
|
||||
this.getShapeGeometry(shape).hitTestPoint(this.getPointInShapeSpace(shape, point), 0, true)
|
||||
) {
|
||||
return true
|
||||
return shape
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6484,7 +6487,9 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
// Make sure that each partial will become the child of either the
|
||||
// page or another shape that exists (or that will exist) in this page.
|
||||
|
||||
// find last parent id
|
||||
const { currentPageShapesSorted } = this
|
||||
|
||||
partials = partials.map((partial) => {
|
||||
// If the partial does not provide the parentId OR if the provided
|
||||
// parentId is NOT in the store AND NOT among the other shapes being
|
||||
|
@ -6495,11 +6500,11 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
!partial.parentId ||
|
||||
!(this.store.has(partial.parentId) || partials.some((p) => p.id === partial.parentId))
|
||||
) {
|
||||
partial = { ...partial }
|
||||
let parentId: TLParentId = this.focusedGroupId
|
||||
|
||||
const parentId =
|
||||
currentPageShapesSorted.findLast(
|
||||
(parent) =>
|
||||
for (let i = currentPageShapesSorted.length - 1; i >= 0; i--) {
|
||||
const parent = currentPageShapesSorted[i]
|
||||
if (
|
||||
// parent.type === 'frame'
|
||||
this.getShapeUtil(parent).canReceiveNewChildrenOfType(parent, partial.type) &&
|
||||
this.isPointInShape(
|
||||
|
@ -6512,7 +6517,22 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
hitInside: true,
|
||||
}
|
||||
)
|
||||
)?.id ?? this.focusedGroupId
|
||||
) {
|
||||
parentId = parent.id
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
const prevParentId = partial.parentId
|
||||
|
||||
// a shape cannot be it's own parent. This was a rare issue with frames/groups in the syncFuzz tests.
|
||||
if (parentId === partial.id) {
|
||||
parentId = focusedGroupId
|
||||
}
|
||||
|
||||
// If the parentid has changed...
|
||||
if (parentId !== prevParentId) {
|
||||
partial = { ...partial }
|
||||
|
||||
partial.parentId = parentId
|
||||
|
||||
|
@ -6529,10 +6549,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
|||
partial.rotation =
|
||||
-this.getShapePageTransform(parentId)!.rotation() + (partial.rotation ?? 0)
|
||||
}
|
||||
|
||||
// a shape cannot be it's own parent. This was a rare issue with frames/groups in the syncFuzz tests.
|
||||
if (partial.parentId === partial.id) {
|
||||
partial.parentId = focusedGroupId
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue