@principal-ade/dynamic-file-tree 0.1.27 → 0.1.29

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 CHANGED
@@ -969,6 +969,7 @@ import {
969
969
  } from "lucide-react";
970
970
  import React7, { useMemo as useMemo5 } from "react";
971
971
  import { Tree as Tree2 } from "react-arborist";
972
+ var GitStatusContext = React7.createContext(null);
972
973
  var getGitStatusDisplay2 = (status, theme) => {
973
974
  switch (status) {
974
975
  case "M":
@@ -1049,38 +1050,38 @@ var sortGitNodes = (a, b) => {
1049
1050
  return 1;
1050
1051
  return a.name.localeCompare(b.name, undefined, { sensitivity: "base" });
1051
1052
  };
1052
- var transformGitFileTree = (fileTree, gitStatusMap) => {
1053
+ var transformTreeStructure = (fileTree) => {
1053
1054
  const transformNode = (node, parentId) => {
1054
1055
  const id = parentId ? `${parentId}/${node.name}` : node.name;
1055
- const gitStatus = gitStatusMap.get(id);
1056
1056
  const arborNode = {
1057
1057
  id,
1058
- name: node.name,
1059
- gitStatus
1058
+ name: node.name
1060
1059
  };
1061
1060
  if ("children" in node && node.children) {
1062
1061
  arborNode.children = node.children.map((child) => transformNode(child, id)).sort(sortGitNodes);
1063
- if (arborNode.children) {
1064
- const hasChangedChildren = arborNode.children.some((child) => child.gitStatus || child.hasChangedChildren);
1065
- arborNode.hasChangedChildren = hasChangedChildren;
1066
- }
1067
1062
  }
1068
1063
  return arborNode;
1069
1064
  };
1070
1065
  return fileTree.root.children.map((node) => transformNode(node, "")).sort(sortGitNodes);
1071
1066
  };
1072
- var filterGitStatusNodes = (nodes, showUnchangedFiles) => {
1073
- if (showUnchangedFiles)
1074
- return nodes;
1067
+ var filterGitStatusNodes = (nodes, gitStatusMap) => {
1075
1068
  const result = [];
1069
+ const hasGitChanges = (node) => {
1070
+ if (gitStatusMap.has(node.id))
1071
+ return true;
1072
+ if (node.children) {
1073
+ return node.children.some((child) => hasGitChanges(child));
1074
+ }
1075
+ return false;
1076
+ };
1076
1077
  for (const node of nodes) {
1077
1078
  if (node.children) {
1078
- if (node.gitStatus || node.hasChangedChildren) {
1079
- const filteredChildren = filterGitStatusNodes(node.children, showUnchangedFiles);
1079
+ if (hasGitChanges(node)) {
1080
+ const filteredChildren = filterGitStatusNodes(node.children, gitStatusMap);
1080
1081
  result.push({ ...node, children: filteredChildren });
1081
1082
  }
1082
1083
  } else {
1083
- if (node.gitStatus) {
1084
+ if (gitStatusMap.has(node.id)) {
1084
1085
  result.push(node);
1085
1086
  }
1086
1087
  }
@@ -1104,7 +1105,7 @@ var GitStatusFileTree = ({
1104
1105
  fileTree,
1105
1106
  theme,
1106
1107
  gitStatusData,
1107
- selectedDirectories = [],
1108
+ selectedDirectories: _selectedDirectories = [],
1108
1109
  selectedFile,
1109
1110
  onDirectorySelect,
1110
1111
  onFileSelect,
@@ -1125,11 +1126,14 @@ var GitStatusFileTree = ({
1125
1126
  }, [gitStatusData]);
1126
1127
  const NodeRenderer = (props) => {
1127
1128
  const { node } = props;
1128
- const gitDisplay = node.data.gitStatus ? getGitStatusDisplay2(node.data.gitStatus, theme) : null;
1129
+ const ctx = React7.useContext(GitStatusContext);
1130
+ const gitStatus = ctx?.gitStatusMap.get(node.data.id);
1131
+ const hasChangedChildren = ctx?.hasChangedChildrenMap.get(node.data.id);
1132
+ const gitDisplay = gitStatus ? getGitStatusDisplay2(gitStatus, theme) : null;
1129
1133
  let nameColor;
1130
1134
  if (gitDisplay) {
1131
1135
  nameColor = gitDisplay.color;
1132
- } else if (node.data.hasChangedChildren) {
1136
+ } else if (hasChangedChildren) {
1133
1137
  const baseColor = theme.colors.primary || "#007bff";
1134
1138
  nameColor = baseColor + "80";
1135
1139
  }
@@ -1147,7 +1151,7 @@ var GitStatusFileTree = ({
1147
1151
  fontSize: "12px",
1148
1152
  fontWeight: "bold"
1149
1153
  }
1150
- }, node.data.gitStatus)) : null;
1154
+ }, gitStatus)) : null;
1151
1155
  return /* @__PURE__ */ React7.createElement(TreeNode, {
1152
1156
  ...props,
1153
1157
  theme,
@@ -1161,14 +1165,36 @@ var GitStatusFileTree = ({
1161
1165
  }
1162
1166
  });
1163
1167
  };
1168
+ const treeStructure = useMemo5(() => {
1169
+ return transformTreeStructure(fileTree);
1170
+ }, [fileTree]);
1164
1171
  const treeData = useMemo5(() => {
1165
- let transformedData = transformGitFileTree(fileTree, gitStatusMap);
1166
- if (!showUnchangedFiles) {
1167
- transformedData = filterGitStatusNodes(transformedData, showUnchangedFiles);
1172
+ if (showUnchangedFiles) {
1173
+ return treeStructure;
1168
1174
  }
1169
- if (selectedDirectories && selectedDirectories.length > 0) {}
1170
- return transformedData;
1171
- }, [fileTree, gitStatusMap, showUnchangedFiles, selectedDirectories]);
1175
+ return filterGitStatusNodes(treeStructure, gitStatusMap);
1176
+ }, [treeStructure, showUnchangedFiles, gitStatusMap]);
1177
+ const hasChangedChildrenMap = useMemo5(() => {
1178
+ const map = new Map;
1179
+ const markChangedParents = (nodes) => {
1180
+ let hasChanged = false;
1181
+ for (const node of nodes) {
1182
+ if (node.children) {
1183
+ const childrenChanged = markChangedParents(node.children);
1184
+ if (childrenChanged) {
1185
+ map.set(node.id, true);
1186
+ hasChanged = true;
1187
+ }
1188
+ }
1189
+ if (gitStatusMap.has(node.id)) {
1190
+ hasChanged = true;
1191
+ }
1192
+ }
1193
+ return hasChanged;
1194
+ };
1195
+ markChangedParents(treeData);
1196
+ return map;
1197
+ }, [treeData, gitStatusMap]);
1172
1198
  const handleSelect = (selectedNodes) => {
1173
1199
  const selectedFiles = selectedNodes.filter((node) => !node.data.children).map((node) => node.data.id);
1174
1200
  const selectedDirs = selectedNodes.filter((node) => node.data.children).map((node) => node.data.id);
@@ -1196,15 +1222,17 @@ var GitStatusFileTree = ({
1196
1222
  fontFamily: theme.fonts.body,
1197
1223
  ...autoHeight ? {} : { height: "100%" }
1198
1224
  }
1225
+ }, /* @__PURE__ */ React7.createElement(GitStatusContext.Provider, {
1226
+ value: { gitStatusMap, hasChangedChildrenMap }
1199
1227
  }, /* @__PURE__ */ React7.createElement(Tree2, {
1200
- initialData: treeData,
1228
+ data: treeData,
1201
1229
  onSelect: handleSelect,
1202
1230
  ...selectedFile !== undefined && { selection: selectedFile },
1203
1231
  ...openByDefault !== undefined && { openByDefault },
1204
1232
  width: "100%",
1205
1233
  height: containerHeight,
1206
1234
  rowHeight: 28
1207
- }, NodeRenderer));
1235
+ }, NodeRenderer)));
1208
1236
  };
1209
1237
  // src/components/GitStatusFileTreeContainer.tsx
1210
1238
  import { RefreshCw, Eye, EyeOff, AlertCircle as AlertCircle3 } from "lucide-react";
@@ -1 +1 @@
1
- {"version":3,"file":"GitStatusFileTree.d.ts","sourceRoot":"","sources":["../../../src/components/GitStatusFileTree.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,QAAQ,EAAgB,MAAM,sCAAsC,CAAC;AAS9E,OAAO,KAAkB,MAAM,OAAO,CAAC;AAQvC,MAAM,MAAM,SAAS,GACjB,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,CAAC;AAGT,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,MAAM,EAAE,SAAS,CAAC;CACnB;AAaD,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,aAAa,EAAE,CAAC;IAC/B,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;I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AC;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iBAAiB,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACpD,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IACvF,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AA0JD,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAsL9D,CAAC"}
@@ -19,4 +19,5 @@ export declare const TerminalTheme: Story;
19
19
  export declare const MatrixTheme: Story;
20
20
  export declare const MatrixMinimalTheme: Story;
21
21
  export declare const SlateTheme: Story;
22
+ export declare const RapidStatusChanges: Story;
22
23
  //# sourceMappingURL=GitStatusFileTree.stories.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GitStatusFileTree.stories.d.ts","sourceRoot":"","sources":["../../../src/components/GitStatusFileTree.stories.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,EAAE,iBAAiB,EAAiB,MAAM,qBAAqB,CAAC;AA8OvE,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,iBAAiB,CASxC,CAAC;AAEF,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAEhD,eAAO,MAAM,OAA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AAC;AAoDF,eAAO,MAAM,cAAc,EAAE,KAe5B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAe7B,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,KAe5B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAe7B,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,KAe1B,CAAC;AAKF,eAAO,MAAM,eAAe,EAAE,KAyB7B,CAAC;AAIF,eAAO,MAAM,eAAe,EAAE,KAwD7B,CAAC;AAIF,eAAO,MAAM,UAAU,EAAE,KAexB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,KAe3B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,KAezB,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,KAehC,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,KAexB,CAAC;AAqGF,eAAO,MAAM,kBAAkB,EAAE,KAuBhC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principal-ade/dynamic-file-tree",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "description": "React component for selective directory filtering and file tree visualization",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",