update wording and docs of editor method

pull/3280/head
Lu[ke] Wilson 2024-03-27 11:46:34 +00:00
rodzic 1284c9af22
commit a25736277e
4 zmienionych plików z 75 dodań i 70 usunięć

Wyświetl plik

@ -654,6 +654,7 @@ export class Editor extends EventEmitter<TLEventMap> {
}[K];
};
findCommonAncestor(shapes: TLShape[] | TLShapeId[], predicate?: (shape: TLShape) => boolean): TLShapeId | undefined;
findSelectedAncestor(shape: TLShape | TLShapeId): null | TLShape;
findShapeAncestor(shape: TLShape | TLShapeId, predicate: (parent: TLShape) => boolean): TLShape | undefined;
flipShapes(shapes: TLShape[] | TLShapeId[], operation: 'horizontal' | 'vertical'): this;
getAncestorPageId(shape?: TLShape | TLShapeId): TLPageId | undefined;
@ -722,8 +723,6 @@ export class Editor extends EventEmitter<TLEventMap> {
isCulled: boolean;
maskedPageBounds: Box | undefined;
}[];
// (undocumented)
getSelectedAncestor(shape: TLShape | TLShapeId): null | TLShape;
getSelectedShapeAtPoint(point: VecLike): TLShape | undefined;
getSelectedShapeIds(): TLShapeId[];
getSelectedShapes(): TLShape[];

Wyświetl plik

@ -9483,6 +9483,69 @@
"isAbstract": false,
"name": "findCommonAncestor"
},
{
"kind": "Method",
"canonicalReference": "@tldraw/editor!Editor#findSelectedAncestor:member(1)",
"docComment": "/**\n * Find the first selected ancestor of a shape.\n *\n * @param shape - The shape to find the selected ancestor of.\n *\n * @returns \n */\n",
"excerptTokens": [
{
"kind": "Content",
"text": "findSelectedAncestor(shape: "
},
{
"kind": "Reference",
"text": "TLShape",
"canonicalReference": "@tldraw/tlschema!TLShape:type"
},
{
"kind": "Content",
"text": " | "
},
{
"kind": "Reference",
"text": "TLShapeId",
"canonicalReference": "@tldraw/tlschema!TLShapeId:type"
},
{
"kind": "Content",
"text": "): "
},
{
"kind": "Content",
"text": "null | "
},
{
"kind": "Reference",
"text": "TLShape",
"canonicalReference": "@tldraw/tlschema!TLShape:type"
},
{
"kind": "Content",
"text": ";"
}
],
"isStatic": false,
"returnTypeTokenRange": {
"startIndex": 5,
"endIndex": 7
},
"releaseTag": "Public",
"isProtected": false,
"overloadIndex": 1,
"parameters": [
{
"parameterName": "shape",
"parameterTypeTokenRange": {
"startIndex": 1,
"endIndex": 4
},
"isOptional": false
}
],
"isOptional": false,
"isAbstract": false,
"name": "findSelectedAncestor"
},
{
"kind": "Method",
"canonicalReference": "@tldraw/editor!Editor#findShapeAncestor:member(1)",
@ -11984,69 +12047,6 @@
"isAbstract": false,
"name": "getRenderingShapes"
},
{
"kind": "Method",
"canonicalReference": "@tldraw/editor!Editor#getSelectedAncestor:member(1)",
"docComment": "",
"excerptTokens": [
{
"kind": "Content",
"text": "getSelectedAncestor(shape: "
},
{
"kind": "Reference",
"text": "TLShape",
"canonicalReference": "@tldraw/tlschema!TLShape:type"
},
{
"kind": "Content",
"text": " | "
},
{
"kind": "Reference",
"text": "TLShapeId",
"canonicalReference": "@tldraw/tlschema!TLShapeId:type"
},
{
"kind": "Content",
"text": "): "
},
{
"kind": "Content",
"text": "null | "
},
{
"kind": "Reference",
"text": "TLShape",
"canonicalReference": "@tldraw/tlschema!TLShape:type"
},
{
"kind": "Content",
"text": ";"
}
],
"isStatic": false,
"returnTypeTokenRange": {
"startIndex": 5,
"endIndex": 7
},
"releaseTag": "Public",
"isProtected": false,
"overloadIndex": 1,
"parameters": [
{
"parameterName": "shape",
"parameterTypeTokenRange": {
"startIndex": 1,
"endIndex": 4
},
"isOptional": false
}
],
"isOptional": false,
"isAbstract": false,
"name": "getSelectedAncestor"
},
{
"kind": "Method",
"canonicalReference": "@tldraw/editor!Editor#getSelectedShapeAtPoint:member(1)",
@ -14547,7 +14547,7 @@
{
"kind": "Method",
"canonicalReference": "@tldraw/editor!Editor#isAncestorSelected:member(1)",
"docComment": "/**\n * Determine whether or not any of a shape's ancestors are selected.\n *\n * @param id - The id of the shape to check.\n *\n * @public\n */\n",
"docComment": "/**\n * Determine whether or not any of a shape's ancestors are selected.\n *\n * @param shape - The shape to check.\n *\n * @public\n */\n",
"excerptTokens": [
{
"kind": "Content",

Wyświetl plik

@ -1518,15 +1518,21 @@ export class Editor extends EventEmitter<TLEventMap> {
/**
* Determine whether or not any of a shape's ancestors are selected.
*
* @param id - The id of the shape to check.
* @param shape - The shape to check.
*
* @public
*/
isAncestorSelected(shape: TLShape | TLShapeId): boolean {
return this.getSelectedAncestor(shape) !== null
return this.findSelectedAncestor(shape) !== null
}
getSelectedAncestor(shape: TLShape | TLShapeId): TLShape | null {
/**
* Find the first selected ancestor of a shape.
*
* @param shape - The shape to find the selected ancestor of.
* @returns
*/
findSelectedAncestor(shape: TLShape | TLShapeId): TLShape | null {
const id = typeof shape === 'string' ? shape : shape?.id ?? null
const _shape = this.getShape(id)
if (!_shape) return null

Wyświetl plik

@ -27,7 +27,7 @@ export class PointingShape extends StateNode {
this.hitShape = info.shape
const outermostSelectingShape = this.editor.getOutermostSelectableShape(info.shape)
const selectedAncestor = this.editor.getSelectedAncestor(outermostSelectingShape.id)
const selectedAncestor = this.editor.findSelectedAncestor(outermostSelectingShape.id)
if (
// If the shape has an onClick handler