MCPcopy
hub / github.com/clientIO/joint / useUpdateElement

Function useUpdateElement

packages/joint-react/src/hooks/use-update-element.ts:105–137  ·  view source on GitHub ↗
(id?: dia.Cell.ID, attributeParameter?: Attribute)

Source from the content-addressed store, hash-verified

103
104// eslint-disable-next-line jsdoc/require-jsdoc
105export 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
139export type SetCell = ReturnType<typeof useUpdateElement>;

Callers 15

HookFunction · 0.90
HookSetPositionFunction · 0.90
HookSetSizeFunction · 0.90
HookSetAngleFunction · 0.90
HookSetAnyFunction · 0.90
ElementInputFunction · 0.90
ElementInputFunction · 0.90
ElementInputFunction · 0.90
RenderElementFunction · 0.90
ListElementFunction · 0.90

Calls 5

useGraphStoreFunction · 0.90
isDiaIdFunction · 0.90
isAttributeFunction · 0.90
isDefinedFunction · 0.90
setCellHelperFunction · 0.85

Tested by

no test coverage detected