@aptre/flex-layout 0.5.3 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +74 -38
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5934,7 +5934,7 @@ var DragState = class {
|
|
|
5934
5934
|
|
|
5935
5935
|
// src/view/OptimizedLayout.tsx
|
|
5936
5936
|
import * as React20 from "react";
|
|
5937
|
-
import { useCallback, useEffect as useEffect6, useState as useState4 } from "react";
|
|
5937
|
+
import { memo as memo2, useCallback, useEffect as useEffect6, useMemo, useState as useState4 } from "react";
|
|
5938
5938
|
function createTabInfo(node) {
|
|
5939
5939
|
const parent = node.getParent();
|
|
5940
5940
|
const contentRect = parent?.getContentRect() ?? Rect.empty();
|
|
@@ -5946,6 +5946,7 @@ function createTabInfo(node) {
|
|
|
5946
5946
|
}
|
|
5947
5947
|
function TabRef({
|
|
5948
5948
|
node,
|
|
5949
|
+
selected,
|
|
5949
5950
|
onTabMount,
|
|
5950
5951
|
onRectChange,
|
|
5951
5952
|
onVisibilityChange
|
|
@@ -5967,14 +5968,52 @@ function TabRef({
|
|
|
5967
5968
|
onRectChange(node.getId(), contentRect);
|
|
5968
5969
|
}
|
|
5969
5970
|
}
|
|
5970
|
-
onVisibilityChange(node.getId(), node.isSelected());
|
|
5971
5971
|
return () => {
|
|
5972
5972
|
node.removeEventListener("resize");
|
|
5973
5973
|
node.removeEventListener("visibility");
|
|
5974
|
+
node.setVisible(false);
|
|
5974
5975
|
};
|
|
5975
5976
|
}, [node, onTabMount, onRectChange, onVisibilityChange]);
|
|
5977
|
+
useEffect6(() => {
|
|
5978
|
+
node.setVisible(selected);
|
|
5979
|
+
}, [node, selected]);
|
|
5976
5980
|
return null;
|
|
5977
5981
|
}
|
|
5982
|
+
var TabPanel = memo2(function TabPanel2({
|
|
5983
|
+
nodeId,
|
|
5984
|
+
node,
|
|
5985
|
+
rect,
|
|
5986
|
+
visible,
|
|
5987
|
+
isDragging,
|
|
5988
|
+
contentClassName,
|
|
5989
|
+
className,
|
|
5990
|
+
renderTab,
|
|
5991
|
+
onPointerDown
|
|
5992
|
+
}) {
|
|
5993
|
+
const hasValidDimensions = rect.width > 0 && rect.height > 0;
|
|
5994
|
+
const content = useMemo(() => renderTab(node), [renderTab, node]);
|
|
5995
|
+
return /* @__PURE__ */ React20.createElement(
|
|
5996
|
+
"div",
|
|
5997
|
+
{
|
|
5998
|
+
role: "tabpanel",
|
|
5999
|
+
"data-tab-id": nodeId,
|
|
6000
|
+
className: className + (contentClassName ? " " + contentClassName : ""),
|
|
6001
|
+
style: {
|
|
6002
|
+
position: "absolute",
|
|
6003
|
+
display: visible ? "flex" : "none",
|
|
6004
|
+
left: hasValidDimensions ? rect.x : 0,
|
|
6005
|
+
top: hasValidDimensions ? rect.y : 0,
|
|
6006
|
+
width: hasValidDimensions ? rect.width : "100%",
|
|
6007
|
+
height: hasValidDimensions ? rect.height : "100%",
|
|
6008
|
+
overflow: "auto",
|
|
6009
|
+
// Tab panels receive pointer events when visible and not dragging
|
|
6010
|
+
pointerEvents: visible && !isDragging ? "auto" : "none"
|
|
6011
|
+
},
|
|
6012
|
+
onPointerDown
|
|
6013
|
+
},
|
|
6014
|
+
content
|
|
6015
|
+
);
|
|
6016
|
+
});
|
|
5978
6017
|
function TabContainer({
|
|
5979
6018
|
tabs,
|
|
5980
6019
|
renderTab,
|
|
@@ -5982,12 +6021,7 @@ function TabContainer({
|
|
|
5982
6021
|
classNameMapper,
|
|
5983
6022
|
model
|
|
5984
6023
|
}) {
|
|
5985
|
-
const
|
|
5986
|
-
(defaultClassName) => {
|
|
5987
|
-
return classNameMapper ? classNameMapper(defaultClassName) : defaultClassName;
|
|
5988
|
-
},
|
|
5989
|
-
[classNameMapper]
|
|
5990
|
-
);
|
|
6024
|
+
const className = classNameMapper ? classNameMapper("flexlayout__tab") : "flexlayout__tab";
|
|
5991
6025
|
const handlePointerDown = useCallback(
|
|
5992
6026
|
(node) => {
|
|
5993
6027
|
const parent = node.getParent();
|
|
@@ -6016,33 +6050,21 @@ function TabContainer({
|
|
|
6016
6050
|
},
|
|
6017
6051
|
"data-layout-path": "/tab-container"
|
|
6018
6052
|
},
|
|
6019
|
-
Array.from(tabs.entries()).map(([nodeId, tabInfo]) =>
|
|
6020
|
-
|
|
6021
|
-
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
top: hasValidDimensions ? rect.y : 0,
|
|
6035
|
-
width: hasValidDimensions ? rect.width : "100%",
|
|
6036
|
-
height: hasValidDimensions ? rect.height : "100%",
|
|
6037
|
-
overflow: "auto",
|
|
6038
|
-
// Tab panels receive pointer events when visible and not dragging
|
|
6039
|
-
pointerEvents: visible && !isDragging ? "auto" : "none"
|
|
6040
|
-
},
|
|
6041
|
-
onPointerDown: () => handlePointerDown(node)
|
|
6042
|
-
},
|
|
6043
|
-
renderTab(node)
|
|
6044
|
-
);
|
|
6045
|
-
})
|
|
6053
|
+
Array.from(tabs.entries()).map(([nodeId, tabInfo]) => /* @__PURE__ */ React20.createElement(
|
|
6054
|
+
TabPanel,
|
|
6055
|
+
{
|
|
6056
|
+
key: nodeId,
|
|
6057
|
+
nodeId,
|
|
6058
|
+
node: tabInfo.node,
|
|
6059
|
+
rect: tabInfo.rect,
|
|
6060
|
+
visible: tabInfo.visible,
|
|
6061
|
+
isDragging,
|
|
6062
|
+
contentClassName: tabInfo.node.getContentClassName(),
|
|
6063
|
+
className,
|
|
6064
|
+
renderTab,
|
|
6065
|
+
onPointerDown: () => handlePointerDown(tabInfo.node)
|
|
6066
|
+
}
|
|
6067
|
+
))
|
|
6046
6068
|
);
|
|
6047
6069
|
}
|
|
6048
6070
|
function OptimizedLayout({ model, renderTab, classNameMapper, onDragStateChange, onModelChange: userOnModelChange, ...layoutProps }) {
|
|
@@ -6123,18 +6145,32 @@ function OptimizedLayout({ model, renderTab, classNameMapper, onDragStateChange,
|
|
|
6123
6145
|
);
|
|
6124
6146
|
const handleModelChange = useCallback(
|
|
6125
6147
|
(changedModel, action) => {
|
|
6126
|
-
setTabs((prevTabs) =>
|
|
6148
|
+
setTabs((prevTabs) => {
|
|
6149
|
+
const synced = syncTabsWithModel(prevTabs);
|
|
6150
|
+
let hasVisibilityChange = false;
|
|
6151
|
+
const updated = /* @__PURE__ */ new Map();
|
|
6152
|
+
for (const [nodeId, tabInfo] of synced) {
|
|
6153
|
+
const shouldBeVisible = tabInfo.node.isSelected();
|
|
6154
|
+
if (tabInfo.visible !== shouldBeVisible) {
|
|
6155
|
+
hasVisibilityChange = true;
|
|
6156
|
+
updated.set(nodeId, { ...tabInfo, visible: shouldBeVisible });
|
|
6157
|
+
} else {
|
|
6158
|
+
updated.set(nodeId, tabInfo);
|
|
6159
|
+
}
|
|
6160
|
+
}
|
|
6161
|
+
return hasVisibilityChange ? updated : synced;
|
|
6162
|
+
});
|
|
6127
6163
|
userOnModelChange?.(changedModel, action);
|
|
6128
6164
|
},
|
|
6129
6165
|
[syncTabsWithModel, userOnModelChange]
|
|
6130
6166
|
);
|
|
6131
6167
|
const factory = useCallback(
|
|
6132
6168
|
(node) => {
|
|
6133
|
-
return /* @__PURE__ */ React20.createElement(TabRef, { key: node.getId(), node, onTabMount: handleTabMount, onRectChange: handleRectChange, onVisibilityChange: handleVisibilityChange });
|
|
6169
|
+
return /* @__PURE__ */ React20.createElement(TabRef, { key: node.getId(), node, selected: node.isSelected(), onTabMount: handleTabMount, onRectChange: handleRectChange, onVisibilityChange: handleVisibilityChange });
|
|
6134
6170
|
},
|
|
6135
6171
|
[handleTabMount, handleRectChange, handleVisibilityChange]
|
|
6136
6172
|
);
|
|
6137
|
-
return /* @__PURE__ */ React20.createElement(
|
|
6173
|
+
return /* @__PURE__ */ React20.createElement("div", { className: "flexlayout__optimized_layout", style: { position: "absolute", inset: 0, overflow: "hidden" } }, /* @__PURE__ */ React20.createElement(Layout, { model, factory, classNameMapper, onDragStateChange: handleDragStateChange, onModelChange: handleModelChange, ...layoutProps }), /* @__PURE__ */ React20.createElement(TabContainer, { tabs, renderTab, isDragging, classNameMapper, model }));
|
|
6138
6174
|
}
|
|
6139
6175
|
|
|
6140
6176
|
// src/model/walk.ts
|