@react-querybuilder/core 8.22.2 → 8.22.4

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.
@@ -5893,6 +5893,50 @@ declare class QueryManager<RG extends RuleGroupTypeAny = RuleGroupType, F extend
5893
5893
  * `targetPathOrID` and `sourcePathOrID`.
5894
5894
  */
5895
5895
  group(sourcePathOrID: Path | string, targetPathOrID: Path | string, options?: GroupOptions & StrictOptions): this;
5896
+ /**
5897
+ * The options currently in effect, as a frozen shallow copy. Reflects everything applied by
5898
+ * the constructor and any subsequent {@link QueryManager.reconfigure} calls, but not the
5899
+ * defaults filled in for options that were never provided.
5900
+ */
5901
+ getOptions(): Readonly<QueryManagerOptions<F, O, C>>;
5902
+ /**
5903
+ * Updates the manager's configuration in place, keeping the current query, the undo/redo
5904
+ * history, and every subscriber. Use this to propagate new `translations`, `fields`,
5905
+ * `operators`, and so on without discarding state:
5906
+ *
5907
+ * ```ts
5908
+ * q.reconfigure({ translations: { fields: { placeholderLabel: 'Choisir un champ' } } });
5909
+ * ```
5910
+ *
5911
+ * The incoming options are shallow-merged over the current ones, so keys left out are
5912
+ * preserved. Passing a key explicitly as `undefined` resets it to its default. Object-valued
5913
+ * options like `translations` are replaced wholesale rather than deep-merged — spread the
5914
+ * current value in yourself to patch one key. Pass `{ replace: true }` to discard the
5915
+ * existing options entirely and start from the incoming set.
5916
+ *
5917
+ * The query is never rewritten, even when the new options no longer describe it: a rule whose
5918
+ * `field` is not in the new `fields` list is left as-is. Call
5919
+ * {@link QueryManager.validate validate} to detect that, or `setQuery(getQuery())` to
5920
+ * re-normalize.
5921
+ *
5922
+ * History options are honored immediately: lowering `maxHistory` trims the undo stack, and
5923
+ * turning history off clears both stacks. Subscribers are notified once, and
5924
+ * {@link QueryManager.getConfigVersion} is incremented, even inside a
5925
+ * {@link QueryManager.batch batch} — configuration is not part of a batch's rollback.
5926
+ */
5927
+ reconfigure(options: Partial<QueryManagerOptions<F, O, C>>, config?: {
5928
+ replace?: boolean;
5929
+ }): this;
5930
+ /**
5931
+ * A counter incremented by every {@link QueryManager.reconfigure} call. Because reconfiguring
5932
+ * leaves the query object untouched, subscribers that compare query identity alone cannot see
5933
+ * it; this provides a snapshot that does change.
5934
+ *
5935
+ * Bound to the instance, so it can be passed directly to `useSyncExternalStore` alongside
5936
+ * {@link QueryManager.subscribe}. The `useQueryManager` hook from `react-querybuilder`
5937
+ * already does this.
5938
+ */
5939
+ getConfigVersion: () => number;
5896
5940
  /**
5897
5941
  * Creates an independent manager with the same configuration and the current query.
5898
5942
  *
@@ -6785,6 +6785,8 @@ var QueryManager = class QueryManager {
6785
6785
  #maxHistory;
6786
6786
  #coalesceMs;
6787
6787
  #now;
6788
+ /** Incremented by every {@link QueryManager.reconfigure} call. See `getConfigVersion`. */
6789
+ #configVersion = 0;
6788
6790
  #past = [];
6789
6791
  #future = [];
6790
6792
  #lastSig;
@@ -6802,6 +6804,15 @@ var QueryManager = class QueryManager {
6802
6804
  #idPathIndex;
6803
6805
  #validation;
6804
6806
  constructor(query, options = {}) {
6807
+ this.#applyOptions(options);
6808
+ this.#query = (0, immer.freeze)(query ? prepareRuleGroup(query, { idGenerator: this.#idGenerator }) : this.createRuleGroup(), true);
6809
+ }
6810
+ /**
6811
+ * Assigns `#options` and every field derived from it. Shared by the constructor and
6812
+ * {@link QueryManager.reconfigure}, so the two can never drift apart. Does not touch the
6813
+ * query, the history stacks, the caches, or the subscriber list.
6814
+ */
6815
+ #applyOptions(options) {
6805
6816
  this.#options = options;
6806
6817
  this.#idGenerator = options.idGenerator ?? generateID;
6807
6818
  this.#validator = options.validator ?? defaultValidator;
@@ -6833,7 +6844,6 @@ var QueryManager = class QueryManager {
6833
6844
  optionList: options.combinators ?? defaultCombinators,
6834
6845
  baseOption: options.baseCombinator
6835
6846
  }).optionList, true);
