-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #605 from Lemoncode/dev
multiple selection props editing
- Loading branch information
Showing
7 changed files
with
521 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useMemo } from 'react'; | ||
import { CommonSelectedPropsAndValues } from '../properties.model'; | ||
import { OtherProps } from '@/core/model'; | ||
|
||
interface Props { | ||
singleSelection: boolean; | ||
multipleSelectionPropsInCommon: CommonSelectedPropsAndValues; | ||
propKey: keyof OtherProps; | ||
propValue: unknown; | ||
children: React.ReactNode; | ||
} | ||
|
||
export const ShowProp: React.FC<Props> = props => { | ||
const { | ||
singleSelection, | ||
multipleSelectionPropsInCommon, | ||
propKey, | ||
propValue, | ||
children, | ||
} = props; | ||
|
||
const showProp: boolean = useMemo( | ||
() => | ||
(singleSelection && propValue !== undefined) || | ||
multipleSelectionPropsInCommon[propKey] !== undefined, | ||
[multipleSelectionPropsInCommon, propKey, propValue] | ||
); | ||
|
||
return <>{showProp ? children : null}</>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { OtherProps, ShapeModel } from '@/core/model'; | ||
import { | ||
CommonSelectedPropsAndValues, | ||
multiSelectEnabledProperties, | ||
} from './properties.model'; | ||
|
||
// Helper function to check if a property is defined in all selected shapes | ||
const isPropertyDefinedInAllShapes = ( | ||
selectedShapes: ShapeModel[], | ||
prop: keyof OtherProps | ||
): boolean => { | ||
return selectedShapes.every( | ||
shape => shape.otherProps && shape.otherProps[prop] !== undefined | ||
); | ||
}; | ||
|
||
// Helper function to get the common value of a property, or undefined if values differ | ||
// TODO: Right now we are getting the first default value of the selectedShape | ||
// this may not be accurate, maybe we could check if all values are not the same | ||
// define a default prop for all the entries | ||
/* | ||
const getCommonValueForProperty = ( | ||
selectedShapes: ShapeModel[], | ||
prop: keyof OtherProps | ||
): PropsValueTypes => { | ||
const values = selectedShapes.map( | ||
shape => shape.otherProps && shape.otherProps[prop] | ||
); | ||
// TODO: Here is the trick, we should return a default value | ||
// if the commonValue is not se or where it is consumed | ||
return values.every(value => value === values[0]) ? values[0] : undefined; | ||
}; | ||
*/ | ||
|
||
// Main function to extract common properties and their values | ||
export const extractMultiplePropsInCommon = ( | ||
selectedShapes: ShapeModel[] | ||
): CommonSelectedPropsAndValues => { | ||
const commonProps: CommonSelectedPropsAndValues = {}; | ||
|
||
multiSelectEnabledProperties.forEach(prop => { | ||
if (isPropertyDefinedInAllShapes(selectedShapes, prop)) { | ||
//commonProps[prop] = getCommonValueForProperty(selectedShapes, prop); | ||
if (selectedShapes.length > 1 && selectedShapes[0].otherProps) { | ||
commonProps[prop] = selectedShapes[0].otherProps[prop]; | ||
} | ||
} | ||
}); | ||
|
||
return commonProps; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { IconInfo, OtherProps } from '@/core/model'; | ||
|
||
export const multiSelectEnabledProperties: (keyof OtherProps)[] = [ | ||
'stroke', | ||
'backgroundColor', | ||
'textColor', | ||
'selectedBackgroundColor', | ||
'strokeStyle', | ||
'fontVariant', | ||
'fontStyle', | ||
'fontSize', | ||
'textDecoration', | ||
'checked', | ||
'icon', | ||
'iconSize', | ||
'imageBlackAndWhite', | ||
'progress', | ||
'borderRadius', | ||
'selectedBackgroundColor', | ||
'textAlignment', | ||
]; | ||
|
||
export type PropsValueTypes = | ||
| string | ||
| number | ||
| boolean | ||
| number[] | ||
| IconInfo | ||
| undefined; | ||
|
||
export interface CommonSelectedPropsAndValues { | ||
[key: string]: PropsValueTypes; | ||
} |
Oops, something went wrong.