react-science 15.0.0 → 16.1.0

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.
Files changed (120) hide show
  1. package/lib/components/accordion/accordion.d.ts +29 -7
  2. package/lib/components/accordion/accordion.d.ts.map +1 -1
  3. package/lib/components/accordion/accordion.js +24 -9
  4. package/lib/components/accordion/accordion.js.map +1 -1
  5. package/lib/components/accordion/accordion_context.d.ts +8 -15
  6. package/lib/components/accordion/accordion_context.d.ts.map +1 -1
  7. package/lib/components/accordion/accordion_context.js +7 -25
  8. package/lib/components/accordion/accordion_context.js.map +1 -1
  9. package/lib/components/accordion/accordion_context_provider.d.ts +7 -0
  10. package/lib/components/accordion/accordion_context_provider.d.ts.map +1 -0
  11. package/lib/components/accordion/accordion_context_provider.js +62 -0
  12. package/lib/components/accordion/accordion_context_provider.js.map +1 -0
  13. package/lib/components/accordion/accordion_context_utils.d.ts +15 -0
  14. package/lib/components/accordion/accordion_context_utils.d.ts.map +1 -0
  15. package/lib/components/accordion/accordion_context_utils.js +4 -0
  16. package/lib/components/accordion/accordion_context_utils.js.map +1 -0
  17. package/lib/components/accordion/accordion_hooks.d.ts +8 -0
  18. package/lib/components/accordion/accordion_hooks.d.ts.map +1 -0
  19. package/lib/components/accordion/accordion_hooks.js +16 -0
  20. package/lib/components/accordion/accordion_hooks.js.map +1 -0
  21. package/lib/components/accordion/index.d.ts +2 -3
  22. package/lib/components/accordion/index.d.ts.map +1 -1
  23. package/lib/components/accordion/index.js +2 -3
  24. package/lib/components/accordion/index.js.map +1 -1
  25. package/lib/components/table/flash_row/flashed_row_context.d.ts +3 -0
  26. package/lib/components/table/flash_row/flashed_row_context.d.ts.map +1 -0
  27. package/lib/components/table/flash_row/flashed_row_context.js +10 -0
  28. package/lib/components/table/flash_row/flashed_row_context.js.map +1 -0
  29. package/lib/components/table/{reorder_rows/dropped_item_provider.d.ts → flash_row/flashed_row_provider.d.ts} +2 -2
  30. package/lib/components/table/flash_row/flashed_row_provider.d.ts.map +1 -0
  31. package/lib/components/table/flash_row/flashed_row_provider.js +8 -0
  32. package/lib/components/table/flash_row/flashed_row_provider.js.map +1 -0
  33. package/lib/components/table/flash_row/use_flash_row_effect.d.ts +3 -0
  34. package/lib/components/table/flash_row/use_flash_row_effect.d.ts.map +1 -0
  35. package/lib/components/table/flash_row/use_flash_row_effect.js +21 -0
  36. package/lib/components/table/flash_row/use_flash_row_effect.js.map +1 -0
  37. package/lib/components/table/index.d.ts +1 -0
  38. package/lib/components/table/index.d.ts.map +1 -1
  39. package/lib/components/table/index.js +1 -0
  40. package/lib/components/table/index.js.map +1 -1
  41. package/lib/components/table/preview_table.d.ts +5 -0
  42. package/lib/components/table/preview_table.d.ts.map +1 -0
  43. package/lib/components/table/preview_table.js +8 -0
  44. package/lib/components/table/preview_table.js.map +1 -0
  45. package/lib/components/table/preview_table_context.d.ts +9 -0
  46. package/lib/components/table/preview_table_context.d.ts.map +1 -0
  47. package/lib/components/table/preview_table_context.js +15 -0
  48. package/lib/components/table/preview_table_context.js.map +1 -0
  49. package/lib/components/table/reorder_rows/draggable_row_tr.d.ts +3 -3
  50. package/lib/components/table/reorder_rows/draggable_row_tr.d.ts.map +1 -1
  51. package/lib/components/table/reorder_rows/draggable_row_tr.js +14 -20
  52. package/lib/components/table/reorder_rows/draggable_row_tr.js.map +1 -1
  53. package/lib/components/table/reorder_rows/table_drag_row_handler.d.ts +3 -1
  54. package/lib/components/table/reorder_rows/table_drag_row_handler.d.ts.map +1 -1
  55. package/lib/components/table/reorder_rows/table_drag_row_handler.js +12 -2
  56. package/lib/components/table/reorder_rows/table_drag_row_handler.js.map +1 -1
  57. package/lib/components/table/reorder_rows/use_drop_monitor.js +4 -4
  58. package/lib/components/table/reorder_rows/use_drop_monitor.js.map +1 -1
  59. package/lib/components/table/table_body.d.ts.map +1 -1
  60. package/lib/components/table/table_body.js +3 -3
  61. package/lib/components/table/table_body.js.map +1 -1
  62. package/lib/components/table/table_root.d.ts +5 -1
  63. package/lib/components/table/table_root.d.ts.map +1 -1
  64. package/lib/components/table/table_root.js +44 -45
  65. package/lib/components/table/table_root.js.map +1 -1
  66. package/lib/components/table/table_row.d.ts +8 -0
  67. package/lib/components/table/table_row.d.ts.map +1 -0
  68. package/lib/components/table/table_row.js +10 -0
  69. package/lib/components/table/table_row.js.map +1 -0
  70. package/lib/components/table/table_scroll_container.d.ts +33 -0
  71. package/lib/components/table/table_scroll_container.d.ts.map +1 -0
  72. package/lib/components/table/table_scroll_container.js +33 -0
  73. package/lib/components/table/table_scroll_container.js.map +1 -0
  74. package/lib/components/table/table_utils.d.ts +13 -4
  75. package/lib/components/table/table_utils.d.ts.map +1 -1
  76. package/lib/components/table/use_table_scroll.d.ts +20 -1
  77. package/lib/components/table/use_table_scroll.d.ts.map +1 -1
  78. package/lib/components/table/use_table_scroll.js +16 -8
  79. package/lib/components/table/use_table_scroll.js.map +1 -1
  80. package/package.json +1 -1
  81. package/src/components/accordion/accordion.tsx +65 -20
  82. package/src/components/accordion/accordion_context.ts +17 -37
  83. package/src/components/accordion/accordion_context_provider.tsx +79 -0
  84. package/src/components/accordion/accordion_context_utils.ts +22 -0
  85. package/src/components/accordion/accordion_hooks.ts +32 -0
  86. package/src/components/accordion/index.ts +2 -6
  87. package/src/components/table/flash_row/flashed_row_context.ts +23 -0
  88. package/src/components/table/flash_row/flashed_row_provider.tsx +13 -0
  89. package/src/components/table/flash_row/use_flash_row_effect.ts +30 -0
  90. package/src/components/table/index.ts +1 -0
  91. package/src/components/table/preview_table.tsx +18 -0
  92. package/src/components/table/preview_table_context.ts +33 -0
  93. package/src/components/table/reorder_rows/draggable_row_tr.tsx +21 -27
  94. package/src/components/table/reorder_rows/table_drag_row_handler.tsx +25 -4
  95. package/src/components/table/reorder_rows/use_drop_monitor.ts +4 -4
  96. package/src/components/table/table_body.tsx +6 -8
  97. package/src/components/table/table_root.tsx +112 -123
  98. package/src/components/table/table_row.tsx +17 -0
  99. package/src/components/table/table_scroll_container.tsx +103 -0
  100. package/src/components/table/table_utils.ts +20 -4
  101. package/src/components/table/use_table_scroll.ts +48 -20
  102. package/lib/components/accordion/accordion_context.provider.d.ts +0 -13
  103. package/lib/components/accordion/accordion_context.provider.d.ts.map +0 -1
  104. package/lib/components/accordion/accordion_context.provider.js +0 -55
  105. package/lib/components/accordion/accordion_context.provider.js.map +0 -1
  106. package/lib/components/accordion/accordion_context.utils.d.ts +0 -23
  107. package/lib/components/accordion/accordion_context.utils.d.ts.map +0 -1
  108. package/lib/components/accordion/accordion_context.utils.js +0 -40
  109. package/lib/components/accordion/accordion_context.utils.js.map +0 -1
  110. package/lib/components/table/reorder_rows/dropped_item_context.d.ts +0 -3
  111. package/lib/components/table/reorder_rows/dropped_item_context.d.ts.map +0 -1
  112. package/lib/components/table/reorder_rows/dropped_item_context.js +0 -10
  113. package/lib/components/table/reorder_rows/dropped_item_context.js.map +0 -1
  114. package/lib/components/table/reorder_rows/dropped_item_provider.d.ts.map +0 -1
  115. package/lib/components/table/reorder_rows/dropped_item_provider.js +0 -8
  116. package/lib/components/table/reorder_rows/dropped_item_provider.js.map +0 -1
  117. package/src/components/accordion/accordion_context.provider.tsx +0 -91
  118. package/src/components/accordion/accordion_context.utils.ts +0 -66
  119. package/src/components/table/reorder_rows/dropped_item_context.ts +0 -23
  120. package/src/components/table/reorder_rows/dropped_item_provider.tsx +0 -13
