Expose getStyleForNextShape
(#3039)
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.
This commit is contained in:
parent
1aef0e8f61
commit
f819a57a05
3 changed files with 77 additions and 2 deletions
|
@ -764,7 +764,6 @@ export class Editor extends EventEmitter<TLEventMap> {
|
||||||
getSharedStyles(): ReadonlySharedStyleMap;
|
getSharedStyles(): ReadonlySharedStyleMap;
|
||||||
getSortedChildIdsForParent(parent: TLPage | TLParentId | TLShape): TLShapeId[];
|
getSortedChildIdsForParent(parent: TLPage | TLParentId | TLShape): TLShapeId[];
|
||||||
getStateDescendant<T extends StateNode>(path: string): T | undefined;
|
getStateDescendant<T extends StateNode>(path: string): T | undefined;
|
||||||
// @internal (undocumented)
|
|
||||||
getStyleForNextShape<T>(style: StyleProp<T>): T;
|
getStyleForNextShape<T>(style: StyleProp<T>): T;
|
||||||
getSvg(shapes: TLShape[] | TLShapeId[], opts?: Partial<TLSvgOptions>): Promise<SVGSVGElement | undefined>;
|
getSvg(shapes: TLShape[] | TLShapeId[], opts?: Partial<TLSvgOptions>): Promise<SVGSVGElement | undefined>;
|
||||||
getViewportPageBounds(): Box;
|
getViewportPageBounds(): Box;
|
||||||
|
|
|
@ -13815,6 +13815,72 @@
|
||||||
"isAbstract": false,
|
"isAbstract": false,
|
||||||
"name": "getStateDescendant"
|
"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<T>(style: "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "Reference",
|
||||||
|
"text": "StyleProp",
|
||||||
|
"canonicalReference": "@tldraw/tlschema!StyleProp:class"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"kind": "Content",
|
||||||
|
"text": "<T>"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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",
|
"kind": "Method",
|
||||||
"canonicalReference": "@tldraw/editor!Editor#getSvg:member(1)",
|
"canonicalReference": "@tldraw/editor!Editor#getSvg:member(1)",
|
||||||
|
|
|
@ -7196,7 +7196,17 @@ export class Editor extends EventEmitter<TLEventMap> {
|
||||||
return sharedStyles
|
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<T>(style: StyleProp<T>): T {
|
getStyleForNextShape<T>(style: StyleProp<T>): T {
|
||||||
const value = this.getInstanceState().stylesForNextShape[style.id]
|
const value = this.getInstanceState().stylesForNextShape[style.id]
|
||||||
return value === undefined ? style.defaultValue : (value as T)
|
return value === undefined ? style.defaultValue : (value as T)
|
||||||
|
|
Loading…
Reference in a new issue