@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
|
@@ -5671,6 +5671,14 @@ interface QueryManagerOptions<F extends FullField = FullField, O extends FullOpe
|
|
|
5671
5671
|
autoSelectOperator?: boolean;
|
|
5672
5672
|
/** When `false`, an empty placeholder option is prepended to each value list. */
|
|
5673
5673
|
autoSelectValue?: boolean;
|
|
5674
|
+
/**
|
|
5675
|
+
* Translations, accepting the same shape as the `translations` prop. Only the placeholder
|
|
5676
|
+
* properties of `fields`, `operators`, and `values` are used, and only when the corresponding
|
|
5677
|
+
* `autoSelect*` option is `false`; the remaining keys describe UI elements that have no
|
|
5678
|
+
* meaning outside the `QueryBuilder` component. Labels are typed as `unknown` so the React
|
|
5679
|
+
* `Translations` type, whose labels are `ReactNode`, can be passed as-is.
|
|
5680
|
+
*/
|
|
5681
|
+
translations?: Partial<BaseTranslations<unknown>>;
|
|
5674
5682
|
/** The default `field` for rules created by {@link QueryManager.createRule}. */
|
|
5675
5683
|
getDefaultField?: string | ((fieldsData: FullOptionList<F>) => string);
|
|
5676
5684
|
/** The default `operator` for a given field. */
|
|
@@ -5885,6 +5893,50 @@ declare class QueryManager<RG extends RuleGroupTypeAny = RuleGroupType, F extend
|
|
|
5885
5893
|
* `targetPathOrID` and `sourcePathOrID`.
|
|
5886
5894
|
*/
|
|
5887
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;
|
|
5888
5940
|
/**
|
|
5889
5941
|
* Creates an independent manager with the same configuration and the current query.
|
|
5890
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;
|
|
@@ -6817,7 +6828,8 @@ var QueryManager = class QueryManager {
|
|
|
6817
6828
|
const { optionList: fields, optionsMap: fieldMap } = prepareOptionList({
|
|
6818
6829
|
optionList: options.fields,
|
|
6819
6830
|
baseOption: options.baseField,
|
|
6820
|
-
autoSelectOption: options.autoSelectField
|
|
6831
|
+
autoSelectOption: options.autoSelectField,
|
|
6832
|
+
placeholder: options.translations?.fields
|
|
6821
6833
|
});
|
|
6822
6834
|
this.#fields = (0, immer.freeze)(fields, true);
|
|
6823
6835
|
this.#fieldMap = (0, immer.freeze)(fieldMap, true);
|
|
@@ -6825,13 +6837,13 @@ var QueryManager = class QueryManager {
|
|
|
6825
6837
|
optionList: options.operators ?? defaultOperators,
|
|
6826
6838
|
baseOption: options.baseOperator,
|
|
6827
6839
|
labelMap: defaultOperatorLabelMap,
|
|
6828
|
-
autoSelectOption: options.autoSelectOperator
|
|
6840
|
+
autoSelectOption: options.autoSelectOperator,
|
|
6841
|
+
placeholder: options.translations?.operators
|
|
6829
6842
|
}).optionList;
|
|
6830
6843
|
this.#combinators = (0, immer.freeze)(prepareOptionList({
|
|
6831
6844
|
optionList: options.combinators ?? defaultCombinators,
|
|
6832
6845
|
baseOption: options.baseCombinator
|
|
6833
6846
|
}).optionList, true);
|
|
6834
|
-
this.#query = (0, immer.freeze)(query ? prepareRuleGroup(query, { idGenerator: this.#idGenerator }) : this.createRuleGroup(), true);
|
|
6835
6847
|
}
|
|
6836
6848
|
/** Resolves the field configuration for a field name. */
|
|
6837
6849
|
#fieldData(field) {
|
|
@@ -6845,7 +6857,8 @@ var QueryManager = class QueryManager {
|
|
|
6845
6857
|
getOperators: this.#options.getOperators,
|
|
6846
6858
|
operators: this.#operators,
|
|
6847
6859
|
baseOption: this.#options.baseOperator,
|
|
6848
|
-
autoSelectOption: this.#options.autoSelectOperator
|
|
6860
|
+
autoSelectOption: this.#options.autoSelectOperator,
|
|
6861
|
+
placeholder: this.#options.translations?.operators
|
|
6849
6862
|
});
|
|
6850
6863
|
}
|
|
6851
6864
|
/** Resolves the default operator for a field, mirroring `QueryBuilder`'s precedence. */
|
|
@@ -6869,7 +6882,8 @@ var QueryManager = class QueryManager {
|
|
|
6869
6882
|
operator,
|
|
6870
6883
|
fieldData: this.#fieldData(field),
|
|
6871
6884
|
getValues: this.#options.getValues,
|
|
6872
|
-
autoSelectOption: this.#options.autoSelectValue
|
|
6885
|
+
autoSelectOption: this.#options.autoSelectValue,
|
|
6886
|
+
placeholder: this.#options.translations?.values
|
|
6873
6887
|
});
|
|
6874
6888
|
}
|
|
6875
6889
|
#valueEditorTypeFor(field, operator) {
|
|
@@ -7165,6 +7179,79 @@ var QueryManager = class QueryManager {
|
|
|
7165
7179
|
return this;
|
|
7166
7180
|
}
|
|
7167
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
|
+
/**
|
|
7168
7255
|
* Creates an independent manager with the same configuration and the current query.
|
|
7169
7256
|
*
|
|
7170
7257
|
* Subscribers and history are _not_ carried over: the clone starts with no listeners and an
|
|
@@ -7232,6 +7319,7 @@ var QueryManager = class QueryManager {
|
|
|
7232
7319
|
this.#future = snapshot.future;
|
|
7233
7320
|
this.#lastSig = snapshot.lastSig;
|
|
7234
7321
|
this.#lastAt = snapshot.lastAt;
|
|
7322
|
+
this.#reconcileHistoryConfig();
|
|
7235
7323
|
}
|
|
7236
7324
|
throw error;
|
|
7237
7325
|
} finally {
|