@headless-tree/core 0.0.0-20250912163308 → 0.0.0-20250916205935

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/CHANGELOG.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # @headless-tree/core
2
2
 
3
- ## 0.0.0-20250912163308
3
+ ## 0.0.0-20250916205935
4
4
 
5
5
  ### Patch Changes
6
6
 
7
7
  - 72e714b: all NPM deployments will now publish with provenance
8
+ - 6693986: fixed an issue where async data loaders cause calling `item.getItemData()` outside of the component calling `useTree()` to cause a React warning log (#158)
9
+ - 7a7424f: fixed incorrect exports definition in package.json for require/cjs imports (#161)
8
10
  - 215ab4b: add a new symbol that can be used in hotkey configurations "metaorcontrol" that will trigger if either any windows control key or mac meta key is pressed (#141)
9
11
  - 51b0dea: Added `isUnorderedDragTarget` as alternative to `isDragTarget` for easier detection of drag type
10
12
  - cf845d7: Added new state variable `loadingCheckPropagationItems` to indicate if, in async trees with checkboxes and state propagation enabled, data loading operations are currently loading due to a checkbox propagation taking place
package/dist/index.d.mts CHANGED
@@ -182,6 +182,8 @@ type MainFeatureDef<T = any> = {
182
182
  };
183
183
  getHotkeyPresets: () => HotkeysConfig<T>;
184
184
  rebuildTree: () => void;
185
+ /** @deprecated Experimental feature, might get removed or changed in the future. */
186
+ scheduleRebuildTree: () => void;
185
187
  };
186
188
  itemInstance: {
187
189
  registerElement: (element: HTMLElement | null) => void;
package/dist/index.d.ts CHANGED
@@ -182,6 +182,8 @@ type MainFeatureDef<T = any> = {
182
182
  };
183
183
  getHotkeyPresets: () => HotkeysConfig<T>;
184
184
  rebuildTree: () => void;
185
+ /** @deprecated Experimental feature, might get removed or changed in the future. */
186
+ scheduleRebuildTree: () => void;
185
187
  };
186
188
  itemInstance: {
187
189
  registerElement: (element: HTMLElement | null) => void;
package/dist/index.js CHANGED
@@ -485,6 +485,7 @@ var createTree = (initialConfig) => {
485
485
  );
486
486
  let treeElement;
487
487
  const treeDataRef = { current: {} };
488
+ let rebuildScheduled = false;
488
489
  const itemInstancesMap = {};
489
490
  let itemInstances = [];
490
491
  const itemElementsMap = {};
@@ -528,6 +529,7 @@ var createTree = (initialConfig) => {
528
529
  itemInstances.push(itemInstancesMap[item.itemId]);
529
530
  }
530
531
  }
532
+ rebuildScheduled = false;
531
533
  };
532
534
  const eachFeature = (fn) => {
533
535
  for (const feature of additionalFeatures) {
@@ -553,6 +555,9 @@ var createTree = (initialConfig) => {
553
555
  rebuildItemMeta();
554
556
  (_a2 = config.setState) == null ? void 0 : _a2.call(config, state);
555
557
  },
558
+ scheduleRebuildTree: () => {
559
+ rebuildScheduled = true;
560
+ },
556
561
  getConfig: () => config,
557
562
  setConfig: (_, updater) => {
558
563
  var _a2, _b2, _c2;
@@ -584,7 +589,10 @@ var createTree = (initialConfig) => {
584
589
  }
585
590
  return existingInstance;
586
591
  },
587
- getItems: () => itemInstances,
592
+ getItems: () => {
593
+ if (rebuildScheduled) rebuildItemMeta();
594
+ return itemInstances;
595
+ },
588
596
  registerElement: ({}, element) => {
589
597
  if (treeElement === element) {
590
598
  return;
@@ -1161,7 +1169,7 @@ var asyncDataLoaderFeature = {
1161
1169
  return dataRef.current.itemData[itemId];
1162
1170
  }
1163
1171
  if (!tree.getState().loadingItemData.includes(itemId) && !skipFetch) {
1164
- loadItemData(tree, itemId);
1172
+ setTimeout(() => loadItemData(tree, itemId));
1165
1173
  }
1166
1174
  return (_b = (_a = config.createLoadingItemData) == null ? void 0 : _a.call(config)) != null ? _b : null;
1167
1175
  },
@@ -1173,7 +1181,7 @@ var asyncDataLoaderFeature = {
1173
1181
  if (tree.getState().loadingItemChildrens.includes(itemId) || skipFetch) {
1174
1182
  return [];
1175
1183
  }
1176
- loadChildrenIds(tree, itemId);
1184
+ setTimeout(() => loadChildrenIds(tree, itemId));
1177
1185
  return [];
1178
1186
  }
1179
1187
  },
package/dist/index.mjs CHANGED
@@ -441,6 +441,7 @@ var createTree = (initialConfig) => {
441
441
  );
442
442
  let treeElement;
443
443
  const treeDataRef = { current: {} };
444
+ let rebuildScheduled = false;
444
445
  const itemInstancesMap = {};
445
446
  let itemInstances = [];
446
447
  const itemElementsMap = {};
@@ -484,6 +485,7 @@ var createTree = (initialConfig) => {
484
485
  itemInstances.push(itemInstancesMap[item.itemId]);
485
486
  }
486
487
  }
488
+ rebuildScheduled = false;
487
489
  };
488
490
  const eachFeature = (fn) => {
489
491
  for (const feature of additionalFeatures) {
@@ -509,6 +511,9 @@ var createTree = (initialConfig) => {
509
511
  rebuildItemMeta();
510
512
  (_a2 = config.setState) == null ? void 0 : _a2.call(config, state);
511
513
  },
514
+ scheduleRebuildTree: () => {
515
+ rebuildScheduled = true;
516
+ },
512
517
  getConfig: () => config,
513
518
  setConfig: (_, updater) => {
514
519
  var _a2, _b2, _c2;
@@ -540,7 +545,10 @@ var createTree = (initialConfig) => {
540
545
  }
541
546
  return existingInstance;
542
547
  },
543
- getItems: () => itemInstances,
548
+ getItems: () => {
549
+ if (rebuildScheduled) rebuildItemMeta();
550
+ return itemInstances;
551
+ },
544
552
  registerElement: ({}, element) => {
545
553
  if (treeElement === element) {
546
554
  return;
@@ -1117,7 +1125,7 @@ var asyncDataLoaderFeature = {
1117
1125
  return dataRef.current.itemData[itemId];
1118
1126
  }
1119
1127
  if (!tree.getState().loadingItemData.includes(itemId) && !skipFetch) {
1120
- loadItemData(tree, itemId);
1128
+ setTimeout(() => loadItemData(tree, itemId));
1121
1129
  }
1122
1130
  return (_b = (_a = config.createLoadingItemData) == null ? void 0 : _a.call(config)) != null ? _b : null;
1123
1131
  },
@@ -1129,7 +1137,7 @@ var asyncDataLoaderFeature = {
1129
1137
  if (tree.getState().loadingItemChildrens.includes(itemId) || skipFetch) {
1130
1138
  return [];
1131
1139
  }
1132
- loadChildrenIds(tree, itemId);
1140
+ setTimeout(() => loadChildrenIds(tree, itemId));
1133
1141
  return [];
1134
1142
  }
1135
1143
  },
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "checkbox",
14
14
  "hook"
15
15
  ],
16
- "version": "0.0.0-20250912163308",
16
+ "version": "0.0.0-20250916205935",
17
17
  "main": "dist/index.d.ts",
18
18
  "module": "dist/index.mjs",
19
19
  "types": "dist/index.d.mts",
@@ -24,8 +24,8 @@
24
24
  "default": "./dist/index.mjs"
25
25
  },
26
26
  "require": {
27
- "types": "./dist/index.js",
28
- "default": "./dist/index.d.ts"
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
29
  }
30
30
  },