6836
- this.#query = (0, immer.freeze)(query ? prepareRuleGroup(query, { idGenerator: this.#idGenerator }) : this.createRuleGroup(), true);
6837
6847
  }
6838
6848
  /** Resolves the field configuration for a field name. */
6839
6849
  #fieldData(field) {
@@ -7169,6 +7179,79 @@ var QueryManager = class QueryManager {
7169
7179
  return this;
7170
7180
  }
7171
7181
  /**
7182
+ * The options currently in effect, as a frozen shallow copy. Reflects everything applied by
7183
+ * the constructor and any subsequent {@link QueryManager.reconfigure} calls, but not the
7184
+ * defaults filled in for options that were never provided.
7185
+ */
7186
+ getOptions() {
7187
+ return (0, immer.freeze)({ ...this.#options });
7188
+ }
7189
+ /**
7190
+ * Updates the manager's configuration in place, keeping the current query, the undo/redo
7191
+ * history, and every subscriber. Use this to propagate new `translations`, `fields`,
7192
+ * `operators`, and so on without discarding state:
7193
+ *
7194
+ * ```ts
7195
+ * q.reconfigure({ translations: { fields: { placeholderLabel: 'Choisir un champ' } } });
7196
+ * ```
7197
+ *
7198
+ * The incoming options are shallow-merged over the current ones, so keys left out are
7199
+ * preserved. Passing a key explicitly as `undefined` resets it to its default. Object-valued
7200
+ * options like `translations` are replaced wholesale rather than deep-merged — spread the
7201
+ * current value in yourself to patch one key. Pass `{ replace: true }` to discard the
7202
+ * existing options entirely and start from the incoming set.
7203
+ *
7204
+ * The query is never rewritten, even when the new options no longer describe it: a rule whose
7205
+ * `field` is not in the new `fields` list is left as-is. Call
7206
+ * {@link QueryManager.validate validate} to detect that, or `setQuery(getQuery())` to
7207
+ * re-normalize.
7208
+ *
7209
+ * History options are honored immediately: lowering `maxHistory` trims the undo stack, and
7210
+ * turning history off clears both stacks. Subscribers are notified once, and
7211
+ * {@link QueryManager.getConfigVersion} is incremented, even inside a
7212
+ * {@link QueryManager.batch batch} — configuration is not part of a batch's rollback.
7213
+ */
7214
+ reconfigure(options, config) {
7215
+ this.#applyOptions((0, immer.freeze)(config?.replace ? { ...options } : {
7216
+ ...this.#options,
7217
+ ...options
7218
+ }));
7219
+ this.#validation = void 0;
7220
+ this.#reconcileHistoryConfig();
7221
+ ++this.#configVersion;
7222
+ this.#notify();
7223
+ return this;
7224
+ }
7225
+ /**
7226
+ * Brings the history stacks in line with the current history configuration. Unlike
7227
+ * {@link QueryManager.clearHistory}, this does _not_ set `#historyBypassed`: it reflects a
7228
+ * configuration change rather than a deliberate history repositioning, so a later mutation in
7229
+ * the same batch must still be recorded normally.
7230
+ *
7231
+ * Called by {@link QueryManager.reconfigure} and again after a failed
7232
+ * {@link QueryManager.batch batch} restores its snapshot, since that snapshot predates the
7233
+ * configuration change (configuration is not part of a batch's rollback).
7234
+ */
7235
+ #reconcileHistoryConfig() {
7236
+ if (this.#historyEnabled) {
7237
+ if (this.#past.length > this.#maxHistory) this.#past.splice(0, this.#past.length - this.#maxHistory);
7238
+ } else {
7239
+ this.#past = [];
7240
+ this.#future = [];
7241
+ this.#lastSig = void 0;
7242
+ }
7243
+ }
7244
+ /**
7245
+ * A counter incremented by every {@link QueryManager.reconfigure} call. Because reconfiguring
7246
+ * leaves the query object untouched, subscribers that compare query identity alone cannot see
7247
+ * it; this provides a snapshot that does change.
7248
+ *
7249
+ * Bound to the instance, so it can be passed directly to `useSyncExternalStore` alongside
7250
+ * {@link QueryManager.subscribe}. The `useQueryManager` hook from `react-querybuilder`
7251
+ * already does this.
7252
+ */
7253
+ getConfigVersion = () => this.#configVersion;
7254
+ /**
7172
7255
  * Creates an independent manager with the same configuration and the current query.
7173
7256
  *
7174
7257
  * Subscribers and history are _not_ carried over: the clone starts with no listeners and an
@@ -7236,6 +7319,7 @@ var QueryManager = class QueryManager {
7236
7319
  this.#future = snapshot.future;
7237
7320
  this.#lastSig = snapshot.lastSig;
7238
7321
  this.#lastAt = snapshot.lastAt;
7322
+ this.#reconcileHistoryConfig();
7239
7323
  }
7240
7324
  throw error;
7241
7325
  } finally {