@easyvision/easyvision-ui 1.4.0 → 1.5.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.
package/dist/index.d.cts CHANGED
@@ -186,6 +186,30 @@ interface EasyVisionMultifilterProps extends BaseStatefulProps<MultifilterSnapsh
186
186
  performTargetRef?: RefObject<HTMLElement>;
187
187
  /** Auto-fire onPerform once on mount (useful when restoring persisted state). */
188
188
  performOnMount?: boolean;
189
+ /**
190
+ * Controls when `performAction` (and therefore `onPerform`) fires in response
191
+ * to value/field changes.
192
+ *
193
+ * - `'manual'` (default for standalone use): only fires from the Buscar
194
+ * button, `performOnMount`, or the imperative `perform()` ref. This is the
195
+ * right default for API-backed tables where each perform = a network
196
+ * request.
197
+ * - `'live'`: also fires on every change to the active values, optionally
198
+ * debounced via `performDebounceMs`. Use for in-memory tables where
199
+ * filtering is cheap.
200
+ * - `'auto'`: ask the parent. When the multifilter is bound through a
201
+ * table's `multifilter` prop, the table picks `'live'` for
202
+ * `paginationMode: 'local'` and `'manual'` for `paginationMode: 'api'`.
203
+ * Falls back to `'manual'` for standalone mounts.
204
+ *
205
+ * Default `'auto'`.
206
+ */
207
+ performMode?: 'live' | 'manual' | 'auto';
208
+ /**
209
+ * Debounce window in ms before a `'live'`-mode perform fires after the last
210
+ * change. Default `0` (next-tick).
211
+ */
212
+ performDebounceMs?: number;
189
213
  onPerform?: (snap: MultifilterSnapshot) => void;
190
214
  onChange?: (snap: MultifilterSnapshot) => void;
191
215
  showClearAll?: boolean;
package/dist/index.d.ts CHANGED
@@ -186,6 +186,30 @@ interface EasyVisionMultifilterProps extends BaseStatefulProps<MultifilterSnapsh
186
186
  performTargetRef?: RefObject<HTMLElement>;
187
187
  /** Auto-fire onPerform once on mount (useful when restoring persisted state). */
188
188
  performOnMount?: boolean;
189
+ /**
190
+ * Controls when `performAction` (and therefore `onPerform`) fires in response
191
+ * to value/field changes.
192
+ *
193
+ * - `'manual'` (default for standalone use): only fires from the Buscar
194
+ * button, `performOnMount`, or the imperative `perform()` ref. This is the
195
+ * right default for API-backed tables where each perform = a network
196
+ * request.
197
+ * - `'live'`: also fires on every change to the active values, optionally
198
+ * debounced via `performDebounceMs`. Use for in-memory tables where
199
+ * filtering is cheap.
200
+ * - `'auto'`: ask the parent. When the multifilter is bound through a
201
+ * table's `multifilter` prop, the table picks `'live'` for
202
+ * `paginationMode: 'local'` and `'manual'` for `paginationMode: 'api'`.
203
+ * Falls back to `'manual'` for standalone mounts.
204
+ *
205
+ * Default `'auto'`.
206
+ */
207
+ performMode?: 'live' | 'manual' | 'auto';
208
+ /**
209
+ * Debounce window in ms before a `'live'`-mode perform fires after the last
210
+ * change. Default `0` (next-tick).
211
+ */
212
+ performDebounceMs?: number;
189
213
  onPerform?: (snap: MultifilterSnapshot) => void;
190
214
  onChange?: (snap: MultifilterSnapshot) => void;
191
215
  showClearAll?: boolean;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import './easyvision.css';
2
2
  import './EasyVisionTable.css';
3
3
  import * as React8 from 'react';
4
- import { createContext, forwardRef, useMemo, useState, useEffect, useRef, useCallback, useImperativeHandle, useSyncExternalStore, useContext, createElement } from 'react';
4
+ import { createContext, forwardRef, useMemo, useSyncExternalStore, useRef, useEffect, useCallback, useImperativeHandle, useContext, useState, createElement } from 'react';
5
5
  import { ChevronDown, ChevronUp, Check, Search, X, Plus, ChevronRight, Circle, Calendar as Calendar$1, ChevronLeft, ChevronsUpDown, Loader2, ArrowUp, ArrowDown, ArrowUpDown, Settings2 } from 'lucide-react';
6
6
  import { clsx } from 'clsx';
7
7
  import { twMerge } from 'tailwind-merge';
@@ -1104,6 +1104,8 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
1104
1104
  performPosition = "inline",
1105
1105
  performTargetRef,
1106
1106
  performOnMount = false,
