Add constrainToBounds prop to DraggableContainer for boundary-limited dragging; enhance console logging in PixelStreamingWrapper to filter messages
This commit is contained in:
@@ -16,6 +16,8 @@ interface DraggableContainerProps {
|
|||||||
enableSnapping?: boolean;
|
enableSnapping?: boolean;
|
||||||
/** Автоматическое flex-выравнивание в зависимости от прижатого угла (по умолчанию false) */
|
/** Автоматическое flex-выравнивание в зависимости от прижатого угла (по умолчанию false) */
|
||||||
autoAlign?: boolean;
|
autoAlign?: boolean;
|
||||||
|
/** Ограничить перетаскивание границами окна (по умолчанию false) */
|
||||||
|
constrainToBounds?: boolean;
|
||||||
/** Начальная позиция контейнера */
|
/** Начальная позиция контейнера */
|
||||||
initialPosition?: Position;
|
initialPosition?: Position;
|
||||||
/** Отступ от краев экрана при снэпинге (по умолчанию 20px) */
|
/** Отступ от краев экрана при снэпинге (по умолчанию 20px) */
|
||||||
@@ -41,6 +43,12 @@ interface DraggableContainerProps {
|
|||||||
* </DraggableContainer>
|
* </DraggableContainer>
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
|
* // С ограничением перетаскивания границами окна
|
||||||
|
* <DraggableContainer constrainToBounds={true}>
|
||||||
|
* <YourContent />
|
||||||
|
* </DraggableContainer>
|
||||||
|
*
|
||||||
|
* @example
|
||||||
* // Без автоматического выравнивания (управляется вручную через className)
|
* // Без автоматического выравнивания (управляется вручную через className)
|
||||||
* <DraggableContainer enableSnapping={true} className="flex flex-col gap-4">
|
* <DraggableContainer enableSnapping={true} className="flex flex-col gap-4">
|
||||||
* <YourContent />
|
* <YourContent />
|
||||||
@@ -50,6 +58,7 @@ export default function DraggableContainer({
|
|||||||
children,
|
children,
|
||||||
enableSnapping = false,
|
enableSnapping = false,
|
||||||
autoAlign = false,
|
autoAlign = false,
|
||||||
|
constrainToBounds = false,
|
||||||
initialPosition = { top: 20, right: 20 },
|
initialPosition = { top: 20, right: 20 },
|
||||||
padding = 20,
|
padding = 20,
|
||||||
className = "",
|
className = "",
|
||||||
@@ -150,8 +159,20 @@ export default function DraggableContainer({
|
|||||||
const deltaX = clientX - dragRef.current.startX;
|
const deltaX = clientX - dragRef.current.startX;
|
||||||
const deltaY = clientY - dragRef.current.startY;
|
const deltaY = clientY - dragRef.current.startY;
|
||||||
|
|
||||||
const newTop = dragRef.current.initialPosition.top + deltaY;
|
// Вычисляем новую позицию
|
||||||
const newLeft = dragRef.current.initialPosition.left + deltaX;
|
let newTop = dragRef.current.initialPosition.top + deltaY;
|
||||||
|
let newLeft = dragRef.current.initialPosition.left + deltaX;
|
||||||
|
|
||||||
|
// Ограничиваем позицию границами окна, если включено
|
||||||
|
if (constrainToBounds && containerRef.current) {
|
||||||
|
const containerWidth = containerRef.current.offsetWidth;
|
||||||
|
const containerHeight = containerRef.current.offsetHeight;
|
||||||
|
const windowWidth = window.innerWidth;
|
||||||
|
const windowHeight = window.innerHeight;
|
||||||
|
|
||||||
|
newTop = Math.max(0, Math.min(newTop, windowHeight - containerHeight));
|
||||||
|
newLeft = Math.max(0, Math.min(newLeft, windowWidth - containerWidth));
|
||||||
|
}
|
||||||
|
|
||||||
// Во время перетаскивания используем только top и left
|
// Во время перетаскивания используем только top и left
|
||||||
const newPosition = {
|
const newPosition = {
|
||||||
|
|||||||
@@ -28,9 +28,49 @@ export const PixelStreamingWrapper = ({
|
|||||||
|
|
||||||
// Run on component mount:
|
// Run on component mount:
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// Сохраняем оригинальные методы console
|
||||||
|
const originalLog = console.log;
|
||||||
|
const originalInfo = console.info;
|
||||||
|
const originalWarn = console.warn;
|
||||||
|
|
||||||
|
// Переопределяем console для фильтрации логов Pixel Streaming
|
||||||
|
console.log = (...args) => {
|
||||||
|
const message = args[0]?.toString() || "";
|
||||||
|
if (
|
||||||
|
!message.includes("[Info]") &&
|
||||||
|
!message.includes("[Debug]") &&
|
||||||
|
!message.includes("Stack:")
|
||||||
|
) {
|
||||||
|
originalLog.apply(console, args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.info = (...args) => {
|
||||||
|
const message = args[0]?.toString() || "";
|
||||||
|
if (
|
||||||
|
!message.includes("[Info]") &&
|
||||||
|
!message.includes("[Debug]") &&
|
||||||
|
!message.includes("Stack:")
|
||||||
|
) {
|
||||||
|
originalInfo.apply(console, args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
console.warn = (...args) => {
|
||||||
|
const message = args[0]?.toString() || "";
|
||||||
|
if (
|
||||||
|
!message.includes("[Info]") &&
|
||||||
|
!message.includes("[Debug]") &&
|
||||||
|
!message.includes("Stack:")
|
||||||
|
) {
|
||||||
|
originalWarn.apply(console, args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (videoParent.current) {
|
if (videoParent.current) {
|
||||||
// Attach Pixel Streaming library to videoParent element:
|
// Attach Pixel Streaming library to videoParent element:
|
||||||
const config = new Config({ initialSettings });
|
const config = new Config({ initialSettings });
|
||||||
|
|
||||||
const streaming = new PixelStreaming(config, {
|
const streaming = new PixelStreaming(config, {
|
||||||
videoElementParent: videoParent.current,
|
videoElementParent: videoParent.current,
|
||||||
});
|
});
|
||||||
@@ -54,8 +94,20 @@ export const PixelStreamingWrapper = ({
|
|||||||
} catch {
|
} catch {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Восстанавливаем оригинальные методы console
|
||||||
|
console.log = originalLog;
|
||||||
|
console.info = originalInfo;
|
||||||
|
console.warn = originalWarn;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Восстанавливаем console если компонент размонтируется до инициализации
|
||||||
|
return () => {
|
||||||
|
console.log = originalLog;
|
||||||
|
console.info = originalInfo;
|
||||||
|
console.warn = originalWarn;
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user