31
31
  "./package.json": "./package.json"
@@ -92,6 +92,7 @@ export const createTree = <T>(
92
92
  let treeElement: HTMLElement | undefined | null;
93
93
  const treeDataRef: { current: any } = { current: {} };
94
94
 
95
+ let rebuildScheduled = false;
95
96
  const itemInstancesMap: Record<string, ItemInstance<T>> = {};
96
97
  let itemInstances: ItemInstance<T>[] = [];
97
98
  const itemElementsMap: Record<string, HTMLElement | undefined | null> = {};
@@ -140,6 +141,8 @@ export const createTree = <T>(
140
141
  itemInstances.push(itemInstancesMap[item.itemId]);
141
142
  }
142
143
  }
144
+
145
+ rebuildScheduled = false;
143
146
  };
144
147
 
145
148
  const eachFeature = (fn: (feature: FeatureImplementation<any>) => void) => {
@@ -175,6 +178,9 @@ export const createTree = <T>(
175
178
  rebuildItemMeta();
176
179
  config.setState?.(state);
177
180
  },
181
+ scheduleRebuildTree: () => {
182
+ rebuildScheduled = true;
183
+ },
178
184
  getConfig: () => config,
179
185
  setConfig: (_, updater) => {
180
186
  const newConfig =
@@ -210,7 +216,10 @@ export const createTree = <T>(
210
216
  }
211
217
  return existingInstance;
212
218
  },
213
- getItems: () => itemInstances,
219
+ getItems: () => {
220
+ if (rebuildScheduled) rebuildItemMeta();
221
+ return itemInstances;
222
+ },
214
223
  registerElement: ({}, element) => {
215
224
  if (treeElement === element) {
216
225
  return;
@@ -46,6 +46,7 @@ describe("core-feature/selections", () => {
46
46
  );
47
47
  const setLoadingItemData = tree.mockedHandler("setLoadingItemData");
48
48
  tree.do.selectItem("x12");
49
+ await tree.do.awaitNextTick();
49
50
  expect(setLoadingItemChildrens).toHaveBeenCalledWith(["x12"]);
50
51
  expect(setLoadingItemData).not.toHaveBeenCalled();
51
52
  await tree.resolveAsyncVisibleItems();
@@ -118,7 +118,7 @@ export const asyncDataLoaderFeature: FeatureImplementation = {
118
118
  }
119
119
 
120
120
  if (!tree.getState().loadingItemData.includes(itemId) && !skipFetch) {
121
- loadItemData(tree, itemId);
121
+ setTimeout(() => loadItemData(tree, itemId));
122
122
  }
123
123
 
124
124
  return config.createLoadingItemData?.() ?? null;
@@ -134,7 +134,7 @@ export const asyncDataLoaderFeature: FeatureImplementation = {
134
134
  return [];
135
135
  }
136
136
 
137
- loadChildrenIds(tree, itemId);
137
+ setTimeout(() => loadChildrenIds(tree, itemId));
138
138
 
139
139
  return [];
140
140
  },
@@ -49,6 +49,8 @@ export type MainFeatureDef<T = any> = {
49
49
  /* @internal */
50
50
  getHotkeyPresets: () => HotkeysConfig<T>;
51
51
  rebuildTree: () => void;
52
+ /** @deprecated Experimental feature, might get removed or changed in the future. */
53
+ scheduleRebuildTree: () => void;
52
54
  };
53
55
  itemInstance: {
54
56
  registerElement: (element: HTMLElement | null) => void;
@@ -135,4 +135,10 @@ export class TestTreeDo<T> {
135
135
  "function called with inconsistent parameters",
136
136
  ).toBeOneOf([0, 1]);
137
137
  }
138
+
139
+ async awaitNextTick() {
140
+ await new Promise((r) => {
141
+ setTimeout(r);
142
+ });
143
+ }
138
144
  }
@@ -87,10 +87,9 @@ export class TestTree<T = string> {
87
87
 
88
88
  static async resolveAsyncLoaders() {
89
89
  do {
90
+ await vi.advanceTimersToNextTimerAsync();
90
91
  TestTree.asyncLoaderResolvers.shift()?.();
91
- await new Promise<void>((r) => {
92
- setTimeout(r);
93
- });
92
+ await vi.advanceTimersToNextTimerAsync();
94
93
  } while (TestTree.asyncLoaderResolvers.length);
95
94
  }
96
95