@easyvision/easyvision-ui 1.4.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/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';
@@ -41,10 +41,11 @@ Input.displayName = "Input";
41
41
  var easyVisionRegistry = createStore((set, get) => ({
42
42
  slices: {},
43
43
  ensure: (_kind, fullId, init) => {
44
- const existing = get().slices[fullId];
44
+ const state = get();
45
+ const existing = state.slices[fullId];
45
46
  if (existing) return existing;
46
47
  const created = init();
47
- set((s) => ({ slices: { ...s.slices, [fullId]: created } }));
48
+ state.slices[fullId] = created;
48
49
  return created;
49
50
  },
50
51
  patch: (fullId, partial) => {
@@ -1104,6 +1105,8 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
1104
1105
  performPosition = "inline",
1105
1106
  performTargetRef,
1106
1107
  performOnMount = false,
1108
+ performMode = "auto",
1109
+ performDebounceMs = 0,
1107
1110
  onPerform,
1108
1111
  onChange,
1109
1112
  onStateChange,
@@ -1113,6 +1116,7 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
1113
1116
  persist = false,
1114
1117
  clearWhen
1115
1118
  } = props;
1119
+ const resolvedPerformMode = performMode === "live" ? "live" : "manual";
1116
1120
  const labels = { ...DEFAULT_LABELS, ...labelOverrides };
1117
1121
  const showClear = showClearAll ?? editable;
1118
1122
  const initialActive = useMemo(() => {
@@ -1150,17 +1154,17 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
1150
1154
  }) : void 0
1151
1155
  });
1152
1156
  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
- }, []);
1157
+ const registryState = useSyncExternalStore(
1158
+ easyVisionRegistry.subscribe,
1159
+ easyVisionRegistry.getState,
1160
+ easyVisionRegistry.getState
1161
+ );
1158
1162
  const childSnapshots = useMemo(() => {
1159
1163
  const out = {};
1160
1164
  for (const f of config.fields) {
1161
1165
  if (f.type !== "multifilter") continue;
1162
1166
  const childFullId = `${fullId}.${f.id}-multifilter`;
1163
- const childSlice = easyVisionRegistry.getState().slices[childFullId];
1167
+ const childSlice = registryState.slices[childFullId];
1164
1168
  if (childSlice) {
1165
1169
  out[f.id] = {
1166
1170
  values: childSlice.values,
@@ -1169,7 +1173,7 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
1169
1173
  }
1170
1174
  }
1171
1175
  return out;
1172
- }, [fullId, config.fields, childTick]);
1176
+ }, [fullId, config.fields, registryState]);
1173
1177
  const childQueries = useMemo(() => {
1174
1178
  const out = {};
1175
1179
  for (const f of config.fields) {
@@ -1241,7 +1245,10 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
1241
1245
  const performAction = useCallback(() => {
1242
1246
  const key = buildSnapshotKey({ activeFields, values: composedValues });
1243
1247
  patch({ lastConfirmedSnapshotJSON: key });
1244
- onPerform?.({ ...snapshot, isDirty: false });
1248
+ if (onPerform) {
1249
+ const emitted = { ...snapshot, isDirty: false };
1250
+ queueMicrotask(() => onPerform(emitted));
1251
+ }
1245
1252
  }, [activeFields, composedValues, patch, onPerform, snapshot]);
1246
1253
  const didPerformOnMountRef = useRef(false);
1247
1254
  useEffect(() => {
@@ -1250,6 +1257,28 @@ var EasyVisionMultifilter = forwardRef(function EasyVisionMultifilter2(props, re
1250
1257
  performAction();
1251
1258
  }
1252
1259
  }, [performOnMount]);
1260
+ const liveTimerRef = useRef(null);
1261
+ const livePrevKeyRef = useRef(null);
1262
+ useEffect(() => {
1263
+ if (resolvedPerformMode !== "live") return;
1264
+ if (livePrevKeyRef.current === null) {
1265
+ livePrevKeyRef.current = snapshotKey;
1266
+ return;
1267
+ }
1268
+ if (livePrevKeyRef.current === snapshotKey) return;
1269
+ livePrevKeyRef.current = snapshotKey;
1270
+ if (liveTimerRef.current !== null) clearTimeout(liveTimerRef.current);
1271
+ liveTimerRef.current = setTimeout(() => {
1272
+ liveTimerRef.current = null;
1273
+ performAction();
1274
+ }, performDebounceMs);
1275
+ return () => {
1276
+ if (liveTimerRef.current !== null) {
1277
+ clearTimeout(liveTimerRef.current);
1278
+ liveTimerRef.current = null;
1279
+ }
1280
+ };
1281
+ }, [snapshotKey, resolvedPerformMode, performDebounceMs, performAction]);
1253
1282
  useImperativeHandle(ref, () => ({
1254
1283
  perform: performAction,
1255
1284
  getSnapshot: () => snapshot
@@ -2531,6 +2560,7 @@ function EasyVisionTable(props) {
2531
2560
  EasyVisionMultifilter,
2532
2561
  {
2533
2562
  ...multifilter,
2563
+ performMode: multifilter.performMode === void 0 || multifilter.performMode === "auto" ? isApi ? "manual" : "live" : multifilter.performMode,
2534
2564
  ref: setMultifilterRef,
2535
2565
  onPerform: handlePerform
2536
2566
  }