schummar-table 1.0.0-beta.5 → 1.0.0-beta.6

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.cjs CHANGED
@@ -269,42 +269,61 @@ function useColumns(props, displaySize) {
269
269
  //#region src/state/useExpanded.ts
270
270
  function useExpanded(props, itemsById, matching) {
271
271
  const [value, setExpanded, setExpandedInternal] = useControllableState(props.expanded, () => props.defaultExpanded ?? /* @__PURE__ */ new Set(), props.onExpandedChange);
272
- return {
273
- expanded: useNormalized(value, (0, react.useMemo)(() => {
274
- let result = value;
275
- const add = (id) => {
276
- if (result.has(id)) return;
272
+ const expanded = useNormalized(value, (0, react.useMemo)(() => {
273
+ let result = value;
274
+ const add = (id) => {
275
+ if (result.has(id)) return;
276
+ if (result === value) result = new Set(value);
277
+ result.add(id);
278
+ };
279
+ if (props.expandOnlyOne && value.size > 1) {
280
+ const deepest = [...value].map((id) => itemsById.get(id)).filter((item) => item !== void 0).sort((a, b) => b.depth - a.depth)[0];
281
+ const branch = deepest ? require_useTheme.getAncestors(itemsById, deepest).add(deepest.id) : /* @__PURE__ */ new Set();
282
+ if ([...value].some((id) => !branch.has(id))) return branch;
283
+ }
284
+ for (const id of value) {
285
+ const item = itemsById.get(id);
286
+ if (item) require_useTheme.getAncestors(itemsById, item).forEach(add);
287
+ }
288
+ if (props.items !== void 0) {
289
+ for (const id of value) if (!itemsById.has(id)) {
277
290
  if (result === value) result = new Set(value);
278
- result.add(id);
279
- };
280
- if (props.expandOnlyOne && value.size > 1) {
281
- const deepest = [...value].map((id) => itemsById.get(id)).filter((item) => item !== void 0).sort((a, b) => b.depth - a.depth)[0];
282
- const branch = deepest ? require_useTheme.getAncestors(itemsById, deepest).add(deepest.id) : /* @__PURE__ */ new Set();
283
- if ([...value].some((id) => !branch.has(id))) return branch;
284
- }
285
- for (const id of value) {
286
- const item = itemsById.get(id);
287
- if (item) require_useTheme.getAncestors(itemsById, item).forEach(add);
288
- }
289
- if (props.items !== void 0) {
290
- for (const id of value) if (!itemsById.has(id)) {
291
- if (result === value) result = new Set(value);
292
- result.delete(id);
293
- }
291
+ result.delete(id);
294
292
  }
295
- if (props.revealFiltered && matching) for (const id of matching) {
296
- const parentId = itemsById.get(id)?.parentId;
297
- if (parentId !== void 0 && parentId !== null) add(parentId);
298
- }
299
- return result;
300
- }, [
301
- value,
302
- itemsById,
303
- matching,
304
- props.items,
305
- props.expandOnlyOne,
306
- props.revealFiltered
307
- ]), setExpanded),
293
+ }
294
+ return result;
295
+ }, [
296
+ value,
297
+ itemsById,
298
+ props.items,
299
+ props.expandOnlyOne
300
+ ]), setExpanded);
301
+ const latest = (0, react.useRef)({
302
+ expanded,
303
+ itemsById
304
+ });
305
+ (0, react.useEffect)(() => {
306
+ latest.current = {
307
+ expanded,
308
+ itemsById
309
+ };
310
+ });
311
+ (0, react.useEffect)(() => {
312
+ if (!props.revealFiltered || !matching) return;
313
+ const { expanded, itemsById } = latest.current;
314
+ const next = new Set(expanded);
315
+ for (const id of matching) {
316
+ const parentId = itemsById.get(id)?.parentId;
317
+ if (parentId !== void 0 && parentId !== null) next.add(parentId);
318
+ }
319
+ if (next.size > expanded.size) setExpanded(next);
320
+ }, [
321
+ matching,
322
+ props.revealFiltered,
323
+ setExpanded
324
+ ]);
325
+ return {
326
+ expanded,
308
327
  setExpanded,
309
328
  setExpandedInternal
310
329
  };