@@ -18,7 +18,7 @@ export function createTableColumnHelper<TData extends RowData>() {
18
18
  return createColumnHelper<TData>();
19
19
  }
20
20
 
21
- export interface TableRowTrProps {
21
+ export interface TableRowTrRenderProps {
22
22
  className: string;
23
23
  style: CSSProperties;
24
24
  children: ReactNode;
@@ -27,7 +27,7 @@ export interface TableRowTrProps {
27
27
  }
28
28
 
29
29
  export type TableRowTrRenderer<TData extends RowData> = (
30
- trProps: TableRowTrProps,
30
+ trProps: TableRowTrRenderProps,
31
31
  row: Row<TData>,
32
32
  ) => ReactNode;
33
33
 
@@ -38,10 +38,26 @@ export type TableRowPreviewRenderer<TData extends RowData> = (
38
38
  row: Row<TData>,
39
39
  ) => ReactNode;
40
40
 
41
+ interface FlashRowOptions {
42
+ /**
43
+ * Whether to flash the row when scrolling into view.
44
+ * The option is only supported when there is no scroll animation, i.e. `behavior` is not `smooth`.
45
+ */
46
+ flashRow?: boolean;
47
+ }
48
+
49
+ export type TableScrollIntoViewOptions = ScrollIntoViewOptions &
50
+ FlashRowOptions;
51
+ export type TableVirtualScrollIntoViewOptions = ScrollToOptions &
52
+ FlashRowOptions;
53
+
41
54
  export interface VirtualScroller {
42
- scrollIntoView: (id: string, options?: ScrollToOptions) => void;
55
+ scrollIntoView: (
56
+ id: string,
57
+ options?: TableVirtualScrollIntoViewOptions,
58
+ ) => void;
43
59
  }
44
60
 
45
61
  export interface Scroller {
46
- scrollIntoView: (id: string, options?: ScrollIntoViewOptions) => void;
62
+ scrollIntoView: (id: string, options?: TableScrollIntoViewOptions) => void;
47
63
  }
@@ -1,26 +1,46 @@
1
1
  import type { RowData, Table } from '@tanstack/react-table';
2
- import type {
3
- ScrollToOptions,
4
- ScrollToOptions as VirtualScrollToOptions,
5
- Virtualizer,
6
- } from '@tanstack/react-virtual';
7
- import { useImperativeHandle, useRef } from 'react';
2
+ import type { Virtualizer } from '@tanstack/react-virtual';
3
+ import type { RefObject } from 'react';
4
+ import { useImperativeHandle } from 'react';
8
5
 
6
+ import { useFlashedRowContext } from './flash_row/flashed_row_context.js';
9
7
  import type { TableProps } from './table_root.js';
8
+ import type { TableVirtualScrollIntoViewOptions } from './table_utils.js';
10
9
 
11
- export function useTableScroll<TData extends RowData>(
12
- tableProps: TableProps<TData>,
13
- table: Table<TData>,
14
- virtualizer: Virtualizer<HTMLDivElement, Element>,
15
- ) {
16
- const tableRef = useRef<HTMLTableElement>(null);
17
- const { scrollToRowRef, virtualizeRows } = tableProps;
10
+ export function useTableScroll<TData extends RowData>(options: {
11
+ /**
12
+ * The user provided ref to attach the scroll callbacks to.
13
+ */
14
+ scrollToRowRef: TableProps<TData>['scrollToRowRef'];
15
+ /**
16
+ * Whether the table rows are virtualized.
17
+ */
18
+ virtualizeRows: TableProps<TData>['virtualizeRows'];
19
+ /**
20
+ * A ref to the effective scroll container.
21
+ */
22
+ scrollRef: RefObject<Element>;
23
+ /*
24
+ Tanstack table instance.
25
+ */
26
+ table: Table<TData>;
27
+ /**
28
+ * Tanstack virtualizer instance.
29
+ */
30
+ virtualizer: Virtualizer<HTMLDivElement, Element>;
31
+ }) {
32
+ const [, setFlashedRow] = useFlashedRowContext();
33
+ const { scrollToRowRef, virtualizeRows, scrollRef, table, virtualizer } =
34
+ options;
18
35
 
19
36
  // @ts-expect-error We cannot call the hook conditionally to satisfy the type checker
20
37
  useImperativeHandle(scrollToRowRef, () => {
21
38
  if (virtualizeRows) {
22
39
  return {
23
- scrollIntoView(id: string, options?: VirtualScrollToOptions) {
40
+ scrollIntoView(
41
+ id: string,
42
+ options?: TableVirtualScrollIntoViewOptions,
43
+ ) {
24
44
  const sortedRows = table.getRowModel().rows; // Get sorted rows
25
45
  const rowIndex = sortedRows.findIndex((row) => row.id === id); // Find the index of the row by ID
26
46
  if (rowIndex === -1) {
@@ -29,14 +49,21 @@ export function useTableScroll<TData extends RowData>(
29
49
  console.warn(
30
50
  `Could not scroll to row with ID ${id}, the row does not exist`,
31
51
  );
52
+ } else {
53
+ virtualizer.scrollToIndex(rowIndex, options);
54
+ if (options?.flashRow && options.behavior !== 'smooth') {
55
+ setFlashedRow(sortedRows[rowIndex].id);
56
+ }
32
57
  }
33
- virtualizer.scrollToIndex(rowIndex, options);
34
58
  },
35
59
  };
36
60
  } else {
37
61
  return {
38
- scrollIntoView(id: string, options?: ScrollToOptions) {
39
- const element = tableRef.current?.querySelector(
62
+ scrollIntoView(
63
+ id: string,
64
+ options?: TableVirtualScrollIntoViewOptions,
65
+ ) {
66
+ const element = scrollRef.current?.querySelector(
40
67
  `tr[data-row-id="${id}"]`,
41
68
  );
42
69
  if (!element) {
@@ -46,10 +73,11 @@ export function useTableScroll<TData extends RowData>(
46
73
  );
47
74
  }
48
75
  element?.scrollIntoView(options);
76
+ if (options?.flashRow && options.behavior !== 'smooth') {
77
+ setFlashedRow(id);
78
+ }
49
79
  },
50
80
  };
51
81
  }
52
- }, [virtualizeRows, table, virtualizer]);
53
-
54
- return tableRef;
82
+ }, [virtualizeRows, scrollRef, table, virtualizer, setFlashedRow]);
55
83
  }
@@ -1,13 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import type { AccordionItemState, ActionType } from './accordion_context.utils.js';
3
- interface AccordionProviderProps {
4
- children: ReactNode;
5
- unmountChildren?: boolean;
6
- }
7
- export type AccordionActions = ActionType<'CHANGE', {
8
- title: string;
9
- isOpen: boolean;
10
- }> | ActionType<'CLEAR', string> | ActionType<'TOGGLE', string> | ActionType<'REMOVE', string> | ActionType<'CREATE', AccordionItemState>;
11
- export declare function AccordionProvider(props: AccordionProviderProps): import("react/jsx-runtime").JSX.Element;
12
- export {};
13
- //# sourceMappingURL=accordion_context.provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accordion_context.provider.d.ts","sourceRoot":"","sources":["../../../src/components/accordion/accordion_context.provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAMvC,OAAO,KAAK,EACV,kBAAkB,EAClB,UAAU,EACX,MAAM,8BAA8B,CAAC;AAQtC,UAAU,sBAAsB;IAC9B,QAAQ,EAAE,SAAS,CAAC;IACpB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,MAAM,gBAAgB,GACxB,UAAU,CAAC,QAAQ,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC,GACxD,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,GAC3B,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,GAC5B,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,GAC5B,UAAU,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;AAyB7C,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,2CAsC9D"}
@@ -1,55 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useMemo, useReducer } from 'react';
3
- import { match } from 'ts-pattern';
4
- import { accordionContext } from './accordion_context.js';
5
- import { changeItem, clearItem, removeItem, toggleItem, } from './accordion_context.utils.js';
6
- function reducer(previous, action) {
7
- return match(action)
8
- .with({ type: 'CHANGE' }, ({ payload }) => {
9
- return changeItem(previous, payload);
10
- })
11
- .with({ type: 'CLEAR' }, ({ payload }) => {
12
- return clearItem(previous, payload);
13
- })
14
- .with({ type: 'TOGGLE' }, ({ payload }) => {
15
- return toggleItem(previous, payload);
16
- })
17
- .with({ type: 'REMOVE' }, ({ payload }) => {
18
- return removeItem(previous, payload);
19
- })
20
- .with({ type: 'CREATE' }, ({ payload }) => {
21
- return [...previous, payload];
22
- })
23
- .exhaustive();
24
- }
25
- export function AccordionProvider(props) {
26
- const { unmountChildren = false, children } = props;
27
- const [items, dispatch] = useReducer(reducer, []);
28
- const utils = useMemo(() => {
29
- return {
30
- change: (title, isOpen) => dispatch({ type: 'CHANGE', payload: { title, isOpen } }),
31
- clear: (except) => dispatch({ type: 'CLEAR', payload: except }),
32
- toggle: (title) => dispatch({ type: 'TOGGLE', payload: title }),
33
- remove: (title) => dispatch({ type: 'REMOVE', payload: title }),
34
- create: (title, defaultOpened) => {
35
- const item = {
36
- title,
37
- isOpen: defaultOpened || false,
38
- };
39
- dispatch({ type: 'CREATE', payload: item });
40
- return item;
41
- },
42
- };
43
- }, []);
44
- const contextValue = useMemo(() => {
45
- return [
46
- {
47
- items,
48
- unmountChildren,
49
- },
50
- utils,
51
- ];
52
- }, [items, unmountChildren, utils]);
53
- return (_jsx(accordionContext.Provider, { value: contextValue, children: children }));
54
- }
55
- //# sourceMappingURL=accordion_context.provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accordion_context.provider.js","sourceRoot":"","sources":["../../../src/components/accordion/accordion_context.provider.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAK1D,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,UAAU,GACX,MAAM,8BAA8B,CAAC;AActC,SAAS,OAAO,CACd,QAA8B,EAC9B,MAAwB;IAExB,OAAO,KAAK,CAAC,MAAM,CAAC;SACjB,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;QACxC,OAAO,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC;SACD,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;QACvC,OAAO,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC,CAAC;SACD,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;QACxC,OAAO,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC;SACD,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;QACxC,OAAO,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC;SACD,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;QACxC,OAAO,CAAC,GAAG,QAAQ,EAAE,OAAO,CAAC,CAAC;IAChC,CAAC,CAAC;SACD,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AChB;YACD,KAAK;SACN,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,EAAE,KAAK,CAAC,CAAC,CAAC;IAEpC,OAAO,CACL,KAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAC3C,QAAQ,GACiB,CAC7B,CAAC;AACJ,CAAC"}
@@ -1,23 +0,0 @@
1
- export interface AccordionItemState {
2
- title: string;
3
- isOpen: boolean;
4
- }
5
- export interface AccordionState {
6
- items: AccordionItemState[];
7
- unmountChildren: boolean;
8
- }
9
- export declare function getItem(title: string, items: AccordionItemState[]): AccordionItemState | undefined;
10
- export type ActionType<Action, Payload = void> = Payload extends void ? {
11
- type: Action;
12
- } : {
13
- type: Action;
14
- payload: Payload;
15
- };
16
- export declare function removeItem(array: AccordionItemState[], title: string): AccordionItemState[];
17
- export declare function changeItem(array: AccordionItemState[], payload: {
18
- title: string;
19
- isOpen: boolean;
20
- }): AccordionItemState[];
21
- export declare function clearItem(array: AccordionItemState[], except: string): AccordionItemState[];
22
- export declare function toggleItem(array: AccordionItemState[], title: string): AccordionItemState[];
23
- //# sourceMappingURL=accordion_context.utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accordion_context.utils.d.ts","sourceRoot":"","sources":["../../../src/components/accordion/accordion_context.utils.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,kBAAkB,EAAE,CAAC;IAC5B,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,EAAE,kCAEjE;AAED,MAAM,MAAM,UAAU,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,IAAI,OAAO,SAAS,IAAI,GACjE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAEvC,wBAAgB,UAAU,CAAC,KAAK,EAAE,kBAAkB,EAAE,EAAE,KAAK,EAAE,MAAM,wBAEpE;AAED,wBAAgB,UAAU,CACxB,KAAK,EAAE,kBAAkB,EAAE,EAC3B,OAAO,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,wBAU5C;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,kBAAkB,EAAE,EAAE,MAAM,EAAE,MAAM,wBAapE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,kBAAkB,EAAE,EAAE,KAAK,EAAE,MAAM,wBAcpE"}
@@ -1,40 +0,0 @@
1
- export function getItem(title, items) {
2
- return items.find((element) => element.title === title);
3
- }
4
- export function removeItem(array, title) {
5
- return array.filter((element) => element.title !== title);
6
- }
7
- export function changeItem(array, payload) {
8
- const { title, isOpen } = payload;
9
- const item = getItem(title, array);
10
- if (item) {
11
- return [...removeItem(array, title), { ...item, isOpen }];
12
- }
13
- return array;
14
- }
15
- export function clearItem(array, except) {
16
- const item = getItem(except, array);
17
- if (!item) {
18
- return [...array, { isOpen: true, title: except }];
19
- }
20
- return array.map((element) => {
21
- return {
22
- ...element,
23
- isOpen: element.title === item.title,
24
- };
25
- });
26
- }
27
- export function toggleItem(array, title) {
28
- const item = getItem(title, array);
29
- if (!item) {
30
- return [...array, { title, isOpen: true }];
31
- }
32
- return [
33
- ...removeItem(array, title),
34
- {
35
- ...item,
36
- isOpen: !item.isOpen,
37
- },
38
- ];
39
- }
40
- //# sourceMappingURL=accordion_context.utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"accordion_context.utils.js","sourceRoot":"","sources":["../../../src/components/accordion/accordion_context.utils.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,OAAO,CAAC,KAAa,EAAE,KAA2B;IAChE,OAAO,KA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I,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,CAAC,GAAG,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO;QACL,GAAG,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC;QAC3B;YACE,GAAG,IAAI;YACP,MAAM,EAAE,CAAC,IAAI,CAAC,MAAM;SACrB;KACF,CAAC;AACJ,CAAC"}
@@ -1,3 +0,0 @@
1
- export declare const droppedItemContext: import("react").Context<[string | undefined, import("react").Dispatch<import("react").SetStateAction<string | undefined>>] | null>;
2
- export declare function useDroppedItemContext(): [string | undefined, import("react").Dispatch<import("react").SetStateAction<string | undefined>>];
3
- //# sourceMappingURL=dropped_item_context.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dropped_item_context.d.ts","sourceRoot":"","sources":["../../../../src/components/table/reorder_rows/dropped_item_context.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,kBAAkB,oIAE9B,CAAC;AAEF,wBAAgB,qBAAqB,uGAUpC"}
@@ -1,10 +0,0 @@
1
- import { createContext, useContext } from 'react';
2
- export const droppedItemContext = createContext(null);
3
- export function useDroppedItemContext() {
4
- const context = useContext(droppedItemContext);
5
- if (!context) {
6
- throw new Error('useDroppedItemId must be used within a DroppedItemProvider');
7
- }
8
- return context;
9
- }
10
- //# sourceMappingURL=dropped_item_context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dropped_item_context.js","sourceRoot":"","sources":["../../../../src/components/table/reorder_rows/dropped_item_context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAOlD,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAC7C,IAAI,CACL,CAAC;AAEF,MAAM,UAAU,qBAAqB;IACnC,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAE/C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"dropped_item_provider.d.ts","sourceRoot":"","sources":["../../../../src/components/table/reorder_rows/dropped_item_provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2CAOjE"}
@@ -1,8 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useState } from 'react';
3
- import { droppedItemContext } from './dropped_item_context.js';
4
- export function DroppedItemProvider(props) {
5
- const value = useState();
6
- return (_jsx(droppedItemContext.Provider, { value: value, children: props.children }));
7
- }
8
- //# sourceMappingURL=dropped_item_provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dropped_item_provider.js","sourceRoot":"","sources":["../../../../src/components/table/reorder_rows/dropped_item_provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,MAAM,UAAU,mBAAmB,CAAC,KAA8B;IAChE,MAAM,KAAK,GAAG,QAAQ,EAAU,CAAC;IACjC,OAAO,CACL,KAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACtC,KAAK,CAAC,QAAQ,GACa,CAC/B,CAAC;AACJ,CAAC"}
@@ -1,91 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import { useMemo, useReducer } from 'react';
3
- import { match } from 'ts-pattern';
4
-
5
- import type { ContextType } from './accordion_context.js';
6
- import { accordionContext } from './accordion_context.js';
7
- import type {
8
- AccordionItemState,
9
- ActionType,
10
- } from './accordion_context.utils.js';
11
- import {
12
- changeItem,
13
- clearItem,
14
- removeItem,
15
- toggleItem,
16
- } from './accordion_context.utils.js';
17
-
18
- interface AccordionProviderProps {
19
- children: ReactNode;
20
- unmountChildren?: boolean;
21
- }
22
-
23
- export type AccordionActions =
24
- | ActionType<'CHANGE', { title: string; isOpen: boolean }>
25
- | ActionType<'CLEAR', string>
26
- | ActionType<'TOGGLE', string>
27
- | ActionType<'REMOVE', string>
28
- | ActionType<'CREATE', AccordionItemState>;
29
-
30
- function reducer(
31
- previous: AccordionItemState[],
32
- action: AccordionActions,
33
- ): AccordionItemState[] {
34
- return match(action)
35
- .with({ type: 'CHANGE' }, ({ payload }) => {
36
- return changeItem(previous, payload);
37
- })
38
- .with({ type: 'CLEAR' }, ({ payload }) => {
39
- return clearItem(previous, payload);
40
- })
41
- .with({ type: 'TOGGLE' }, ({ payload }) => {
42
- return toggleItem(previous, payload);
43
- })
44
- .with({ type: 'REMOVE' }, ({ payload }) => {
45
- return removeItem(previous, payload);
46
- })
47
- .with({ type: 'CREATE' }, ({ payload }) => {
48
- return [...previous, payload];
49
- })
50
- .exhaustive();
51
- }
52
-
53
- export function AccordionProvider(props: AccordionProviderProps) {
54
- const { unmountChildren = false, children } = props;
55
- const [items, dispatch] = useReducer(reducer, []);
56
-
57
- const utils = useMemo<ContextType[1]>(() => {
58
- return {
59
- change: (title: string, isOpen: boolean) =>
60
- dispatch({ type: 'CHANGE', payload: { title, isOpen } }),
61
- clear: (except: string) => dispatch({ type: 'CLEAR', payload: except }),
62
- toggle: (title: string) => dispatch({ type: 'TOGGLE', payload: title }),
63
- remove: (title: string) => dispatch({ type: 'REMOVE', payload: title }),
64
- create: (title: string, defaultOpened?: boolean) => {
65
- const item: AccordionItemState = {
66
- title,
67
- isOpen: defaultOpened || false,
68
- };
69
-
70
- dispatch({ type: 'CREATE', payload: item });
71
- return item;
72
- },
73
- };
74
- }, []);
75
-
76
- const contextValue = useMemo<ContextType>(() => {
77
- return [
78
- {
79
- items,
80
- unmountChildren,
81
- },
82
- utils,
83
- ];
84
- }, [items, unmountChildren, utils]);
85
-
86
- return (
87
- <accordionContext.Provider value={contextValue}>
88
- {children}
89
- </accordionContext.Provider>
90
- );
91
- }
@@ -1,66 +0,0 @@
1
- export interface AccordionItemState {
2
- title: string;
3
- isOpen: boolean;
4
- }
5
-
6
- export interface AccordionState {
7
- items: AccordionItemState[];
8
- unmountChildren: boolean;
9
- }
10
-
11
- export function getItem(title: string, items: AccordionItemState[]) {
12
- return items.find((element) => element.title === title);
13
- }
14
-
15
- export type ActionType<Action, Payload = void> = Payload extends void
16
- ? { type: Action }
17
- : { type: Action; payload: Payload };
18
-
19
- export function removeItem(array: AccordionItemState[], title: string) {
20
- return array.filter((element) => element.title !== title);
21
- }
22
-
23
- export function changeItem(
24
- array: AccordionItemState[],
25
- payload: { title: string; isOpen: boolean },
26
- ) {
27
- const { title, isOpen } = payload;
28
- const item = getItem(title, array);
29
-
30
- if (item) {
31
- return [...removeItem(array, title), { ...item, isOpen }];
32
- }
33
-
34
- return array;
35
- }
36
-
37
- export function clearItem(array: AccordionItemState[], except: string) {
38
- const item = getItem(except, array);
39
-
40
- if (!item) {
41
- return [...array, { isOpen: true, title: except }];
42
- }
43
-
44
- return array.map((element) => {
45
- return {
46
- ...element,
47
- isOpen: element.title === item.title,
48
- };
49
- });
50
- }
51
-
52
- export function toggleItem(array: AccordionItemState[], title: string) {
53
- const item = getItem(title, array);
54
-
55
- if (!item) {
56
- return [...array, { title, isOpen: true }];
57
- }
58
-
59
- return [
60
- ...removeItem(array, title),
61
- {
62
- ...item,
63
- isOpen: !item.isOpen,
64
- },
65
- ];
66
- }
@@ -1,23 +0,0 @@
1
- import type { useState } from 'react';
2
- import { createContext, useContext } from 'react';
3
-
4
- /**
5
- * ID of the dropped item
6
- */
7
- type DroppedItemContextValue = ReturnType<typeof useState<string>>;
8
-
9
- export const droppedItemContext = createContext<DroppedItemContextValue | null>(
10
- null,
11
- );
12
-
13
- export function useDroppedItemContext() {
14
- const context = useContext(droppedItemContext);
15
-
16
- if (!context) {
17
- throw new Error(
18
- 'useDroppedItemId must be used within a DroppedItemProvider',
19
- );
20
- }
21
-
22
- return context;
23
- }
@@ -1,13 +0,0 @@
1
- import { useState } from 'react';
2
- import type { ReactNode } from 'react';
3
-
4
- import { droppedItemContext } from './dropped_item_context.js';
5
-
6
- export function DroppedItemProvider(props: { children: ReactNode }) {
7
- const value = useState<string>();
8
- return (
9
- <droppedItemContext.Provider value={value}>
10
- {props.children}
11
- </droppedItemContext.Provider>
12
- );
13
- }