fastapi-rtk 1.0.44 → 1.0.45

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 (33) hide show
  1. package/dist/.bundled/jsonforms/cjs/_virtual/index11.cjs +2 -2
  2. package/dist/.bundled/jsonforms/cjs/_virtual/index12.cjs +2 -2
  3. package/dist/.bundled/jsonforms/esm/_virtual/index11.mjs +2 -2
  4. package/dist/.bundled/jsonforms/esm/_virtual/index12.mjs +2 -2
  5. package/dist/.external/cjs/fast-uri@3.1.0/fast-uri/index.cjs +1 -1
  6. package/dist/.external/cjs/json-schema-traverse@1.0.0/json-schema-traverse/index.cjs +1 -1
  7. package/dist/.external/esm/fast-uri@3.1.0/fast-uri/index.mjs +1 -1
  8. package/dist/.external/esm/json-schema-traverse@1.0.0/json-schema-traverse/index.mjs +1 -1
  9. package/dist/core/cjs/Tables/NextGenDataGrid/NextGenDataGrid.cjs +3 -2
  10. package/dist/core/cjs/Tables/NextGenDataGrid/components/OptimizedMRT_RowSelectColumn/zustand.cjs +12 -0
  11. package/dist/core/cjs/Tables/NextGenDataGrid/hooks/useOptimizations.cjs +24 -0
  12. package/dist/core/cjs/Tables/NextGenDataGrid/hooks/useSelection/useSelection.cjs +2 -2
  13. package/dist/core/cjs/_virtual/_nodeUtil.cjs +4 -0
  14. package/dist/core/cjs/_virtual/isBuffer.cjs +4 -0
  15. package/dist/core/cjs/_virtual/isEqual.cjs +6 -0
  16. package/dist/core/esm/Tables/NextGenDataGrid/NextGenDataGrid.mjs +3 -2
  17. package/dist/core/esm/Tables/NextGenDataGrid/components/OptimizedMRT_RowSelectColumn/zustand.mjs +12 -0
  18. package/dist/core/esm/Tables/NextGenDataGrid/hooks/useOptimizations.mjs +24 -0
  19. package/dist/core/esm/Tables/NextGenDataGrid/hooks/useSelection/useSelection.mjs +2 -2
  20. package/dist/core/esm/_virtual/_nodeUtil.mjs +4 -0
  21. package/dist/core/esm/_virtual/isBuffer.mjs +4 -0
  22. package/dist/core/esm/_virtual/isEqual.mjs +7 -0
  23. package/dist/core/lib/Tables/NextGenDataGrid/NextGenDataGrid.d.ts +4 -0
  24. package/dist/core/lib/Tables/NextGenDataGrid/components/OptimizedMRT_RowSelectColumn/zustand.d.ts +12 -0
  25. package/dist/core/lib/Tables/NextGenDataGrid/hooks/useSelection/useSelection.d.ts +1 -1
  26. package/dist/utils/cjs/index.cjs +2 -0
  27. package/dist/utils/cjs/useWatchRef/useWatchRef.cjs +28 -0
  28. package/dist/utils/esm/index.mjs +3 -1
  29. package/dist/utils/esm/useWatchRef/useWatchRef.mjs +28 -0
  30. package/dist/utils/lib/index.d.ts +1 -0
  31. package/dist/utils/lib/useWatchRef/index.d.ts +1 -0
  32. package/dist/utils/lib/useWatchRef/useWatchRef.d.ts +1 -0
  33. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- var fastUri = { exports: {} };
4
- exports.__module = fastUri;
3
+ var jsonSchemaTraverse = { exports: {} };
4
+ exports.__module = jsonSchemaTraverse;
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- var jsonSchemaTraverse = { exports: {} };
4
- exports.__module = jsonSchemaTraverse;
3
+ var fastUri = { exports: {} };
4
+ exports.__module = fastUri;
@@ -1,4 +1,4 @@
1
- var fastUri = { exports: {} };
1
+ var jsonSchemaTraverse = { exports: {} };
2
2
  export {
3
- fastUri as __module
3
+ jsonSchemaTraverse as __module
4
4
  };
