(id?: dia.Cell.ID, attributeParameter?: Attribute)
| 103 | |
| 104 | // eslint-disable-next-line jsdoc/require-jsdoc |
| 105 | export function useUpdateElement< |
| 106 | Attributes = BaseAttributes, |
| 107 | Attribute extends keyof Attributes = keyof Attributes, |
| 108 | >(id?: dia.Cell.ID, attributeParameter?: Attribute) { |
| 109 | const { graph } = useGraphStore(); |
| 110 | const setElement = useCallback( |
| 111 | (idOrAttributeOrValue: unknown, attributeOrValue?: unknown, value?: unknown) => { |
| 112 | if (isDiaId(idOrAttributeOrValue) && isAttribute(attributeOrValue) && isDefined(value)) { |
| 113 | // this mean, there is ID, attribute, and value via this fn |
| 114 | setCellHelper(graph, idOrAttributeOrValue, attributeOrValue, value); |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | if (!isDiaId(id)) { |
| 119 | return; |
| 120 | } |
| 121 | |
| 122 | if (isAttribute(idOrAttributeOrValue) && isDefined(attributeOrValue)) { |
| 123 | // this mean, there is attribute and value via this fn |
| 124 | setCellHelper(graph, id, idOrAttributeOrValue, attributeOrValue); |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | if (!isAttribute(attributeParameter)) { |
| 129 | return; |
| 130 | } |
| 131 | // mean only value is provided |
| 132 | setCellHelper(graph, id, attributeParameter, idOrAttributeOrValue); |
| 133 | }, |
| 134 | [attributeParameter, graph, id] |
| 135 | ); |
| 136 | return setElement; |
| 137 | } |
| 138 | |
| 139 | export type SetCell = ReturnType<typeof useUpdateElement>; |
no test coverage detected