mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
* performance -init * fixes: child components getting replaced * child components should be able to added to target containers * feat: reduce rerender of Dragcontainer (#9217) * fixes component crash for height incremental * clean up * clean up * clean up * removes debouncing of currentState updater * cleanup * controls update on components' referenced changed * fixes: widget crash if references are found * Reduced the load time by combining the appLoad queries loading state * Debounced initial currentState updates * reduce debounced time for updating current state * clean up * on events updation, referenced component via source id or csa would undergo a new re-render * Optimize tab navigation by asynchronously handling event, reducing UI blockage * off load updating app suggestions until UI renders * off load app load an page load event to low priority tasks list, resulting in faster app load * Added blocking updates to macrotask queue and changed Leftsidebar * Revert "Merge branch 'feat/grid-appbuilder-improvement' into core-performance/appbuilder" This reverts commit2e8374ac31, reversing changes made to23a86bfe6e. * fixes: component -extra re-rendering issue on current state changes. * fixes: extra re-render for each compoennt dnd updates * reverting computeComponentState back to autoSave callaback * Fixed showing default children * Reverted commit9b88e9fwhich causes infinite loop * Removed debuggerStore & unwanted props * Added profiler hoc * Implement batch processing and selective flushing for efficient state… (#9278) * Implement batch processing and selective flushing for efficient state updates in React components, optimizing performance for large-scale applications. * clean up * fix: fixed issues with delay of rerender (#9291) * fix: fixed issues with delay of rerender * fix: removed unused logs * fix: removed unused logs * fix: removed unused logs * clean up --------- Co-authored-by: arpitnath <arpitnath42@gmail.com> --------- Co-authored-by: Johnson Cherian <johnsonc.dev@gmail.com> * clean up * Fixed the crash on Form component * Optimize reference update tracking by sourcing from direct modifications rather than state diff comparisons. * clean up * fix: update appdefinition to editorstore in viewert (#9297) * removing current state deps from editor and processing re-renders. and use new resolver inside components (#9298) * removing current state deps from editor and processing re-renders. Also use new resolver inside components * perf: update position before state update on dnd (#9301) --------- Co-authored-by: Johnson Cherian <johnsonc.dev@gmail.com> --------- Co-authored-by: Johnson Cherian <johnsonc.dev@gmail.com> Co-authored-by: Kavin Venkatachalam <kavin.saratha@gmail.com>
97 lines
2.8 KiB
JavaScript
97 lines
2.8 KiB
JavaScript
import React from 'react';
|
|
import { useDragLayer } from 'react-dnd';
|
|
import { ItemTypes } from './editorConstants';
|
|
import { BoxDragPreview } from './BoxDragPreview';
|
|
import { snapToGrid } from '@/_helpers/appUtils';
|
|
const layerStyles = {
|
|
pointerEvents: 'none',
|
|
zIndex: 100,
|
|
left: 0,
|
|
top: 0,
|
|
width: '100%',
|
|
height: '100%',
|
|
};
|
|
|
|
function getItemStyles(delta, item, initialOffset, currentOffset, parentRef, parent, currentLayout, canvasWidth) {
|
|
if (!initialOffset || !currentOffset || !parentRef.current) {
|
|
return {
|
|
display: 'none',
|
|
};
|
|
}
|
|
|
|
if (parent !== item.parent) {
|
|
return {
|
|
display: 'none',
|
|
};
|
|
}
|
|
|
|
let x, y;
|
|
|
|
let id = item.id;
|
|
|
|
const realCanvasBoundingRect = parentRef.current.getElementsByClassName('real-canvas')[0].getBoundingClientRect();
|
|
|
|
if (id) {
|
|
// Dragging within the canvas
|
|
x = Math.round((item.layouts[currentLayout].left * canvasWidth) / 100 + delta.x);
|
|
y = Math.round(item.layouts[currentLayout].top + delta.y);
|
|
} else {
|
|
// New component being dragged from components sidebar
|
|
const offsetFromTopOfWindow = realCanvasBoundingRect.top;
|
|
const offsetFromLeftOfWindow = realCanvasBoundingRect.left;
|
|
const zoomLevel = item.zoomLevel;
|
|
|
|
x = Math.round(currentOffset.x + currentOffset.x * (1 - zoomLevel) - offsetFromLeftOfWindow);
|
|
y = Math.round(currentOffset.y + currentOffset.y * (1 - zoomLevel) - offsetFromTopOfWindow);
|
|
}
|
|
|
|
[x, y] = snapToGrid(canvasWidth, x, y);
|
|
|
|
const transform = `translate(${x}px, ${y}px)`;
|
|
return {
|
|
transform,
|
|
WebkitTransform: transform,
|
|
};
|
|
}
|
|
export const SubCustomDragLayer = ({ parentRef, parent, currentLayout }) => {
|
|
const { itemType, isDragging, item, initialOffset, currentOffset, delta } = useDragLayer((monitor) => ({
|
|
item: monitor.getItem(),
|
|
itemType: monitor.getItemType(),
|
|
initialOffset: monitor.getInitialSourceClientOffset(),
|
|
currentOffset: monitor.getSourceClientOffset(),
|
|
isDragging: monitor.isDragging(),
|
|
delta: monitor.getDifferenceFromInitialOffset(),
|
|
}));
|
|
|
|
let canvasWidth = 0;
|
|
|
|
if (parentRef.current) {
|
|
const realCanvas = parentRef.current.getElementsByClassName('real-canvas')[0];
|
|
if (realCanvas) {
|
|
const canvasBoundingRect = realCanvas.getBoundingClientRect();
|
|
canvasWidth = canvasBoundingRect.width;
|
|
}
|
|
}
|
|
|
|
function renderItem() {
|
|
switch (itemType) {
|
|
case ItemTypes.BOX:
|
|
return <BoxDragPreview item={item} currentLayout={currentLayout} canvasWidth={canvasWidth} />;
|
|
default:
|
|
return null;
|
|
}
|
|
}
|
|
if (!isDragging) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<div style={layerStyles} className="sub-custom-drag-layer">
|
|
<div
|
|
style={getItemStyles(delta, item, initialOffset, currentOffset, parentRef, parent, currentLayout, canvasWidth)}
|
|
>
|
|
{renderItem()}
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|