Apply styles to groups

pull/68/head
Steve Ruiz 2021-09-03 11:58:20 +01:00
rodzic 2e96f0f3e2
commit adda205917
2 zmienionych plików z 27 dodań i 1 usunięć

Wyświetl plik

@ -22,4 +22,28 @@ describe('Style command', () => {
expect(tlstate.getShape('rect1').style.size).toEqual(SizeStyle.Small)
})
describe('When styling groups', () => {
it('applies style to all group children', () => {
const tlstate = new TLDrawState()
tlstate
.loadDocument(mockDocument)
.group(['rect1', 'rect2'], 'groupA')
.select('groupA')
.style({ size: SizeStyle.Small })
expect(tlstate.getShape('rect1').style.size).toEqual(SizeStyle.Small)
expect(tlstate.getShape('rect2').style.size).toEqual(SizeStyle.Small)
tlstate.undo()
expect(tlstate.getShape('rect1').style.size).toEqual(SizeStyle.Medium)
expect(tlstate.getShape('rect2').style.size).toEqual(SizeStyle.Medium)
tlstate.redo()
expect(tlstate.getShape('rect1').style.size).toEqual(SizeStyle.Small)
expect(tlstate.getShape('rect2').style.size).toEqual(SizeStyle.Small)
})
})
})

Wyświetl plik

@ -4,9 +4,11 @@ import { TLDR } from '~state/tldr'
export function style(data: Data, ids: string[], changes: Partial<ShapeStyles>): TLDrawCommand {
const { currentPageId } = data.appState
const shapeIdsToMutate = ids.flatMap((id) => TLDR.getDocumentBranch(data, id, currentPageId))
const { before, after } = TLDR.mutateShapes(
data,
ids,
shapeIdsToMutate,
(shape) => ({ style: { ...shape.style, ...changes } }),
currentPageId
)