@@ -1,4 +1,4 @@
1
- var jsonSchemaTraverse = { exports: {} };
1
+ var fastUri = { exports: {} };
2
2
  export {
3
- jsonSchemaTraverse as __module
3
+ fastUri as __module
4
4
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("../../../../.bundled/jsonforms/cjs/_virtual/index11.cjs");
3
+ const index = require("../../../../.bundled/jsonforms/cjs/_virtual/index12.cjs");
4
4
  const utils = require("./lib/utils.cjs");
5
5
  const schemes = require("./lib/schemes.cjs");
6
6
  var hasRequiredFastUri;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("../../../../.bundled/jsonforms/cjs/_virtual/index12.cjs");
3
+ const index = require("../../../../.bundled/jsonforms/cjs/_virtual/index11.cjs");
4
4
  var hasRequiredJsonSchemaTraverse;
5
5
  function requireJsonSchemaTraverse() {
6
6
  if (hasRequiredJsonSchemaTraverse) return index.__module.exports;
@@ -1,4 +1,4 @@
1
- import { __module as fastUri } from "../../../../.bundled/jsonforms/esm/_virtual/index11.mjs";
1
+ import { __module as fastUri } from "../../../../.bundled/jsonforms/esm/_virtual/index12.mjs";
2
2
  import { __require as requireUtils } from "./lib/utils.mjs";
3
3
  import { __require as requireSchemes } from "./lib/schemes.mjs";
4
4
  var hasRequiredFastUri;
@@ -1,4 +1,4 @@
1
- import { __module as jsonSchemaTraverse } from "../../../../.bundled/jsonforms/esm/_virtual/index12.mjs";
1
+ import { __module as jsonSchemaTraverse } from "../../../../.bundled/jsonforms/esm/_virtual/index11.mjs";
2
2
  var hasRequiredJsonSchemaTraverse;
3
3
  function requireJsonSchemaTraverse() {
4
4
  if (hasRequiredJsonSchemaTraverse) return jsonSchemaTraverse.exports;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  ;/* empty css */
5
5
  ;/* empty css */
6
+ const constants = require("fastapi-rtk/constants");
6
7
  const utils = require("fastapi-rtk/utils");
7
8
  const core = require("@mantine/core");
8
9
  const index_esm = require("../../../../.external/cjs/mantine-react-table@2.0.0-beta.9_@mantine_core@7.17.8_@mantine_dates@7.17.8_@mantine_hooks@7._7jqiyi5sshrifwwn7z7vmkfdl4/mantine-react-table/dist/index.esm.cjs");
@@ -32,7 +33,7 @@ const useToolbar = require("./hooks/useToolbar/useToolbar.cjs");
32
33
  const useToolbarAlertBanner = require("./hooks/useToolbarAlertBanner/useToolbarAlertBanner.cjs");
33
34
  const MantineReactTable = require("./patch/MantineReactTable.cjs");
34
35
  const baseProps = { enableStickyHeader: true, enableColumnPinning: true };
35
- const defaultProps = { optimizations: { loading: true } };
36
+ const defaultProps = { optimizations: { loading: true, selectionSyncDelay: constants.DEBOUNCE_DELAY } };
36
37
  const NextGenDataGrid = React.forwardRef((props, ref) => {
37
38
  var _a, _b, _c, _d, _e;
38
39
  const { info, specialKey } = useApi.useApi();
@@ -153,7 +154,7 @@ const NextGenDataGrid = React.forwardRef((props, ref) => {
153
154
  const globalFilterProps = useGlobalFilter.useGlobalFilter();
154
155
  const toolbarProps = useToolbar.useToolbar(toolbar, quickFilters, quickFiltersComponent, hideToolbar, enableAdvancedFilters);
155
156
  const eventProps = useEvent.useEvent(onClickEntry);
156
- const checkboxProps = useSelection.useSelection(onSelectCheckbox, bulkActions);
157
+ const checkboxProps = useSelection.useSelection(onSelectCheckbox, bulkActions, optimizations);
157
158
  const filterProps = useFilters.useFilters();
158
159
  const toolbarAlertBannerProps = useToolbarAlertBanner.useToolbarAlertBanner(toolbar, optimizations);
159
160
  const i18nProps = useI18n.useI18n();
@@ -3,6 +3,16 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const react = require("../../../../../../.external/cjs/zustand@5.0.11_@types_react@19.2.14_react@19.2.4/zustand/esm/react.cjs");
4
4
  const selectionStoreFactory = () => react.create((set, get) => ({
5
5
  rowSelection: {},
6
+ refs: /* @__PURE__ */ new Set(),
7
+ getSelectedRows: () => Object.keys(get().rowSelection),
8
+ setSelectedRows: (ids) => set(() => {
9
+ const newRowSelection = {};
10
+ ids.forEach((id) => {
11
+ newRowSelection[id] = true;
12
+ });
13
+ get().refs.forEach((ref) => ref.current = ids);
14
+ return { rowSelection: newRowSelection };
15
+ }),
6
16
  getIsAllRowsSelected: (table) => {
7
17
  const rowModel = table.getRowModel();
8
18
  return rowModel.rows.length > 0 && rowModel.rows.every((row) => get().rowSelection[row.id]);
@@ -19,6 +29,7 @@ const selectionStoreFactory = () => react.create((set, get) => ({
19
29
  } else {
20
30
  newRowSelection[rowId] = true;
21
31
  }
32
+ get().refs.forEach((ref) => ref.current = Object.keys(newRowSelection));
22
33
  return { rowSelection: newRowSelection };
23
34
  }),
24
35
  toggleAllRowsSelected: (table, value) => set((state) => {
@@ -30,6 +41,7 @@ const selectionStoreFactory = () => react.create((set, get) => ({
30
41
  delete newRowSelection[row.id];
31
42
  }
32
43
  });
44
+ get().refs.forEach((ref) => ref.current = Object.keys(newRowSelection));
33
45
  return { rowSelection: newRowSelection };
34
46
  })
35
47
  }));
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utils = require("fastapi-rtk/utils");
4
+ const isEqual = require("../../../_virtual/isEqual.cjs");
3
5
  const React = require("react");
4
6
  const getOptimizedMRT_RowSelectColumnDef = require("../components/OptimizedMRT_RowSelectColumn/getOptimizedMRT_RowSelectColumnDef.cjs");
5
7
  const zustand = require("../components/OptimizedMRT_RowSelectColumn/zustand.cjs");
@@ -13,7 +15,29 @@ const useOptimizations = (tableOptions, columns, optimizations) => {
13
15
  };
14
16
  const useTableOptimizations = (table, onSelectCheckbox, bulkActions, optimizations) => {
15
17
  const store = table.refs.selectionStoreRef.current;
18
+ const refs = zustand.useSelectionStore(store, (state) => state.refs);
16
19
  const optimizedRowSelection = zustand.useSelectionStore(store, (state) => state.rowSelection);
20
+ const optimizedGetSelectedRows = zustand.useSelectionStore(store, (state) => state.getSelectedRows);
21
+ const optimizedSetSelectedRows = zustand.useSelectionStore(store, (state) => state.setSelectedRows);
22
+ utils.useWatchRef(optimizations == null ? void 0 : optimizations.selectionValueRef, (value) => {
23
+ const internalValue = optimizedGetSelectedRows();
24
+ utils.FastAPIRTKLogger.debug(
25
+ "[useTableOptimizations] Watching selectionValueRef",
26
+ `value:`,
27
+ value,
28
+ `internalValue:`,
29
+ internalValue
30
+ );
31
+ if (isEqual(internalValue, value)) {
32
+ utils.FastAPIRTKLogger.debug("[useTableOptimizations] No change in selection, skipping update.");
33
+ return;
34
+ }
35
+ utils.FastAPIRTKLogger.debug("[useTableOptimizations] Updating selected rows based on selectionValueRef change.");
36
+ optimizedSetSelectedRows(value);
37
+ });
38
+ if (optimizations == null ? void 0 : optimizations.selectionValueRef) {
39
+ refs.add(optimizations.selectionValueRef);
40
+ }
17
41
  React.useEffect(() => {
18
42
  if (!(optimizations == null ? void 0 : optimizations.selection)) {
19
43
  return;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const React = require("react");
4
- function useSelection(onSelectCheckbox, bulkActions) {
5
- return { enableRowSelection: !!onSelectCheckbox || !!bulkActions };
4
+ function useSelection(onSelectCheckbox, bulkActions, optimizations) {
5
+ return { enableRowSelection: !!onSelectCheckbox || !!bulkActions || !!(optimizations == null ? void 0 : optimizations.selection) };
6
6
  }
7
7
  const useTableSelection = (table, onSelectCheckbox, bulkActions) => {
8
8
  React.useEffect(() => {
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ var _nodeUtil = { exports: {} };
4
+ exports.__module = _nodeUtil;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ var isBuffer = { exports: {} };
4
+ exports.__module = isBuffer;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ const _commonjsHelpers = require("./_commonjsHelpers.cjs");
3
+ const isEqual$1 = require("../../../.external/cjs/lodash@4.17.23/lodash/isEqual.cjs");
4
+ var isEqualExports = isEqual$1.__require();
5
+ const isEqual = /* @__PURE__ */ _commonjsHelpers.getDefaultExportFromCjs(isEqualExports);
6
+ module.exports = isEqual;
@@ -1,6 +1,7 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
2
  /* empty css */
3
3
  /* empty css */
4
+ import { DEBOUNCE_DELAY } from "fastapi-rtk/constants";
4
5
  import { deepMerge, mergeProps, getItemId, parseFromValuesOrFunc } from "fastapi-rtk/utils";
5
6
  import { useProps, Box } from "@mantine/core";
6
7
  import { useMRT_TableOptions, useMantineReactTable } from "../../../../.external/esm/mantine-react-table@2.0.0-beta.9_@mantine_core@7.17.8_@mantine_dates@7.17.8_@mantine_hooks@7._7jqiyi5sshrifwwn7z7vmkfdl4/mantine-react-table/dist/index.esm.mjs";
@@ -30,7 +31,7 @@ import { useToolbar } from "./hooks/useToolbar/useToolbar.mjs";
30
31
  import { useToolbarAlertBanner } from "./hooks/useToolbarAlertBanner/useToolbarAlertBanner.mjs";
31
32
  import { MantineReactTable } from "./patch/MantineReactTable.mjs";
32
33
  const baseProps = { enableStickyHeader: true, enableColumnPinning: true };
33
- const defaultProps = { optimizations: { loading: true } };
34
+ const defaultProps = { optimizations: { loading: true, selectionSyncDelay: DEBOUNCE_DELAY } };
34
35
  const NextGenDataGrid = forwardRef((props, ref) => {
35
36
  var _a, _b, _c, _d, _e;
36
37
  const { info, specialKey } = useApi();
@@ -151,7 +152,7 @@ const NextGenDataGrid = forwardRef((props, ref) => {
151
152
  const globalFilterProps = useGlobalFilter();
152
153
  const toolbarProps = useToolbar(toolbar, quickFilters, quickFiltersComponent, hideToolbar, enableAdvancedFilters);
153
154
  const eventProps = useEvent(onClickEntry);
154
- const checkboxProps = useSelection(onSelectCheckbox, bulkActions);
155
+ const checkboxProps = useSelection(onSelectCheckbox, bulkActions, optimizations);
155
156
  const filterProps = useFilters();
156
157
  const toolbarAlertBannerProps = useToolbarAlertBanner(toolbar, optimizations);
157
158
  const i18nProps = useI18n();
@@ -1,6 +1,16 @@
1
1
  import { create } from "../../../../../../.external/esm/zustand@5.0.11_@types_react@19.2.14_react@19.2.4/zustand/esm/react.mjs";
2
2
  const selectionStoreFactory = () => create((set, get) => ({
3
3
  rowSelection: {},
4
+ refs: /* @__PURE__ */ new Set(),
5
+ getSelectedRows: () => Object.keys(get().rowSelection),
6
+ setSelectedRows: (ids) => set(() => {
7
+ const newRowSelection = {};
8
+ ids.forEach((id) => {
9
+ newRowSelection[id] = true;
10
+ });
11
+ get().refs.forEach((ref) => ref.current = ids);
12
+ return { rowSelection: newRowSelection };
13
+ }),
4
14
  getIsAllRowsSelected: (table) => {
5
15
  const rowModel = table.getRowModel();
6
16
  return rowModel.rows.length > 0 && rowModel.rows.every((row) => get().rowSelection[row.id]);
@@ -17,6 +27,7 @@ const selectionStoreFactory = () => create((set, get) => ({
17
27
  } else {
18
28
  newRowSelection[rowId] = true;
19
29
  }
30
+ get().refs.forEach((ref) => ref.current = Object.keys(newRowSelection));
20
31
  return { rowSelection: newRowSelection };
21
32
  }),
22
33
  toggleAllRowsSelected: (table, value) => set((state) => {
@@ -28,6 +39,7 @@ const selectionStoreFactory = () => create((set, get) => ({
28
39
  delete newRowSelection[row.id];
29
40
  }
30
41
  });
42
+ get().refs.forEach((ref) => ref.current = Object.keys(newRowSelection));
31
43
  return { rowSelection: newRowSelection };
32
44
  })
33
45
  }));
@@ -1,3 +1,5 @@
1
+ import { useWatchRef, FastAPIRTKLogger } from "fastapi-rtk/utils";
2
+ import isEqual from "../../../_virtual/isEqual.mjs";
1
3
  import { useMemo, useEffect } from "react";
2
4
  import { getOptimizedMRT_RowSelectColumnDef } from "../components/OptimizedMRT_RowSelectColumn/getOptimizedMRT_RowSelectColumnDef.mjs";
3
5
  import { useSelectionStore } from "../components/OptimizedMRT_RowSelectColumn/zustand.mjs";
@@ -11,7 +13,29 @@ const useOptimizations = (tableOptions, columns, optimizations) => {
11
13
  };
12
14
  const useTableOptimizations = (table, onSelectCheckbox, bulkActions, optimizations) => {
13
15
  const store = table.refs.selectionStoreRef.current;
16
+ const refs = useSelectionStore(store, (state) => state.refs);
14
17
  const optimizedRowSelection = useSelectionStore(store, (state) => state.rowSelection);
18
+ const optimizedGetSelectedRows = useSelectionStore(store, (state) => state.getSelectedRows);
19
+ const optimizedSetSelectedRows = useSelectionStore(store, (state) => state.setSelectedRows);
20
+ useWatchRef(optimizations == null ? void 0 : optimizations.selectionValueRef, (value) => {
21
+ const internalValue = optimizedGetSelectedRows();
22
+ FastAPIRTKLogger.debug(
23
+ "[useTableOptimizations] Watching selectionValueRef",
24
+ `value:`,
25
+ value,
26
+ `internalValue:`,
27
+ internalValue
28
+ );
29
+ if (isEqual(internalValue, value)) {
30
+ FastAPIRTKLogger.debug("[useTableOptimizations] No change in selection, skipping update.");
31
+ return;
32
+ }
33
+ FastAPIRTKLogger.debug("[useTableOptimizations] Updating selected rows based on selectionValueRef change.");
34
+ optimizedSetSelectedRows(value);
35
+ });
36
+ if (optimizations == null ? void 0 : optimizations.selectionValueRef) {
37
+ refs.add(optimizations.selectionValueRef);
38
+ }
15
39
  useEffect(() => {
16
40
  if (!(optimizations == null ? void 0 : optimizations.selection)) {
17
41
  return;
@@ -1,6 +1,6 @@
1
1
  import { useEffect } from "react";
2
- function useSelection(onSelectCheckbox, bulkActions) {
3
- return { enableRowSelection: !!onSelectCheckbox || !!bulkActions };
2
+ function useSelection(onSelectCheckbox, bulkActions, optimizations) {
3
+ return { enableRowSelection: !!onSelectCheckbox || !!bulkActions || !!(optimizations == null ? void 0 : optimizations.selection) };
4
4
  }
5
5
  const useTableSelection = (table, onSelectCheckbox, bulkActions) => {
6
6
  useEffect(() => {
@@ -0,0 +1,4 @@
1
+ var _nodeUtil = { exports: {} };
2
+ export {
3
+ _nodeUtil as __module
4
+ };
@@ -0,0 +1,4 @@
1
+ var isBuffer = { exports: {} };
2
+ export {
3
+ isBuffer as __module
4
+ };
@@ -0,0 +1,7 @@
1
+ import { getDefaultExportFromCjs } from "./_commonjsHelpers.mjs";
2
+ import { __require as requireIsEqual } from "../../../.external/esm/lodash@4.17.23/lodash/isEqual.mjs";
3
+ var isEqualExports = requireIsEqual();
4
+ const isEqual = /* @__PURE__ */ getDefaultExportFromCjs(isEqualExports);
5
+ export {
6
+ isEqual as default
7
+ };
@@ -1170,6 +1170,10 @@ export type NextGenDataGridOptimizationProps = {
1170
1170
  * - Whether to optimize for selection. When enabled, selection column will be replaced with a custom one that is optimized for performance.
1171
1171
  */
1172
1172
  selection?: boolean;
1173
+ /**
1174
+ * - Ref for the selection value to synchronize with external components when `selection` optimization is enabled.
1175
+ */
1176
+ selectionValueRef?: React.RefObject<string[]>;
1173
1177
  /**
1174
1178
  * - Whether to optimize for loading state. When enabled, the table body will not render any cells when in loading state. This will break features that rely on the cells being rendered in loading state, such as skeletons and custom loading indicators, but will improve performance when dealing with large data sets. Defaults to `true`
1175
1179
  */
@@ -5,6 +5,18 @@ export type SelectionStore = {
5
5
  * - An object mapping row IDs to their selected state.
6
6
  */
7
7
  rowSelection: Record<string, boolean>;
8
+ /**
9
+ * - A set of React refs that need to be synchronized with the row selection state.
10
+ */
11
+ refs: Set<React.RefObject<string[]>>;
12
+ /**
13
+ * - A function to retrieve the currently selected row IDs as an array.
14
+ */
15
+ getSelectedRows: () => string[];
16
+ /**
17
+ * - A function to set the selected rows based on an array of row IDs.
18
+ */
19
+ setSelectedRows: (ids: string[]) => void;
8
20
  /**
9
21
  * - A function to determine if all rows are selected based on the current state of rowSelection.
10
22
  */
@@ -1,4 +1,4 @@
1
- export function useSelection(onSelectCheckbox: any, bulkActions: any): {
1
+ export function useSelection(onSelectCheckbox: any, bulkActions: any, optimizations: any): {
2
2
  enableRowSelection: boolean;
3
3
  };
4
4
  export function useTableSelection(table: any, onSelectCheckbox: any, bulkActions: any): void;
@@ -19,6 +19,7 @@ const parseFromValuesOrFunc = require("./parseFromValuesOrFunc/parseFromValuesOr
19
19
  const parseResponse = require("./parseResponse/parseResponse.cjs");
20
20
  const parseValue = require("./parseValue/parseValue.cjs");
21
21
  const urlJoin = require("./urlJoin/urlJoin.cjs");
22
+ const useWatchRef = require("./useWatchRef/useWatchRef.cjs");
22
23
  exports.convertId = convertId.convertId;
23
24
  exports.convertToFormData = convertToFormData.convertToFormData;
24
25
  exports.createFetchParams = createFetchParams.createFetchParams;
@@ -39,3 +40,4 @@ exports.parseResponse = parseResponse.parseResponse;
39
40
  exports.parseValue = parseValue.parseValue;
40
41
  exports.normalize = urlJoin.normalize;
41
42
  exports.urlJoin = urlJoin.urlJoin;
43
+ exports.useWatchRef = useWatchRef.useWatchRef;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const react = require("react");
4
+ const FastAPIRTKLogger = require("../FastAPIRTKLogger/FastAPIRTKLogger.cjs");
5
+ const useWatchRef = (ref, callback) => {
6
+ const [value, setValue] = react.useState(ref == null ? void 0 : ref.current);
7
+ react.useEffect(() => {
8
+ if (!ref) {
9
+ FastAPIRTKLogger.FastAPIRTKLogger.debug("[useWatchRef] No ref provided, skipping watch.");
10
+ return;
11
+ }
12
+ FastAPIRTKLogger.FastAPIRTKLogger.debug("[useWatchRef] Starting to watch ref for changes.", "Initial value:", ref.current);
13
+ let prev = ref.current;
14
+ let frame;
15
+ const check = () => {
16
+ if (ref.current !== prev) {
17
+ prev = ref.current;
18
+ setValue(ref.current);
19
+ callback == null ? void 0 : callback(ref.current);
20
+ }
21
+ frame = requestAnimationFrame(check);
22
+ };
23
+ frame = requestAnimationFrame(check);
24
+ return () => cancelAnimationFrame(frame);
25
+ }, [ref]);
26
+ return value;
27
+ };
28
+ exports.useWatchRef = useWatchRef;
@@ -17,6 +17,7 @@ import { parseFromValuesOrFunc } from "./parseFromValuesOrFunc/parseFromValuesOr
17
17
  import { parseResponse } from "./parseResponse/parseResponse.mjs";
18
18
  import { parseValue } from "./parseValue/parseValue.mjs";
19
19
  import { normalize, urlJoin } from "./urlJoin/urlJoin.mjs";
20
+ import { useWatchRef } from "./useWatchRef/useWatchRef.mjs";
20
21
  export {
21
22
  FastAPIRTKLogger,
22
23
  MemoWrapper,
@@ -37,5 +38,6 @@ export {
37
38
  parseFromValuesOrFunc,
38
39
  parseResponse,
39
40
  parseValue,
40
- urlJoin
41
+ urlJoin,
42
+ useWatchRef
41
43
  };
@@ -0,0 +1,28 @@
1
+ import { useState, useEffect } from "react";
2
+ import { FastAPIRTKLogger } from "../FastAPIRTKLogger/FastAPIRTKLogger.mjs";
3
+ const useWatchRef = (ref, callback) => {
4
+ const [value, setValue] = useState(ref == null ? void 0 : ref.current);
5
+ useEffect(() => {
6
+ if (!ref) {
7
+ FastAPIRTKLogger.debug("[useWatchRef] No ref provided, skipping watch.");
8
+ return;
9
+ }
10
+ FastAPIRTKLogger.debug("[useWatchRef] Starting to watch ref for changes.", "Initial value:", ref.current);
11
+ let prev = ref.current;
12
+ let frame;
13
+ const check = () => {
14
+ if (ref.current !== prev) {
15
+ prev = ref.current;
16
+ setValue(ref.current);
17
+ callback == null ? void 0 : callback(ref.current);
18
+ }
19
+ frame = requestAnimationFrame(check);
20
+ };
21
+ frame = requestAnimationFrame(check);
22
+ return () => cancelAnimationFrame(frame);
23
+ }, [ref]);
24
+ return value;
25
+ };
26
+ export {
27
+ useWatchRef
28
+ };
@@ -16,3 +16,4 @@ export * from './parseFromValuesOrFunc/index';
16
16
  export * from './parseResponse/index';
17
17
  export * from './parseValue/index';
18
18
  export * from './urlJoin/index';
19
+ export * from './useWatchRef/index';
@@ -0,0 +1 @@
1
+ export * from './useWatchRef';
@@ -0,0 +1 @@
1
+ export function useWatchRef(ref: React.RefObject<any>, callback?: (newValue: any) => void): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastapi-rtk",
3
- "version": "1.0.44",
3
+ "version": "1.0.45",
4
4
  "private": false,
5
5
  "description": "A React component library for FastAPI in combination with FastAPI React Toolkit backend, built with Mantine, JsonForms, and Zustand.",
6
6
  "license": "MIT",