From f819a57a052d74667134866859bbdc7045493bae Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Sat, 2 Mar 2024 20:16:55 +0000 Subject: [PATCH] Expose `getStyleForNextShape` (#3039) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR exposes a method for getting the style for the next shape. ### Change Type - [x] `patch` — Bug fix ### Release Notes - Expose the API for `Editor.getStyleForNextShape`, previously marked as internal. --- packages/editor/api-report.md | 1 - packages/editor/api/api.json | 66 ++++++++++++++++++++++++ packages/editor/src/lib/editor/Editor.ts | 12 ++++- 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/packages/editor/api-report.md b/packages/editor/api-report.md index e52e7db5a..df34bb5e9 100644 --- a/packages/editor/api-report.md +++ b/packages/editor/api-report.md @@ -764,7 +764,6 @@ export class Editor extends EventEmitter { getSharedStyles(): ReadonlySharedStyleMap; getSortedChildIdsForParent(parent: TLPage | TLParentId | TLShape): TLShapeId[]; getStateDescendant(path: string): T | undefined; - // @internal (undocumented) getStyleForNextShape(style: StyleProp): T; getSvg(shapes: TLShape[] | TLShapeId[], opts?: Partial): Promise; getViewportPageBounds(): Box; diff --git a/packages/editor/api/api.json b/packages/editor/api/api.json index 2d4099197..7b4bfc662 100644 --- a/packages/editor/api/api.json +++ b/packages/editor/api/api.json @@ -13815,6 +13815,72 @@ "isAbstract": false, "name": "getStateDescendant" }, + { + "kind": "Method", + "canonicalReference": "@tldraw/editor!Editor#getStyleForNextShape:member(1)", + "docComment": "/**\n * Get the style for the next shape.\n *\n * @param style - The style to get.\n *\n * @example\n * ```ts\n * const color = editor.getStyleForNextShape(DefaultColorStyle)\n * ```\n *\n * @public\n */\n", + "excerptTokens": [ + { + "kind": "Content", + "text": "getStyleForNextShape(style: " + }, + { + "kind": "Reference", + "text": "StyleProp", + "canonicalReference": "@tldraw/tlschema!StyleProp:class" + }, + { + "kind": "Content", + "text": "" + }, + { + "kind": "Content", + "text": "): " + }, + { + "kind": "Content", + "text": "T" + }, + { + "kind": "Content", + "text": ";" + } + ], + "typeParameters": [ + { + "typeParameterName": "T", + "constraintTokenRange": { + "startIndex": 0, + "endIndex": 0 + }, + "defaultTypeTokenRange": { + "startIndex": 0, + "endIndex": 0 + } + } + ], + "isStatic": false, + "returnTypeTokenRange": { + "startIndex": 4, + "endIndex": 5 + }, + "releaseTag": "Public", + "isProtected": false, + "overloadIndex": 1, + "parameters": [ + { + "parameterName": "style", + "parameterTypeTokenRange": { + "startIndex": 1, + "endIndex": 3 + }, + "isOptional": false + } + ], + "isOptional": false, + "isAbstract": false, + "name": "getStyleForNextShape" + }, { "kind": "Method", "canonicalReference": "@tldraw/editor!Editor#getSvg:member(1)", diff --git a/packages/editor/src/lib/editor/Editor.ts b/packages/editor/src/lib/editor/Editor.ts index 4e4e2c691..fdaba114d 100644 --- a/packages/editor/src/lib/editor/Editor.ts +++ b/packages/editor/src/lib/editor/Editor.ts @@ -7196,7 +7196,17 @@ export class Editor extends EventEmitter { return sharedStyles } - /** @internal */ + /** + * Get the style for the next shape. + * + * @example + * ```ts + * const color = editor.getStyleForNextShape(DefaultColorStyle) + * ``` + * + * @param style - The style to get. + * + * @public */ getStyleForNextShape(style: StyleProp): T { const value = this.getInstanceState().stylesForNextShape[style.id] return value === undefined ? style.defaultValue : (value as T)