1107
+ performMode = "auto",
1108
+ performDebounceMs = 0,
1107
1109
  onPerform,
1108
1110
  onChange,
1109
1111
  onStateChange,
@@ -1113,6 +1115,7 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
1113
1115
  persist = false,
1114
1116
  clearWhen
1115
1117
  } = props;
1118
+ const resolvedPerformMode = performMode === "live" ? "live" : "manual";
1116
1119
  const labels = { ...DEFAULT_LABELS, ...labelOverrides };
1117
1120
  const showClear = showClearAll ?? editable;
1118
1121
  const initialActive = useMemo(() => {
@@ -1150,17 +1153,17 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
1150
1153
  }) : void 0
1151
1154
  });
1152
1155
  const { activeFields, values, lastConfirmedSnapshotJSON } = slice;
1153
- const [childTick, setChildTick] = useState(0);
1154
- useEffect(() => {
1155
- const unsub = easyVisionRegistry.subscribe(() => setChildTick((t) => t + 1));
1156
- return unsub;
1157
- }, []);
1156
+ const registryState = useSyncExternalStore(
1157
+ easyVisionRegistry.subscribe,
1158
+ easyVisionRegistry.getState,
1159
+ easyVisionRegistry.getState
1160
+ );
1158
1161
  const childSnapshots = useMemo(() => {
1159
1162
  const out = {};
1160
1163
  for (const f of config.fields) {
1161
1164
  if (f.type !== "multifilter") continue;
1162
1165
  const childFullId = `${fullId}.${f.id}-multifilter`;
1163
- const childSlice = easyVisionRegistry.getState().slices[childFullId];
1166
+ const childSlice = registryState.slices[childFullId];
1164
1167
  if (childSlice) {
1165
1168
  out[f.id] = {
1166
1169
  values: childSlice.values,
@@ -1169,7 +1172,7 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
1169
1172
  }
1170
1173
  }
1171
1174
  return out;
1172
- }, [fullId, config.fields, childTick]);
1175
+ }, [fullId, config.fields, registryState]);
1173
1176
  const childQueries = useMemo(() => {
1174
1177
  const out = {};
1175
1178
  for (const f of config.fields) {
@@ -1241,7 +1244,10 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
1241
1244
  const performAction = useCallback(() => {
1242
1245
  const key = buildSnapshotKey({ activeFields, values: composedValues });
1243
1246
  patch({ lastConfirmedSnapshotJSON: key });
1244
- onPerform?.({ ...snapshot, isDirty: false });
1247
+ if (onPerform) {
1248
+ const emitted = { ...snapshot, isDirty: false };
1249
+ queueMicrotask(() => onPerform(emitted));
1250
+ }
1245
1251
  }, [activeFields, composedValues, patch, onPerform, snapshot]);
1246
1252
  const didPerformOnMountRef = useRef(false);
1247
1253
  useEffect(() => {
@@ -1250,6 +1256,28 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
1250
1256
  performAction();
1251
1257
  }
1252
1258
  }, [performOnMount]);
1259
+ const liveTimerRef = useRef(null);
1260
+ const livePrevKeyRef = useRef(null);
1261
+ useEffect(() => {
1262
+ if (resolvedPerformMode !== "live") return;
1263
+ if (livePrevKeyRef.current === null) {
1264
+ livePrevKeyRef.current = snapshotKey;
1265
+ return;
1266
+ }
1267
+ if (livePrevKeyRef.current === snapshotKey) return;
1268
+ livePrevKeyRef.current = snapshotKey;
1269
+ if (liveTimerRef.current !== null) clearTimeout(liveTimerRef.current);
1270
+ liveTimerRef.current = setTimeout(() => {
1271
+ liveTimerRef.current = null;
1272
+ performAction();
1273
+ }, performDebounceMs);
1274
+ return () => {
1275
+ if (liveTimerRef.current !== null) {
1276
+ clearTimeout(liveTimerRef.current);
1277
+ liveTimerRef.current = null;
1278
+ }
1279
+ };
1280
+ }, [snapshotKey, resolvedPerformMode, performDebounceMs, performAction]);
1253
1281
  useImperativeHandle(ref, () => ({
1254
1282
  perform: performAction,
1255
1283
  getSnapshot: () => snapshot
@@ -2531,6 +2559,7 @@ function EasyVisionTable(props) {
2531
2559
  EasyVisionMultifilter,
2532
2560
  {
2533
2561
  ...multifilter,
2562
+ performMode: multifilter.performMode === void 0 || multifilter.performMode === "auto" ? isApi ? "manual" : "live" : multifilter.performMode,
2534
2563
  ref: setMultifilterRef,
2535
2564
  onPerform: handlePerform
2536
2565
  }