@react-querybuilder/core 8.22.1 → 8.22.3
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/cjs/react-querybuilder_core.cjs.development.d.ts +52 -0
- package/dist/cjs/react-querybuilder_core.cjs.development.js +93 -5
- package/dist/cjs/react-querybuilder_core.cjs.development.js.map +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.d.ts +52 -0
- package/dist/cjs/react-querybuilder_core.cjs.production.js +1 -1
- package/dist/cjs/react-querybuilder_core.cjs.production.js.map +1 -1
- package/dist/react-querybuilder_core.d.mts +52 -0
- package/dist/react-querybuilder_core.legacy-esm.d.ts +52 -0
- package/dist/react-querybuilder_core.legacy-esm.js +132 -40
- package/dist/react-querybuilder_core.legacy-esm.js.map +1 -1
- package/dist/react-querybuilder_core.mjs +93 -5
- package/dist/react-querybuilder_core.mjs.map +1 -1
- package/dist/react-querybuilder_core.production.d.mts +52 -0
- package/dist/react-querybuilder_core.production.mjs +1 -1
- package/dist/react-querybuilder_core.production.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -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;
|
|
@@ -6816,7 +6827,8 @@ var QueryManager = class QueryManager {
|
|
|
6816
6827
|
const { optionList: fields, optionsMap: fieldMap } = prepareOptionList({
|
|
6817
6828
|
optionList: options.fields,
|
|
6818
6829
|
baseOption: options.baseField,
|
|
6819
|
-
autoSelectOption: options.autoSelectField
|
|
6830
|
+
autoSelectOption: options.autoSelectField,
|
|
6831
|
+
placeholder: options.translations?.fields
|
|
6820
6832
|
});
|
|
6821
6833
|
this.#fields = freeze(fields, true);
|
|
6822
6834
|
this.#fieldMap = freeze(fieldMap, true);
|
|
@@ -6824,13 +6836,13 @@ var QueryManager = class QueryManager {
|
|
|
6824
6836
|
optionList: options.operators ?? defaultOperators,
|
|
6825
6837
|
baseOption: options.baseOperator,
|
|
6826
6838
|
labelMap: defaultOperatorLabelMap,
|
|
6827
|
-
autoSelectOption: options.autoSelectOperator
|
|
6839
|
+
autoSelectOption: options.autoSelectOperator,
|
|
6840
|
+
placeholder: options.translations?.operators
|
|
6828
6841
|
}).optionList;
|
|
6829
6842
|
this.#combinators = freeze(prepareOptionList({
|
|
6830
6843
|
optionList: options.combinators ?? defaultCombinators,
|
|
6831
6844
|
baseOption: options.baseCombinator
|
|
6832
6845
|
}).optionList, true);
|
|
6833
|
-
this.#query = freeze(query ? prepareRuleGroup(query, { idGenerator: this.#idGenerator }) : this.createRuleGroup(), true);
|
|
6834
6846
|
}
|
|
6835
6847
|
/** Resolves the field configuration for a field name. */
|
|
6836
6848
|
#fieldData(field) {
|
|
@@ -6844,7 +6856,8 @@ var QueryManager = class QueryManager {
|
|
|
6844
6856
|
getOperators: this.#options.getOperators,
|
|
6845
6857
|
operators: this.#operators,
|
|
6846
6858
|
baseOption: this.#options.baseOperator,
|
|
6847
|
-
autoSelectOption: this.#options.autoSelectOperator
|
|
6859
|
+
autoSelectOption: this.#options.autoSelectOperator,
|
|
6860
|
+
placeholder: this.#options.translations?.operators
|
|
6848
6861
|
});
|
|
6849
6862
|
}
|
|
6850
6863
|
/** Resolves the default operator for a field, mirroring `QueryBuilder`'s precedence. */
|
|
@@ -6868,7 +6881,8 @@ var QueryManager = class QueryManager {
|
|
|
6868
6881
|
operator,
|
|
6869
6882
|
fieldData: this.#fieldData(field),
|
|
6870
6883
|
getValues: this.#options.getValues,
|
|
6871
|
-
autoSelectOption: this.#options.autoSelectValue
|
|
6884
|
+
autoSelectOption: this.#options.autoSelectValue,
|
|
6885
|
+
placeholder: this.#options.translations?.values
|
|
6872
6886
|
});
|
|
6873
6887
|
}
|
|
6874
6888
|
#valueEditorTypeFor(field, operator) {
|
|
@@ -7164,6 +7178,79 @@ var QueryManager = class QueryManager {
|
|
|
7164
7178
|
return this;
|
|
7165
7179
|
}
|
|
7166
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
|
+
/**
|
|
7167
7254
|
* Creates an independent manager with the same configuration and the current query.
|
|
7168
7255
|
*
|
|
7169
7256
|
* Subscribers and history are _not_ carried over: the clone starts with no listeners and an
|
|
@@ -7231,6 +7318,7 @@ var QueryManager = class QueryManager {
|
|
|
7231
7318
|
this.#future = snapshot.future;
|
|
7232
7319
|
this.#lastSig = snapshot.lastSig;
|
|
7233
7320
|
this.#lastAt = snapshot.lastAt;
|
|
7321
|
+
this.#reconcileHistoryConfig();
|
|
7234
7322
|
}
|
|
7235
7323
|
throw error;
|
|
7236
7324
|
} finally {
|