Skip to content

Commit

Permalink
refactor: calculate path consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Jan 19, 2025
1 parent 97d25d4 commit b781b5a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
12 changes: 3 additions & 9 deletions packages/core/components/DragDropContext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,26 +305,20 @@ const DragDropContextClient = ({
const dragMode = useRef<"new" | "existing" | null>(null);

const registerPath = useCallback(
(selector: ItemSelector) => {
const item = getItem(selector, data);

if (!item) {
return;
}

(id: string, selector: ItemSelector, label: string) => {
const [area] = getZoneId(selector.zone);

setPathData((latestPathData = {}) => {
const parentPathData = latestPathData[area] || { path: [] };

return {
...latestPathData,
[item.props.id]: {
[id]: {
path: [
...parentPathData.path,
...(selector.zone ? [selector.zone] : []),
],
label: item.type as string,
label: label,
},
};
});
Expand Down
12 changes: 7 additions & 5 deletions packages/core/components/DraggableComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,15 @@ export const DraggableComponent = ({
}, [ref.current]);

useEffect(() => {
if (isSelected) {
ctx?.registerPath!({
ctx?.registerPath!(
id,
{
index,
zone: zoneCompound,
});
}
}, [isSelected]);
},
componentType
);
}, [id, zoneCompound, index, componentType]);

const CustomActionBar = useMemo(
() => overrides.actionBar || DefaultActionBar,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/components/DropZone/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type DropZoneContext<UserConfig extends Config = Config> = {
unregisterZone?: (zoneCompound: string) => void;
activeZones?: Record<string, boolean>;
pathData?: PathData;
registerPath?: (selector: ItemSelector) => void;
registerPath?: (id: string, selector: ItemSelector, label: string) => void;
mode?: "edit" | "render";
depth: number;
registerLocalZone?: (zone: string, active: boolean) => void; // A zone as it pertains to the current area
Expand Down

0 comments on commit b781b5a

Please sign in to comment.