2021-06-02 11:50:34 +00:00
|
|
|
import Command from './command'
|
|
|
|
import history from '../history'
|
|
|
|
import { Data, ShapeStyles } from 'types'
|
|
|
|
import { getPage, getSelectedShapes } from 'utils/utils'
|
|
|
|
import { getShapeUtils } from 'lib/shape-utils'
|
|
|
|
import { current } from 'immer'
|
2021-05-26 10:34:10 +00:00
|
|
|
|
2021-06-02 11:50:34 +00:00
|
|
|
export default function styleCommand(data: Data, styles: Partial<ShapeStyles>) {
|
2021-05-26 10:34:10 +00:00
|
|
|
const { currentPageId } = data
|
|
|
|
const initialShapes = getSelectedShapes(current(data))
|
|
|
|
|
|
|
|
history.execute(
|
|
|
|
data,
|
|
|
|
new Command({
|
2021-06-02 11:50:34 +00:00
|
|
|
name: 'changed_style',
|
|
|
|
category: 'canvas',
|
2021-05-26 10:34:10 +00:00
|
|
|
manualSelection: true,
|
|
|
|
do(data) {
|
|
|
|
const { shapes } = getPage(data, currentPageId)
|
|
|
|
|
|
|
|
for (const { id } of initialShapes) {
|
|
|
|
const shape = shapes[id]
|
|
|
|
getShapeUtils(shape).applyStyles(shape, styles)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
undo(data) {
|
|
|
|
const { shapes } = getPage(data, currentPageId)
|
|
|
|
|
|
|
|
for (const { id, style } of initialShapes) {
|
|
|
|
const shape = shapes[id]
|
|
|
|
getShapeUtils(shape).applyStyles(shape, style)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|