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.
pull/3046/head
Steve Ruiz 2024-03-02 20:16:55 +00:00 zatwierdzone przez GitHub
rodzic 1aef0e8f61
commit f819a57a05
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
3 zmienionych plików z 77 dodań i 2 usunięć

Wyświetl plik

@ -764,7 +764,6 @@ export class Editor extends EventEmitter<TLEventMap> {
getSharedStyles(): ReadonlySharedStyleMap;
getSortedChildIdsForParent(parent: TLPage | TLParentId | TLShape): TLShapeId[];
getStateDescendant<T extends StateNode>(path: string): T | undefined;
// @internal (undocumented)
getStyleForNextShape<T>(style: StyleProp<T>): T;
getSvg(shapes: TLShape[] | TLShapeId[], opts?: Partial<TLSvgOptions>): Promise<SVGSVGElement | undefined>;
getViewportPageBounds(): Box;

Wyświetl plik

@ -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<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",
"canonicalReference": "@tldraw/editor!Editor#getSvg:member(1)",

Wyświetl plik

@ -7196,7 +7196,17 @@ export class Editor extends EventEmitter<TLEventMap> {
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 {
const value = this.getInstanceState().stylesForNextShape[style.id]
return value === undefined ? style.defaultValue : (value as T)