@headless-tree/core 1.5.0 → 1.5.1

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,5 +1,11 @@
1
1
  # @headless-tree/core
2
2
 
3
+ ## 1.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 08f10f1: Fixed an issue where `isFolder` returns incorrect values for leafs if they are not visibly rendered (#166)
8
+
3
9
  ## 1.5.0
4
10
 
5
11
  ### Minor Changes
@@ -17,6 +23,10 @@
17
23
  - 597faad: Checkbox propagation is now supported for trees with async data loaders!
18
24
  - b0ee382: triggering a data refetch will now always set the loadingItemData/loadingItemChildrens state variable to the associated items if they where not apart of the cache before
19
25
 
26
+ ### Sponsorship appreciation
27
+
28
+ Thanks for [Docmost](https://docmost.com/), who have supported the development of Headless Tree with a sponsor contribution. Docmost is a wiki-software that can be self-hosted or used in cloud. Thank you!
29
+
20
30
  ## 1.4.0
21
31
 
22
32
  ### Minor Changes
package/dist/index.js CHANGED
@@ -303,7 +303,7 @@ var treeFeature = {
303
303
  );
304
304
  },
305
305
  isFocused: ({ tree, item, itemId }) => tree.getState().focusedItem === itemId || tree.getState().focusedItem === null && item.getItemMeta().index === 0,
