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