kopia lustrzana https://github.com/Tldraw/Tldraw
update wording and docs of editor method
rodzic
1284c9af22
commit
a25736277e
|
@ -654,6 +654,7 @@ export class Editor extends EventEmitter<TLEventMap> {
|
||||||
}[K];
|
}[K];
|
||||||
};
|
};
|
||||||
findCommonAncestor(shapes: TLShape[] | TLShapeId[], predicate?: (shape: TLShape) => boolean): TLShapeId | undefined;
|
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;
|
findShapeAncestor(shape: TLShape | TLShapeId, predicate: (parent: TLShape) => boolean): TLShape | undefined;
|
||||||
flipShapes(shapes: TLShape[] | TLShapeId[], operation: 'horizontal' | 'vertical'): this;
|
flipShapes(shapes: TLShape[] | TLShapeId[], operation: 'horizontal' | 'vertical'): this;
|
||||||
getAncestorPageId(shape?: TLShape | TLShapeId): TLPageId | undefined;
|
getAncestorPageId(shape?: TLShape | TLShapeId): TLPageId | undefined;
|
||||||
|
@ -722,8 +723,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
||||||
isCulled: boolean;
|
isCulled: boolean;
|
||||||
maskedPageBounds: Box | undefined;
|
maskedPageBounds: Box | undefined;
|
||||||
}[];
|
}[];
|
||||||
// (undocumented)
|
|
||||||
getSelectedAncestor(shape: TLShape | TLShapeId): null | TLShape;
|
|
||||||
getSelectedShapeAtPoint(point: VecLike): TLShape | undefined;
|
getSelectedShapeAtPoint(point: VecLike): TLShape | undefined;
|
||||||
getSelectedShapeIds(): TLShapeId[];
|
getSelectedShapeIds(): TLShapeId[];
|
||||||
getSelectedShapes(): TLShape[];
|
getSelectedShapes(): TLShape[];
|
||||||
|
|
|
@ -9483,6 +9483,69 @@
|
||||||
"isAbstract": false,
|
"isAbstract": false,
|
||||||
"name": "findCommonAncestor"
|
"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",
|
"kind": "Method",
|
||||||
"canonicalReference": "@tldraw/editor!Editor#findShapeAncestor:member(1)",
|
"canonicalReference": "@tldraw/editor!Editor#findShapeAncestor:member(1)",
|
||||||
|
@ -11984,69 +12047,6 @@
|
||||||
"isAbstract": false,
|
"isAbstract": false,
|
||||||
"name": "getRenderingShapes"
|
"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",
|
"kind": "Method",
|
||||||
"canonicalReference": "@tldraw/editor!Editor#getSelectedShapeAtPoint:member(1)",
|
"canonicalReference": "@tldraw/editor!Editor#getSelectedShapeAtPoint:member(1)",
|
||||||
|
@ -14547,7 +14547,7 @@
|
||||||
{
|
{
|
||||||
"kind": "Method",
|
"kind": "Method",
|
||||||
"canonicalReference": "@tldraw/editor!Editor#isAncestorSelected:member(1)",
|
"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": [
|
"excerptTokens": [
|
||||||
{
|
{
|
||||||
"kind": "Content",
|
"kind": "Content",
|
||||||
|
|
|
@ -1518,15 +1518,21 @@ export class Editor extends EventEmitter<TLEventMap> {
|
||||||
/**
|
/**
|
||||||
* Determine whether or not any of a shape's ancestors are selected.
|
* 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
|
* @public
|
||||||
*/
|
*/
|
||||||
isAncestorSelected(shape: TLShape | TLShapeId): boolean {
|
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 id = typeof shape === 'string' ? shape : shape?.id ?? null
|
||||||
const _shape = this.getShape(id)
|
const _shape = this.getShape(id)
|
||||||
if (!_shape) return null
|
if (!_shape) return null
|
||||||
|
|
|
@ -27,7 +27,7 @@ export class PointingShape extends StateNode {
|
||||||
|
|
||||||
this.hitShape = info.shape
|
this.hitShape = info.shape
|
||||||
const outermostSelectingShape = this.editor.getOutermostSelectableShape(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 (
|
||||||
// If the shape has an onClick handler
|
// If the shape has an onClick handler
|
||||||
|
|
Ładowanie…
Reference in New Issue