306
- isFolder: ({ tree, item }) => item.getItemMeta().level === -1 || tree.getConfig().isItemFolder(item),
306
+ isFolder: ({ tree, item, itemId }) => itemId === tree.getConfig().rootItemId || tree.getConfig().isItemFolder(item),
307
307
  getItemName: ({ tree, item }) => {
308
308
  const config = tree.getConfig();
309
309
  return config.getItemName(item);
@@ -1007,7 +1007,8 @@ var specialKeys = {
1007
1007
  minus: /^(NumpadSubtract|Minus)$/,
1008
1008
  control: /^(ControlLeft|ControlRight)$/,
1009
1009
  shift: /^(ShiftLeft|ShiftRight)$/,
1010
- metaorcontrol: /^(MetaLeft|MetaRight|ControlLeft|ControlRight)$/
1010
+ metaorcontrol: /^(MetaLeft|MetaRight|ControlLeft|ControlRight)$/,
1011
+ enter: /^(Enter|NumpadEnter)$/
1011
1012
  };
1012
1013
  var testHotkeyMatch = (pressedKeys, tree, hotkey) => {
1013
1014
  const supposedKeys = hotkey.hotkey.toLowerCase().split("+");
package/dist/index.mjs CHANGED
@@ -259,7 +259,7 @@ var treeFeature = {
259
259
  );
260
260
  },
261
261
  isFocused: ({ tree, item, itemId }) => tree.getState().focusedItem === itemId || tree.getState().focusedItem === null && item.getItemMeta().index === 0,
262
- isFolder: ({ tree, item }) => item.getItemMeta().level === -1 || tree.getConfig().isItemFolder(item),
262
+ isFolder: ({ tree, item, itemId }) => itemId === tree.getConfig().rootItemId || tree.getConfig().isItemFolder(item),
263
263
  getItemName: ({ tree, item }) => {
264
264
  const config = tree.getConfig();
265
265
  return config.getItemName(item);
@@ -963,7 +963,8 @@ var specialKeys = {
963
963
  minus: /^(NumpadSubtract|Minus)$/,
964
964
  control: /^(ControlLeft|ControlRight)$/,
965
965
  shift: /^(ShiftLeft|ShiftRight)$/,
966
- metaorcontrol: /^(MetaLeft|MetaRight|ControlLeft|ControlRight)$/
966
+ metaorcontrol: /^(MetaLeft|MetaRight|ControlLeft|ControlRight)$/,
967
+ enter: /^(Enter|NumpadEnter)$/
967
968
  };
968
969
  var testHotkeyMatch = (pressedKeys, tree, hotkey) => {
969
970
  const supposedKeys = hotkey.hotkey.toLowerCase().split("+");
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "checkbox",
14
14
  "hook"
15
15
  ],
16
- "version": "1.5.0",
16
+ "version": "1.5.1",
17
17
  "main": "dist/index.d.ts",
18
18
  "module": "dist/index.mjs",
19
19
  "types": "dist/index.d.mts",
@@ -14,6 +14,7 @@ const specialKeys: Record<string, RegExp> = {
14
14
  control: /^(ControlLeft|ControlRight)$/,
15
15
  shift: /^(ShiftLeft|ShiftRight)$/,
16
16
  metaorcontrol: /^(MetaLeft|MetaRight|ControlLeft|ControlRight)$/,
17
+ enter: /^(Enter|NumpadEnter)$/,
17
18
  };
18
19
 
19
20
  const testHotkeyMatch = (
@@ -203,8 +203,8 @@ export const treeFeature: FeatureImplementation<any> = {
203
203
  isFocused: ({ tree, item, itemId }) =>
204
204
  tree.getState().focusedItem === itemId ||
205
205
  (tree.getState().focusedItem === null && item.getItemMeta().index === 0),
206
- isFolder: ({ tree, item }) =>
207
- item.getItemMeta().level === -1 ||
206
+ isFolder: ({ tree, item, itemId }) =>
207
+ itemId === tree.getConfig().rootItemId ||
208
208
  tree.getConfig().isItemFolder(item as ItemInstance<any>),
209
209
  getItemName: ({ tree, item }) => {
210
210
  const config = tree.getConfig();
@@ -4,8 +4,8 @@ import { propMemoizationFeature } from "../prop-memoization/feature";
4
4
 
5
5
  const factory = TestTree.default({}).withFeatures(propMemoizationFeature);
6
6
 
7
- describe("core-feature/selections", () => {
8
- factory.forSuits((tree) => {
7
+ describe("core-feature/tree", () => {
8
+ factory.forSuits((tree, title) => {
9
9
  describe("expanded items", () => {
10
10
  it("can expand via tree instance", () => {
11
11
  const setExpandedItems = tree.mockedHandler("setExpandedItems");
@@ -156,6 +156,17 @@ describe("core-feature/selections", () => {
156
156
  });
157
157
  });
158
158
 
159
+ it("unloaded item", () => {
160
+ expect(tree.instance.getItemInstance("x444").getItemMeta()).toEqual({
161
+ index: -1,
162
+ itemId: "x444",
163
+ level: -1,
164
+ parentId: null,
165
+ posInSet: 0,
166
+ setSize: 1,
167
+ });
168
+ });
169
+
159
170
  it("expanded container", () => {
160
171
  expect(tree.instance.getItemInstance("x11").getItemMeta()).toEqual({
161
172
  index: 1,
@@ -312,8 +323,30 @@ describe("core-feature/selections", () => {
312
323
  expect(tree.instance.getItemInstance("x1").isFolder()).toBe(true);
313
324
  });
314
325
 
315
- it("returns correctly for false cases of isFolder()", () => {
316
- expect(tree.instance.getItemInstance("x111").isFolder()).toBe(false);
326
+ it("returns correctly for true cases of isFolder() ", () => {
327
+ expect(tree.instance.getItemInstance("x1").isFolder()).toBe(true);
328
+ });
329
+
330
+ it("returns correct isFolder for hidden items", async () => {
331
+ if (title.toLocaleLowerCase().includes("async")) {
332
+ // async test tree defaults to "loading" item names
333
+ return;
334
+ }
335
+ const testTree = await tree
336
+ .with({
337
+ isItemFolder: (item: any) => item.getItemData().length < 4,
338
+ })
339
+ .createTestCaseTree();
340
+
341
+ // Reference: https://github.com/lukasbach/headless-tree/issues/166
342
+ expect(testTree.instance.getItemInstance("x44").isFolder()).toBe(true);
343
+ expect(testTree.instance.getItemInstance("x444").isFolder()).toBe(
344
+ false,
345
+ );
346
+ });
347
+
348
+ it("returns isFolder=true for root item", () => {
349
+ expect(tree.instance.getItemInstance("x").isFolder()).toBe(true);
317
350
  });
318
351
 
319
352
  it("returns correctly for getParent()", () => {
@@ -63,15 +63,15 @@ export class TestTree<T = string> {
63
63
  }),
64
64
  };
65
65
 
66
- forSuits(runSuite: (tree: TestTree<T>) => void) {
66
+ forSuits(runSuite: (tree: TestTree<T>, title: string) => void) {
67
67
  describe.for([
68
68
  this.suits.sync(),
69
69
  this.suits.async(),
70
70
  this.suits.proxifiedSync(),
71
71
  this.suits.proxifiedAsync(),
72
- ])("$title", ({ tree }) => {
72
+ ])("$title", ({ tree, title }) => {
73
73
  tree.resetBeforeEach();
74
- runSuite(tree);
74
+ runSuite(tree, title);
75
75
  });
76
76
  }
77
77