@cgarciagarcia/react-query-builder 1.1.0 → 1.3.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/README.md +3 -3
- package/dist/index.js +1 -0
- package/dist/src/actions/filter.js +44 -0
- package/dist/src/actions/include.js +23 -0
- package/dist/src/actions/index.js +3 -0
- package/dist/src/actions/sort.js +26 -0
- package/dist/src/index.js +3 -0
- package/dist/src/useQueryBuilder.js +81 -0
- package/dist/src/utils/alias.js +4 -0
- package/dist/src/utils/build.js +29 -0
- package/dist/src/utils/index.js +2 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +11 -7
- package/.eslintignore +0 -1
- package/.eslintrc.cjs +0 -56
- package/.nvmrc +0 -1
- package/.prettierignore +0 -1
- package/prettier.config.cjs +0 -28
- package/src/actions/filter.ts +0 -46
- package/src/actions/include.ts +0 -14
- package/src/actions/index.ts +0 -5
- package/src/actions/sort.ts +0 -14
- package/src/index.ts +0 -3
- package/src/useQueryBuilder.ts +0 -126
- package/src/utils/alias.ts +0 -11
- package/src/utils/build.ts +0 -31
- package/src/utils/index.ts +0 -3
- package/src/utils/state.ts +0 -8
- package/tsconfig.json +0 -27
package/README.md
CHANGED
|
@@ -18,15 +18,15 @@ using your favorite library for frontend `React.js` using a customize hook which
|
|
|
18
18
|
Here is a simple example:
|
|
19
19
|
|
|
20
20
|
```js
|
|
21
|
-
import {useQueryBuilder} from "@cgarciagarcia/react-
|
|
21
|
+
import {useQueryBuilder} from "@cgarciagarcia/react-query-builder";
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const baseConfig = {
|
|
24
24
|
aliases: {
|
|
25
25
|
"frontend_name": "backend_name",
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const builder = useQueryBuilder(
|
|
29
|
+
const builder = useQueryBuilder(baseConfig)
|
|
30
30
|
.filters("age", 18)
|
|
31
31
|
.sorts("created_at")// by default sorting asc
|
|
32
32
|
.sorts("age", 'desc') // sorting desc
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './src/index';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
21
|
+
import { usingAlias } from "utils";
|
|
22
|
+
export var filterAction = function (attribute, value, state) {
|
|
23
|
+
var _a;
|
|
24
|
+
var alias = usingAlias(state, attribute);
|
|
25
|
+
var prevFilter;
|
|
26
|
+
var allFilters = state.filters.reduce(function (filters, filter) {
|
|
27
|
+
if (filter.attribute === alias) {
|
|
28
|
+
prevFilter = filter;
|
|
29
|
+
return filters;
|
|
30
|
+
}
|
|
31
|
+
return __spreadArray(__spreadArray([], filters, true), [filter], false);
|
|
32
|
+
}, []);
|
|
33
|
+
var val = Array.isArray(value) ? value : [value];
|
|
34
|
+
var newState = __assign(__assign({}, state), { filters: __spreadArray(__spreadArray([], allFilters, true), [
|
|
35
|
+
{
|
|
36
|
+
attribute: attribute,
|
|
37
|
+
value: __spreadArray(__spreadArray([], ((_a = prevFilter === null || prevFilter === void 0 ? void 0 : prevFilter.value) !== null && _a !== void 0 ? _a : []), true), val, true),
|
|
38
|
+
},
|
|
39
|
+
], false) });
|
|
40
|
+
return newState;
|
|
41
|
+
};
|
|
42
|
+
export var clearFilterAction = function (state) {
|
|
43
|
+
return __assign(__assign({}, state), { filters: [] });
|
|
44
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
21
|
+
export var includeAction = function (includes, state) {
|
|
22
|
+
return __assign(__assign({}, state), { includes: __spreadArray(__spreadArray([], state.includes, true), [includes], false) });
|
|
23
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
21
|
+
import { usingAlias } from "index";
|
|
22
|
+
export var sortAction = function (sorts, state) {
|
|
23
|
+
var attribute = sorts[0], direction = sorts[1];
|
|
24
|
+
var attributeAliased = usingAlias(state, attribute);
|
|
25
|
+
return __assign(__assign({}, state), { sorts: __spreadArray(__spreadArray([], state.sorts, true), [[attributeAliased, direction]], false) });
|
|
26
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { useReducer, useState } from "react";
|
|
13
|
+
import { build, clearFilterAction, filterAction, includeAction, sortAction, } from "index";
|
|
14
|
+
var reducer = function (state, action) {
|
|
15
|
+
switch (action === null || action === void 0 ? void 0 : action.type) {
|
|
16
|
+
case "filter": {
|
|
17
|
+
var filter = action.payload;
|
|
18
|
+
return filterAction(filter.attribute, filter.value, state);
|
|
19
|
+
}
|
|
20
|
+
case "clear_filter": {
|
|
21
|
+
return clearFilterAction(state);
|
|
22
|
+
}
|
|
23
|
+
case "include": {
|
|
24
|
+
var includes = action.payload;
|
|
25
|
+
return includeAction(includes, state);
|
|
26
|
+
}
|
|
27
|
+
case "sort": {
|
|
28
|
+
var sorts = action.payload;
|
|
29
|
+
return sortAction(sorts, state);
|
|
30
|
+
}
|
|
31
|
+
default: {
|
|
32
|
+
return __assign({}, state);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var initialState = function () { return ({
|
|
37
|
+
aliases: {},
|
|
38
|
+
filters: [],
|
|
39
|
+
includes: [],
|
|
40
|
+
sorts: [],
|
|
41
|
+
}); };
|
|
42
|
+
export var useQueryBuilder = function (config) {
|
|
43
|
+
if (config === void 0) { config = {}; }
|
|
44
|
+
var init = useState(function () { return initialState(); })[0];
|
|
45
|
+
var _a = useReducer(reducer, init, function (init) {
|
|
46
|
+
var _a;
|
|
47
|
+
return (__assign(__assign({}, init), { aliases: (_a = config === null || config === void 0 ? void 0 : config.aliases) !== null && _a !== void 0 ? _a : {} }));
|
|
48
|
+
}), state = _a[0], dispatch = _a[1];
|
|
49
|
+
var builder = {
|
|
50
|
+
filters: function (attribute, value) {
|
|
51
|
+
dispatch({
|
|
52
|
+
type: "filter",
|
|
53
|
+
payload: { attribute: attribute, value: value },
|
|
54
|
+
});
|
|
55
|
+
return builder;
|
|
56
|
+
},
|
|
57
|
+
build: function () { return build(state); },
|
|
58
|
+
clearFilters: function () {
|
|
59
|
+
dispatch({
|
|
60
|
+
type: "clear_filter",
|
|
61
|
+
payload: undefined,
|
|
62
|
+
});
|
|
63
|
+
return builder;
|
|
64
|
+
},
|
|
65
|
+
includes: function (includes) {
|
|
66
|
+
dispatch({
|
|
67
|
+
type: "include",
|
|
68
|
+
payload: includes,
|
|
69
|
+
});
|
|
70
|
+
return builder;
|
|
71
|
+
},
|
|
72
|
+
sorts: function (attribute, direction) {
|
|
73
|
+
dispatch({
|
|
74
|
+
type: "sort",
|
|
75
|
+
payload: [attribute, direction !== null && direction !== void 0 ? direction : "asc"],
|
|
76
|
+
});
|
|
77
|
+
return builder;
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
return builder;
|
|
81
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
export var build = function (state) {
|
|
13
|
+
var filters = state.filters.reduce(function (acc, filter) {
|
|
14
|
+
var _a;
|
|
15
|
+
return (__assign(__assign({}, acc), (_a = {}, _a["filters[".concat(filter.attribute, "]")] = filter.value.join(","), _a)));
|
|
16
|
+
}, {});
|
|
17
|
+
var sorts = state.sorts.reduce(function (acc, sort) {
|
|
18
|
+
var attribute = sort[0], dir = sort[1];
|
|
19
|
+
var direction = dir === "desc" ? "-" : "";
|
|
20
|
+
acc.push("".concat(direction).concat(attribute));
|
|
21
|
+
return acc;
|
|
22
|
+
}, []);
|
|
23
|
+
var urlSearchParams = new URLSearchParams(__assign({}, filters));
|
|
24
|
+
if (sorts.length > 0) {
|
|
25
|
+
urlSearchParams.append("sort", sorts.join(","));
|
|
26
|
+
}
|
|
27
|
+
var searchParamsString = urlSearchParams.toString();
|
|
28
|
+
return searchParamsString ? "?" + urlSearchParams.toString() : "";
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"program":{"fileNames":["../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es5.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2021.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2022.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2023.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.dom.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.dom.iterable.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2016.intl.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2017.date.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2019.intl.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2021.promise.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2021.string.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2021.weakref.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2021.intl.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2022.array.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2022.error.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2022.intl.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2022.object.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2022.string.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2022.regexp.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2023.array.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2023.collection.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.es2023.intl.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.decorators.d.ts","../node_modules/.pnpm/typescript@5.5.3/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../node_modules/.pnpm/@types+react@18.3.3/node_modules/@types/react/global.d.ts","../node_modules/.pnpm/csstype@3.1.3/node_modules/csstype/index.d.ts","../node_modules/.pnpm/@types+prop-types@15.7.12/node_modules/@types/prop-types/index.d.ts","../node_modules/.pnpm/@types+react@18.3.3/node_modules/@types/react/index.d.ts","../node_modules/.pnpm/@types+react@18.3.3/node_modules/@types/react/jsx-runtime.d.ts","../src/types/index.d.ts","../src/utils/alias.ts","../src/utils/build.ts","../src/utils/index.ts","../src/actions/sort.ts","../src/actions/filter.ts","../src/actions/include.ts","../src/actions/index.ts","../src/usequerybuilder.ts","../src/index.ts","../index.js"],"fileInfos":[{"version":"44e584d4f6444f58791784f1d530875970993129442a847597db702a073ca68c","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","3facaf05f0c5fc569c5649dd359892c98a85557e3e0c847964caeb67076f4d75","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","27bdc30a0e32783366a5abeda841bc22757c1797de8681bbe81fbc735eeb1c10",{"version":"4af6b0c727b7a2896463d512fafd23634229adf69ac7c00e2ae15a09cb084fad","affectsGlobalScope":true},{"version":"9c00a480825408b6a24c63c1b71362232927247595d7c97659bc24dc68ae0757","affectsGlobalScope":true},{"version":"6920e1448680767498a0b77c6a00a8e77d14d62c3da8967b171f1ddffa3c18e4","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"ea011c76963fb15ef1cdd7ce6a6808b46322c527de2077b6cfdf23ae6f5f9ec7","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"9e9fbd7030c440b33d021da145d3232984c8bb7916f277e8ffd3dc2e3eae2bdb","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"74f7fa2d027d5b33eb0471c8e82a6c87216223181ec31247c357a3e8e2fddc5b","affectsGlobalScope":true},{"version":"ae37d6ccd1560b0203ab88d46987393adaaa78c919e51acf32fb82c86502e98c","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"5e07ed3809d48205d5b985642a59f2eba47c402374a7cf8006b686f79efadcbd","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"479553e3779be7d4f68e9f40cdb82d038e5ef7592010100410723ceced22a0f7","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"d3d7b04b45033f57351c8434f60b6be1ea71a2dfec2d0a0c3c83badbb0e3e693","affectsGlobalScope":true},{"version":"956d27abdea9652e8368ce029bb1e0b9174e9678a273529f426df4b3d90abd60","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"e6633e05da3ff36e6da2ec170d0d03ccf33de50ca4dc6f5aeecb572cedd162fb","affectsGlobalScope":true},{"version":"d8670852241d4c6e03f2b89d67497a4bbefe29ecaa5a444e2c11a9b05e6fccc6","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"caccc56c72713969e1cfe5c3d44e5bab151544d9d2b373d7dbe5a1e4166652be","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"b4b67b1a91182421f5df999988c690f14d813b9850b40acd06ed44691f6727ad","affectsGlobalScope":true},{"version":"08a58483392df5fcc1db57d782e87734f77ae9eab42516028acbfe46f29a3ef7","affectsGlobalScope":true},{"version":"436aaf437562f276ec2ddbee2f2cdedac7664c1e4c1d2c36839ddd582eeb3d0a","affectsGlobalScope":true},{"version":"8e3c06ea092138bf9fa5e874a1fdbc9d54805d074bee1de31b99a11e2fec239d","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},{"version":"36a2e4c9a67439aca5f91bb304611d5ae6e20d420503e96c230cf8fcdc948d94","affectsGlobalScope":true},"8a8eb4ebffd85e589a1cc7c178e291626c359543403d58c9cd22b81fab5b1fb9","247a952efd811d780e5630f8cfd76f495196f5fa74f6f0fee39ac8ba4a3c9800",{"version":"8ca4709dbd22a34bcc1ebf93e1877645bdb02ebd3f3d9a211a299a8db2ee4ba1","affectsGlobalScope":true},"42c169fb8c2d42f4f668c624a9a11e719d5d07dacbebb63cbcf7ef365b0a75b3","7df2bbc3af842a0e585285afc1e370a5c6d807f8334a2aee977a363a0f7c481e","3e5bbd3b9984c1a38073687125db23aad8023c3f2f84cfdad530027fc5e7beaa","4107dfe18887c6ad25be8b595397f952c2476597796444b7487b6a752d17bd28","d0091298ea49905c39dbe1aec1f8fa4e042bdc7d2fd479dce3b80bb512f81845","77739f4a6ee562d3e950ebef542b5053d4ede90f9ff12b518b126bc08ec69996","73e305ba4f52c186a753faf136e600c361822107ffab515a8ce4af869953539b","ffc374725cfb39812fb1059a8dfeba5afc6e8142b1275ac68a613cdc4951d63f","4caa6f0205a5c341776d7f97ecc587fb435bcdf583929612dd40fba01a3e33d2","ab09ac72f9328e3975060a11c2ad24ef3bd3487ae3df433741525cb832cd35cb","5fb32e3692cd6391161703f4802f5bfe28ca13fb7f093af58fb0092ae66ffe08","e9a2505933b5e08b66d5d15d2bafd974dc2df0e9fc9a551600b817197c068505"],"root":[69,79],"options":{"allowJs":true,"esModuleInterop":true,"jsx":4,"module":99,"noUncheckedIndexedAccess":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","skipLibCheck":true,"strict":true},"fileIdsList":[[68,78],[64,65,66],[67],[68,69,72],[68,69],[68,73,74,75],[68,69,78],[68,72,76,77],[67,68,69,78],[68,70,71]],"referencedMap":[[79,1],[67,2],[68,3],[74,4],[75,5],[76,6],[73,7],[78,8],[77,9],[70,5],[71,5],[72,10]]},"version":"5.5.3"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cgarciagarcia/react-query-builder",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
},
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
11
10
|
"repository": {
|
|
12
11
|
"type": "git",
|
|
13
12
|
"url": "git+https://github.com/cgarciagarcia/react-query-builder.git"
|
|
@@ -41,5 +40,10 @@
|
|
|
41
40
|
"bugs": {
|
|
42
41
|
"url": "https://github.com/cgarciagarcia/react-query-builder/issues"
|
|
43
42
|
},
|
|
44
|
-
"homepage": "https://github.com/cgarciagarcia/react-query-builder#readme"
|
|
45
|
-
|
|
43
|
+
"homepage": "https://github.com/cgarciagarcia/react-query-builder#readme",
|
|
44
|
+
"scripts": {
|
|
45
|
+
"clean": "rm -rf dist",
|
|
46
|
+
"build": "npm run clean && tsc",
|
|
47
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/.eslintignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
dist/
|
package/.eslintrc.cjs
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/** @type {import('eslint').Linter.Config} */
|
|
2
|
-
const config = {
|
|
3
|
-
extends: [
|
|
4
|
-
'eslint:recommended',
|
|
5
|
-
'plugin:@typescript-eslint/recommended-type-checked',
|
|
6
|
-
'plugin:@typescript-eslint/stylistic-type-checked',
|
|
7
|
-
'plugin:jsx-a11y/recommended',
|
|
8
|
-
'plugin:react-hooks/recommended',
|
|
9
|
-
'plugin:react/recommended',
|
|
10
|
-
'prettier'
|
|
11
|
-
],
|
|
12
|
-
env: {
|
|
13
|
-
es2022: true,
|
|
14
|
-
browser: true,
|
|
15
|
-
commonjs: true
|
|
16
|
-
},
|
|
17
|
-
parser: '@typescript-eslint/parser',
|
|
18
|
-
parserOptions: {
|
|
19
|
-
project: true
|
|
20
|
-
},
|
|
21
|
-
plugins: ['@typescript-eslint', 'import', 'unused-imports'],
|
|
22
|
-
rules: {
|
|
23
|
-
'react/prop-types': 'off',
|
|
24
|
-
'@typescript-eslint/unbound-method': 'off',
|
|
25
|
-
'@typescript-eslint/no-unused-vars': [
|
|
26
|
-
'error',
|
|
27
|
-
{
|
|
28
|
-
argsIgnorePattern: '^_',
|
|
29
|
-
varsIgnorePattern: '^_'
|
|
30
|
-
}
|
|
31
|
-
],
|
|
32
|
-
'unused-imports/no-unused-imports': 'error',
|
|
33
|
-
'@typescript-eslint/consistent-type-imports': [
|
|
34
|
-
'warn',
|
|
35
|
-
{prefer: 'type-imports', fixStyle: 'separate-type-imports'}
|
|
36
|
-
],
|
|
37
|
-
'@typescript-eslint/no-misused-promises': [
|
|
38
|
-
2,
|
|
39
|
-
{checksVoidReturn: {attributes: false}}
|
|
40
|
-
],
|
|
41
|
-
'import/consistent-type-specifier-style': ['error', 'prefer-inline'],
|
|
42
|
-
'import/no-duplicates': 'error',
|
|
43
|
-
'object-curly-spacing': ["warn", "always"]
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
ignorePatterns: ['.eslintrc.cjs', '.config.js', '.config.cjs', '.config.ts'],
|
|
47
|
-
reportUnusedDisableDirectives: true,
|
|
48
|
-
globals: {
|
|
49
|
-
React: 'writable'
|
|
50
|
-
},
|
|
51
|
-
settings: {
|
|
52
|
-
react: {version: 'detect'}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
module.exports = config
|
package/.nvmrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
v20.14.0
|
package/.prettierignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
node_modules/
|
package/prettier.config.cjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/** @typedef {import('@ianvs/prettier-plugin-sort-imports').PluginConfig} SortImportsConfig */
|
|
2
|
-
/** @typedef {import('prettier').Config} PrettierConfig */
|
|
3
|
-
/** @typedef {{ tailwindConfig: string }} TailwindConfig */
|
|
4
|
-
|
|
5
|
-
/** @type { PrettierConfig | SortImportsConfig | TailwindConfig } */
|
|
6
|
-
const config = {
|
|
7
|
-
arrowParens: 'always',
|
|
8
|
-
printWidth: 80,
|
|
9
|
-
singleQuote: false,
|
|
10
|
-
jsxSingleQuote: false,
|
|
11
|
-
semi: true,
|
|
12
|
-
trailingComma: 'all',
|
|
13
|
-
tabWidth: 2,
|
|
14
|
-
plugins: [
|
|
15
|
-
'@ianvs/prettier-plugin-sort-imports',
|
|
16
|
-
],
|
|
17
|
-
importOrder: [
|
|
18
|
-
'^(react/(.*)$)|^(react$)',
|
|
19
|
-
'<THIRD_PARTY_MODULES>',
|
|
20
|
-
'^[../]',
|
|
21
|
-
'^[./]'
|
|
22
|
-
],
|
|
23
|
-
importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'],
|
|
24
|
-
importOrderTypeScriptVersion: '5.0.0',
|
|
25
|
-
bracketSpacing: true
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = config
|
package/src/actions/filter.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { type Alias, type GlobalState, usingAlias, } from "@/utils";
|
|
2
|
-
|
|
3
|
-
export type FilterValue = (string | number)[] | string | number;
|
|
4
|
-
|
|
5
|
-
export interface Filter {
|
|
6
|
-
attribute: string;
|
|
7
|
-
value: (string | number)[];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const filterAction = <Al extends Alias<object>, Attr extends string>(
|
|
11
|
-
attribute: Attr,
|
|
12
|
-
value: FilterValue,
|
|
13
|
-
state: GlobalState<Al>,
|
|
14
|
-
) => {
|
|
15
|
-
const alias = usingAlias(state, attribute);
|
|
16
|
-
let prevFilter: Filter | undefined;
|
|
17
|
-
|
|
18
|
-
const allFilters = state.filters.reduce((filters, filter) => {
|
|
19
|
-
if (filter.attribute === alias) {
|
|
20
|
-
prevFilter = filter;
|
|
21
|
-
return filters;
|
|
22
|
-
}
|
|
23
|
-
return [...filters, filter];
|
|
24
|
-
}, [] as Filter[]);
|
|
25
|
-
|
|
26
|
-
const val = Array.isArray(value) ? value : [value];
|
|
27
|
-
|
|
28
|
-
const newState: GlobalState<Al> = {
|
|
29
|
-
...state,
|
|
30
|
-
filters: [
|
|
31
|
-
...allFilters,
|
|
32
|
-
{
|
|
33
|
-
attribute: attribute,
|
|
34
|
-
value: [...(prevFilter?.value ?? []), ...val],
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
};
|
|
38
|
-
return newState
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export const clearFilterAction = <Al>(state: GlobalState<Al>) => {
|
|
42
|
-
return {
|
|
43
|
-
...state,
|
|
44
|
-
filters: [],
|
|
45
|
-
};
|
|
46
|
-
};
|
package/src/actions/include.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type GlobalState } from "@/index";
|
|
2
|
-
|
|
3
|
-
export type Include = string
|
|
4
|
-
export type Includes = string[];
|
|
5
|
-
|
|
6
|
-
export const includeAction = <T>(
|
|
7
|
-
includes: Include,
|
|
8
|
-
state: GlobalState<T>,
|
|
9
|
-
): GlobalState<T> => {
|
|
10
|
-
return {
|
|
11
|
-
...state,
|
|
12
|
-
includes: [...state.includes, includes],
|
|
13
|
-
} satisfies GlobalState<T>;
|
|
14
|
-
};
|
package/src/actions/index.ts
DELETED
package/src/actions/sort.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { type GlobalState, usingAlias } from "@/index";
|
|
2
|
-
|
|
3
|
-
export type Sort = [string, "asc" | "desc"];
|
|
4
|
-
|
|
5
|
-
export type Sorts = Sort[];
|
|
6
|
-
|
|
7
|
-
export const sortAction = <T>(sorts: Sort, state: GlobalState<T>) => {
|
|
8
|
-
const [attribute, direction] = sorts;
|
|
9
|
-
const attributeAliased = usingAlias(state, attribute);
|
|
10
|
-
return {
|
|
11
|
-
...state,
|
|
12
|
-
sorts: [...state.sorts, [attributeAliased, direction]],
|
|
13
|
-
} satisfies GlobalState<T>;
|
|
14
|
-
};
|
package/src/index.ts
DELETED
package/src/useQueryBuilder.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { useReducer, useState } from "react";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
type Actions,
|
|
5
|
-
type Alias,
|
|
6
|
-
build,
|
|
7
|
-
clearFilterAction,
|
|
8
|
-
type Filter,
|
|
9
|
-
filterAction,
|
|
10
|
-
type FilterValue,
|
|
11
|
-
type GlobalState,
|
|
12
|
-
type Include,
|
|
13
|
-
includeAction,
|
|
14
|
-
type Sort,
|
|
15
|
-
sortAction,
|
|
16
|
-
} from "@/index";
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
interface Action {
|
|
20
|
-
type: Actions;
|
|
21
|
-
payload: unknown;
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const reducer = <Aliases extends Record<string, string>>(
|
|
26
|
-
state: GlobalState<Aliases>,
|
|
27
|
-
action: Action,
|
|
28
|
-
) => {
|
|
29
|
-
switch (action?.type) {
|
|
30
|
-
case "filter": {
|
|
31
|
-
const filter = action.payload as Filter;
|
|
32
|
-
return filterAction(filter.attribute, filter.value, state);
|
|
33
|
-
}
|
|
34
|
-
case "clear_filter": {
|
|
35
|
-
return clearFilterAction(state);
|
|
36
|
-
}
|
|
37
|
-
case "include": {
|
|
38
|
-
const includes = action.payload as Include;
|
|
39
|
-
return includeAction(includes, state);
|
|
40
|
-
}
|
|
41
|
-
case "sort": {
|
|
42
|
-
const sorts = action.payload as Sort;
|
|
43
|
-
return sortAction(sorts, state);
|
|
44
|
-
}
|
|
45
|
-
default: {
|
|
46
|
-
return { ...state };
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const initialState = <T>(): GlobalState<T> => ({
|
|
53
|
-
aliases: {} as Alias<T>,
|
|
54
|
-
filters: [],
|
|
55
|
-
includes: [],
|
|
56
|
-
sorts: [],
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
export interface QueryBuilder<AliasType = NonNullable<unknown>> {
|
|
60
|
-
filters: (
|
|
61
|
-
attribute: keyof AliasType | string,
|
|
62
|
-
value: FilterValue,
|
|
63
|
-
) => QueryBuilder<AliasType>;
|
|
64
|
-
build: () => string;
|
|
65
|
-
clearFilters: () => QueryBuilder<AliasType>;
|
|
66
|
-
includes: (includes: Include) => QueryBuilder<AliasType>;
|
|
67
|
-
sorts: (
|
|
68
|
-
attribute: string,
|
|
69
|
-
direction?: "asc" | "desc",
|
|
70
|
-
) => QueryBuilder<AliasType>;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
type ExtensibleQueryProps<T> = Pick<
|
|
74
|
-
QueryBuilder<T>,
|
|
75
|
-
"filters" | "includes" | "sorts"
|
|
76
|
-
>;
|
|
77
|
-
|
|
78
|
-
interface QueryBuilderProps<AliasType> extends ExtensibleQueryProps<AliasType> {
|
|
79
|
-
aliases?: AliasType;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export const useQueryBuilder: <Aliases extends Record<string, string>>(
|
|
83
|
-
config?: QueryBuilderProps<Aliases>,
|
|
84
|
-
) => QueryBuilder<Aliases> = <Aliases extends Record<string, string>>(
|
|
85
|
-
config = {} as QueryBuilderProps<Aliases>,
|
|
86
|
-
) => {
|
|
87
|
-
const [init] = useState(() => initialState<Aliases>());
|
|
88
|
-
const [state, dispatch] = useReducer(reducer, init, (init) => ({
|
|
89
|
-
...init,
|
|
90
|
-
aliases: config?.aliases ?? ({} as Aliases),
|
|
91
|
-
}));
|
|
92
|
-
|
|
93
|
-
const builder: QueryBuilder<Aliases> = {
|
|
94
|
-
filters: (attribute, value) => {
|
|
95
|
-
dispatch({
|
|
96
|
-
type: "filter",
|
|
97
|
-
payload: { attribute, value },
|
|
98
|
-
});
|
|
99
|
-
return builder;
|
|
100
|
-
},
|
|
101
|
-
build: () => build(state),
|
|
102
|
-
clearFilters: () => {
|
|
103
|
-
dispatch({
|
|
104
|
-
type: "clear_filter",
|
|
105
|
-
payload: undefined,
|
|
106
|
-
});
|
|
107
|
-
return builder;
|
|
108
|
-
},
|
|
109
|
-
includes: (includes) => {
|
|
110
|
-
dispatch({
|
|
111
|
-
type: "include",
|
|
112
|
-
payload: includes,
|
|
113
|
-
});
|
|
114
|
-
return builder;
|
|
115
|
-
},
|
|
116
|
-
sorts: (attribute, direction) => {
|
|
117
|
-
dispatch({
|
|
118
|
-
type: "sort",
|
|
119
|
-
payload: [attribute, direction ?? "asc"],
|
|
120
|
-
});
|
|
121
|
-
return builder;
|
|
122
|
-
},
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
return builder;
|
|
126
|
-
};
|
package/src/utils/alias.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { type GlobalState } from "@/index";
|
|
2
|
-
|
|
3
|
-
export const usingAlias = <Al, K>(state: GlobalState<Al>, key: K) => {
|
|
4
|
-
return (state.aliases[key as unknown as keyof Al] as string) ?? key;
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export type Alias<Prop> = {
|
|
9
|
-
[key in keyof Prop]: Prop[key] extends string ? string : never;
|
|
10
|
-
};
|
|
11
|
-
|
package/src/utils/build.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { type GlobalState } from "@/utils/state";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export const build = <T>(state: GlobalState<T>): string => {
|
|
5
|
-
const filters = state.filters.reduce(
|
|
6
|
-
(acc, filter) => ({
|
|
7
|
-
...acc,
|
|
8
|
-
[`filters[${filter.attribute}]`]: filter.value.join(","),
|
|
9
|
-
}),
|
|
10
|
-
{},
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
const sorts = state.sorts.reduce((acc, sort) => {
|
|
14
|
-
const [attribute, dir] = sort;
|
|
15
|
-
const direction = dir === "desc" ? "-" : "";
|
|
16
|
-
acc.push(`${direction}${attribute}`);
|
|
17
|
-
return acc;
|
|
18
|
-
}, [] as string[]);
|
|
19
|
-
|
|
20
|
-
const urlSearchParams = new URLSearchParams({
|
|
21
|
-
...filters,
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
if (sorts.length > 0) {
|
|
25
|
-
urlSearchParams.append("sort", sorts.join(","));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const searchParamsString = urlSearchParams.toString();
|
|
29
|
-
|
|
30
|
-
return searchParamsString ? "?" + urlSearchParams.toString() : "";
|
|
31
|
-
};
|
package/src/utils/index.ts
DELETED
package/src/utils/state.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"allowJs": true,
|
|
4
|
-
"baseUrl": "./src",
|
|
5
|
-
"esModuleInterop": true,
|
|
6
|
-
"forceConsistentCasingInFileNames": true,
|
|
7
|
-
"incremental": true,
|
|
8
|
-
"isolatedModules": true,
|
|
9
|
-
"jsx": "react-jsx",
|
|
10
|
-
"outDir": "./dist",
|
|
11
|
-
"noUnusedParameters": true,
|
|
12
|
-
"noUnusedLocals": true,
|
|
13
|
-
"noUncheckedIndexedAccess": true,
|
|
14
|
-
"paths": {
|
|
15
|
-
"@/*": [
|
|
16
|
-
"./*"
|
|
17
|
-
]
|
|
18
|
-
},
|
|
19
|
-
"resolveJsonModule": true,
|
|
20
|
-
"skipLibCheck": true,
|
|
21
|
-
"strict": true
|
|
22
|
-
},
|
|
23
|
-
"type": "module",
|
|
24
|
-
"exclude": [
|
|
25
|
-
"./*.config.cjs"
|
|
26
|
-
]
|
|
27
|
-
}
|