@react-fabric/searchbar 1.0.0-beta.0
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/LICENSE +21 -0
- package/README.md +10 -0
- package/dist/cjs/filterbar/Context.js +34 -0
- package/dist/cjs/filterbar/FilterBar.js +149 -0
- package/dist/cjs/filterbar/FilterEdit.js +51 -0
- package/dist/cjs/filterbar/FilterForm.js +262 -0
- package/dist/cjs/filterbar/FilterMenu.js +80 -0
- package/dist/cjs/filterbar/FilterTag.js +93 -0
- package/dist/cjs/filterbar/FilterView.js +88 -0
- package/dist/cjs/filterbar/QueryForm.js +135 -0
- package/dist/cjs/i18n/ar.json.js +84 -0
- package/dist/cjs/i18n/en.json.js +84 -0
- package/dist/cjs/i18n/index.js +33 -0
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/searchbar/SearchBar.js +154 -0
- package/dist/cjs/types/index.js +70 -0
- package/dist/esm/filterbar/Context.js +33 -0
- package/dist/esm/filterbar/FilterBar.js +149 -0
- package/dist/esm/filterbar/FilterEdit.js +51 -0
- package/dist/esm/filterbar/FilterForm.js +262 -0
- package/dist/esm/filterbar/FilterMenu.js +80 -0
- package/dist/esm/filterbar/FilterTag.js +93 -0
- package/dist/esm/filterbar/FilterView.js +88 -0
- package/dist/esm/filterbar/QueryForm.js +135 -0
- package/dist/esm/i18n/ar.json.js +77 -0
- package/dist/esm/i18n/en.json.js +77 -0
- package/dist/esm/i18n/index.js +33 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/searchbar/SearchBar.js +154 -0
- package/dist/esm/types/index.js +68 -0
- package/dist/types/filterbar/Context.d.ts +4 -0
- package/dist/types/filterbar/FilterBar.d.ts +2 -0
- package/dist/types/filterbar/FilterEdit.d.ts +6 -0
- package/dist/types/filterbar/FilterForm.d.ts +6 -0
- package/dist/types/filterbar/FilterMenu.d.ts +7 -0
- package/dist/types/filterbar/FilterTag.d.ts +6 -0
- package/dist/types/filterbar/FilterView.d.ts +5 -0
- package/dist/types/filterbar/QueryForm.d.ts +6 -0
- package/dist/types/i18n/index.d.ts +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/searchbar/SearchBar.d.ts +2 -0
- package/dist/types/types/index.d.ts +203 -0
- package/package.json +56 -0
- package/src/filterbar/Context.tsx +31 -0
- package/src/filterbar/FilterBar.tsx +195 -0
- package/src/filterbar/FilterEdit.tsx +70 -0
- package/src/filterbar/FilterForm.tsx +281 -0
- package/src/filterbar/FilterMenu.tsx +100 -0
- package/src/filterbar/FilterTag.tsx +114 -0
- package/src/filterbar/FilterView.tsx +89 -0
- package/src/filterbar/QueryForm.tsx +151 -0
- package/src/i18n/ar.json +68 -0
- package/src/i18n/en.json +68 -0
- package/src/i18n/index.ts +28 -0
- package/src/index.ts +32 -0
- package/src/searchbar/SearchBar.tsx +162 -0
- package/src/types/index.ts +315 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 React Fabric, Adarsh Pastakia
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* React Fabric
|
|
7
|
+
* @version: 1.0.0
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* The MIT License (MIT)
|
|
11
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
14
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
15
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
16
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
17
|
+
* subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
20
|
+
* portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
23
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
24
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
25
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
var FilterContext = /*#__PURE__*/react.createContext({});
|
|
29
|
+
var useFilterContext = function useFilterContext() {
|
|
30
|
+
return react.useContext(FilterContext);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
exports.FilterContext = FilterContext;
|
|
34
|
+
exports.useFilterContext = useFilterContext;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
+
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
5
|
+
var core = require('@react-fabric/core');
|
|
6
|
+
var utilities = require('@react-fabric/utilities');
|
|
7
|
+
var react = require('react');
|
|
8
|
+
var reactI18next = require('react-i18next');
|
|
9
|
+
var FilterEdit = require('./FilterEdit.js');
|
|
10
|
+
var FilterTag = require('./FilterTag.js');
|
|
11
|
+
var classNames = require('classnames');
|
|
12
|
+
var Context = require('./Context.js');
|
|
13
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
14
|
+
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
+
var FilterBar = function FilterBar(_ref) {
|
|
18
|
+
var _ref$filters = _ref.filters,
|
|
19
|
+
filters = _ref$filters === void 0 ? [] : _ref$filters,
|
|
20
|
+
allowAdd = _ref.allowAdd,
|
|
21
|
+
fields = _ref.fields,
|
|
22
|
+
querySchema = _ref.querySchema,
|
|
23
|
+
defaultQuery = _ref.defaultQuery,
|
|
24
|
+
includedColor = _ref.includedColor,
|
|
25
|
+
excludedColor = _ref.excludedColor,
|
|
26
|
+
onFilterChanged = _ref.onFilterChanged;
|
|
27
|
+
var _useTranslation = reactI18next.useTranslation("searchbar"),
|
|
28
|
+
t = _useTranslation.t;
|
|
29
|
+
var handleRemove = react.useCallback(function (index) {
|
|
30
|
+
var list = _toConsumableArray(filters);
|
|
31
|
+
list.splice(index, 1);
|
|
32
|
+
onFilterChanged === null || onFilterChanged === void 0 || onFilterChanged(list);
|
|
33
|
+
}, [filters]);
|
|
34
|
+
var handleChange = react.useCallback(function (filter, index) {
|
|
35
|
+
var list = _toConsumableArray(filters);
|
|
36
|
+
utilities.isNil(index) ? list.push(filter) : list.splice(index, 1, filter);
|
|
37
|
+
onFilterChanged === null || onFilterChanged === void 0 || onFilterChanged(list);
|
|
38
|
+
}, [filters]);
|
|
39
|
+
var handleToggle = react.useCallback(function (type) {
|
|
40
|
+
var list = [];
|
|
41
|
+
if (type === "removeAll") {
|
|
42
|
+
list.push.apply(list, _toConsumableArray(filters.filter(function (filter) {
|
|
43
|
+
return filter.required;
|
|
44
|
+
})));
|
|
45
|
+
}
|
|
46
|
+
if (type !== "removeAll") {
|
|
47
|
+
list.push.apply(list, _toConsumableArray(filters.map(function (filter) {
|
|
48
|
+
if (type === "disableAll") filter.disabled = true;
|
|
49
|
+
if (type === "enableAll") filter.disabled = false;
|
|
50
|
+
if (type === "toggleDisable") filter.disabled = !filter.disabled;
|
|
51
|
+
if (type === "excludeAll") filter.negate = true;
|
|
52
|
+
if (type === "includeAll") filter.negate = false;
|
|
53
|
+
if (type === "invertAll") filter.negate = !filter.negate;
|
|
54
|
+
return _objectSpread({}, filter);
|
|
55
|
+
})));
|
|
56
|
+
}
|
|
57
|
+
onFilterChanged === null || onFilterChanged === void 0 || onFilterChanged(list);
|
|
58
|
+
}, [filters]);
|
|
59
|
+
var menuItems = react.useMemo(function () {
|
|
60
|
+
var key = {
|
|
61
|
+
someDisabled: false,
|
|
62
|
+
someEnabled: false,
|
|
63
|
+
someExcluded: false,
|
|
64
|
+
someIncluded: false,
|
|
65
|
+
canRemoveAll: false
|
|
66
|
+
};
|
|
67
|
+
filters.forEach(function (filter) {
|
|
68
|
+
if (filter.disabled && filter.canDisable !== false && !key.someDisabled) key.someDisabled = true;
|
|
69
|
+
if (!filter.disabled && filter.canDisable !== false && !key.someEnabled) key.someEnabled = true;
|
|
70
|
+
if (filter.negate && filter.canInvert !== false && !key.someExcluded) key.someExcluded = true;
|
|
71
|
+
if (!filter.negate && filter.canInvert !== false && !key.someIncluded) key.someIncluded = true;
|
|
72
|
+
if (!filter.required && !key.canRemoveAll) key.canRemoveAll = true;
|
|
73
|
+
});
|
|
74
|
+
return key;
|
|
75
|
+
}, [filters]);
|
|
76
|
+
return /*#__PURE__*/jsxRuntime.jsx(Context.FilterContext.Provider, {
|
|
77
|
+
value: {
|
|
78
|
+
defaultQuery: defaultQuery,
|
|
79
|
+
querySchema: querySchema,
|
|
80
|
+
fields: fields
|
|
81
|
+
},
|
|
82
|
+
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
83
|
+
className: "flex flex-wrap gap-1 items-center",
|
|
84
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs(core.Dropdown, {
|
|
85
|
+
showArrow: true,
|
|
86
|
+
disabled: utilities.isEmpty(filters),
|
|
87
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
88
|
+
icon: core.CoreIcons.config,
|
|
89
|
+
className: classNames(utilities.isEmpty(filters) && "pointer-events-none opacity-30"),
|
|
90
|
+
color: !utilities.isEmpty(filters) ? "primary" : undefined
|
|
91
|
+
}), /*#__PURE__*/jsxRuntime.jsxs(core.Menu, {
|
|
92
|
+
className: "text-sm",
|
|
93
|
+
onClick: handleToggle,
|
|
94
|
+
children: [menuItems.someDisabled && /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
95
|
+
id: "enableAll",
|
|
96
|
+
label: t("label.enableAll")
|
|
97
|
+
}), menuItems.someEnabled && /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
98
|
+
id: "disableAll",
|
|
99
|
+
label: t("label.disableAll")
|
|
100
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
101
|
+
icon: core.CoreIcons.invertDisable,
|
|
102
|
+
id: "toggleDisable",
|
|
103
|
+
label: t("label.toggleDisable")
|
|
104
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Divider, {}), menuItems.someExcluded && /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
105
|
+
id: "includeAll",
|
|
106
|
+
label: t("label.includeAll")
|
|
107
|
+
}), menuItems.someIncluded && /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
108
|
+
id: "excludeAll",
|
|
109
|
+
label: t("label.excludeAll")
|
|
110
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
111
|
+
id: "invertAll",
|
|
112
|
+
icon: core.CoreIcons.invertExclude,
|
|
113
|
+
label: t("label.invertAll")
|
|
114
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Divider, {}), /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
115
|
+
id: "removeAll",
|
|
116
|
+
color: "danger",
|
|
117
|
+
icon: core.CoreIcons.remove,
|
|
118
|
+
label: t("label.removeAll"),
|
|
119
|
+
disabled: !menuItems.canRemoveAll
|
|
120
|
+
})]
|
|
121
|
+
})]
|
|
122
|
+
}), filters === null || filters === void 0 ? void 0 : filters.map(function (filter, idx) {
|
|
123
|
+
return /*#__PURE__*/jsxRuntime.jsx(FilterTag.FilterTag, {
|
|
124
|
+
filter: filter,
|
|
125
|
+
includedColor: includedColor,
|
|
126
|
+
excludedColor: excludedColor,
|
|
127
|
+
onRemove: function onRemove() {
|
|
128
|
+
return handleRemove(idx);
|
|
129
|
+
},
|
|
130
|
+
onChange: function onChange(filter) {
|
|
131
|
+
return handleChange(filter, idx);
|
|
132
|
+
}
|
|
133
|
+
}, idx);
|
|
134
|
+
}), allowAdd && /*#__PURE__*/jsxRuntime.jsxs(core.Dropdown, {
|
|
135
|
+
showArrow: true,
|
|
136
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(core.Chip, {
|
|
137
|
+
size: "sm",
|
|
138
|
+
className: "!outline-dashed !outline-tint-400",
|
|
139
|
+
icon: core.CoreIcons.insert,
|
|
140
|
+
children: t("label.add")
|
|
141
|
+
}), /*#__PURE__*/jsxRuntime.jsx(FilterEdit.FilterEdit, {
|
|
142
|
+
onChange: handleChange
|
|
143
|
+
})]
|
|
144
|
+
})]
|
|
145
|
+
})
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
exports.FilterBar = FilterBar;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
4
|
+
var utilities = require('@react-fabric/utilities');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var reactI18next = require('react-i18next');
|
|
7
|
+
var Context = require('./Context.js');
|
|
8
|
+
var FilterForm = require('./FilterForm.js');
|
|
9
|
+
var QueryForm = require('./QueryForm.js');
|
|
10
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
11
|
+
|
|
12
|
+
var FilterEdit = function FilterEdit(_ref) {
|
|
13
|
+
var filter = _ref.filter,
|
|
14
|
+
onRemove = _ref.onRemove,
|
|
15
|
+
onChange = _ref.onChange;
|
|
16
|
+
var _useTranslation = reactI18next.useTranslation("searchbar"),
|
|
17
|
+
t = _useTranslation.t;
|
|
18
|
+
var _useFilterContext = Context.useFilterContext(),
|
|
19
|
+
fields = _useFilterContext.fields;
|
|
20
|
+
var _useState = react.useState(utilities.isEmpty(fields)),
|
|
21
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
22
|
+
queryEdit = _useState2[0],
|
|
23
|
+
setQueryEdit = _useState2[1];
|
|
24
|
+
react.useEffect(function () {
|
|
25
|
+
setQueryEdit(!!filter && "query" in filter);
|
|
26
|
+
}, [filter]);
|
|
27
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
28
|
+
className: "px-2 py-1 bg-base outline min-w-[420px]",
|
|
29
|
+
children: [!utilities.isEmpty(fields) && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
30
|
+
className: "pb-4 flex justify-end",
|
|
31
|
+
children: /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
32
|
+
role: "none",
|
|
33
|
+
className: "text-sm link",
|
|
34
|
+
onClick: function onClick() {
|
|
35
|
+
return setQueryEdit(!queryEdit);
|
|
36
|
+
},
|
|
37
|
+
children: t(queryEdit ? "label.basicFilter" : "label.customQuery")
|
|
38
|
+
})
|
|
39
|
+
}), !queryEdit && /*#__PURE__*/jsxRuntime.jsx(FilterForm.FilterForm, {
|
|
40
|
+
filter: filter,
|
|
41
|
+
onRemove: onRemove,
|
|
42
|
+
onChange: onChange
|
|
43
|
+
}), queryEdit && /*#__PURE__*/jsxRuntime.jsx(QueryForm.QueryForm, {
|
|
44
|
+
filter: filter,
|
|
45
|
+
onRemove: onRemove,
|
|
46
|
+
onChange: onChange
|
|
47
|
+
})]
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.FilterEdit = FilterEdit;
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
4
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
5
|
+
var react = require('@floating-ui/react');
|
|
6
|
+
var core = require('@react-fabric/core');
|
|
7
|
+
var form = require('@react-fabric/form');
|
|
8
|
+
var utilities = require('@react-fabric/utilities');
|
|
9
|
+
var react$1 = require('react');
|
|
10
|
+
var reactI18next = require('react-i18next');
|
|
11
|
+
var index = require('../types/index.js');
|
|
12
|
+
var Context = require('./Context.js');
|
|
13
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
14
|
+
|
|
15
|
+
var FilterSchema = new utilities.yup.ObjectSchema({
|
|
16
|
+
id: utilities.yup.string().required(),
|
|
17
|
+
field: utilities.yup.string().required(),
|
|
18
|
+
operator: utilities.yup.string().required().oneOf(Object.values(index.OPERATOR)),
|
|
19
|
+
negate: utilities.yup["boolean"](),
|
|
20
|
+
label: utilities.yup.string(),
|
|
21
|
+
value: utilities.yup.mixed().when("operator", {
|
|
22
|
+
is: index.OPERATOR.EXISTS,
|
|
23
|
+
then: function then(schema) {
|
|
24
|
+
return schema.optional();
|
|
25
|
+
},
|
|
26
|
+
otherwise: function otherwise(schema) {
|
|
27
|
+
return schema.required();
|
|
28
|
+
}
|
|
29
|
+
}).when("operator", {
|
|
30
|
+
is: index.OPERATOR.IN,
|
|
31
|
+
then: function then(schema) {
|
|
32
|
+
return schema.test({
|
|
33
|
+
name: "array-check",
|
|
34
|
+
message: "${path} is a required field",
|
|
35
|
+
test: function test() {
|
|
36
|
+
var val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
37
|
+
return (val === null || val === void 0 ? void 0 : val.length) > 0;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
var FilterForm = function FilterForm(_ref) {
|
|
44
|
+
var filter = _ref.filter,
|
|
45
|
+
onChange = _ref.onChange,
|
|
46
|
+
onRemove = _ref.onRemove;
|
|
47
|
+
var _useTranslation = reactI18next.useTranslation("searchbar"),
|
|
48
|
+
t = _useTranslation.t;
|
|
49
|
+
var tree = react.useFloatingTree();
|
|
50
|
+
var _useFilterContext = Context.useFilterContext(),
|
|
51
|
+
_useFilterContext$fie = _useFilterContext.fields,
|
|
52
|
+
fields = _useFilterContext$fie === void 0 ? [] : _useFilterContext$fie;
|
|
53
|
+
var inputRef = react$1.useRef(null);
|
|
54
|
+
var formRef = react$1.useRef(null);
|
|
55
|
+
var _useState = react$1.useState(filter),
|
|
56
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
57
|
+
values = _useState2[0],
|
|
58
|
+
setValues = _useState2[1];
|
|
59
|
+
react$1.useEffect(function () {
|
|
60
|
+
if (filter && "field" in filter && filter.field) return setValues(filter);
|
|
61
|
+
setValues({
|
|
62
|
+
id: utilities.shortHash(),
|
|
63
|
+
field: "",
|
|
64
|
+
operator: index.OPERATOR.EXISTS
|
|
65
|
+
});
|
|
66
|
+
}, [filter]);
|
|
67
|
+
react$1.useEffect(function () {
|
|
68
|
+
setTimeout(function () {
|
|
69
|
+
var _inputRef$current;
|
|
70
|
+
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
71
|
+
}, 100);
|
|
72
|
+
}, []);
|
|
73
|
+
var field = react$1.useMemo(function () {
|
|
74
|
+
if (!(values !== null && values !== void 0 && values.field)) return undefined;
|
|
75
|
+
return fields.find(function (f) {
|
|
76
|
+
return f.field === (values === null || values === void 0 ? void 0 : values.field);
|
|
77
|
+
});
|
|
78
|
+
}, [values]);
|
|
79
|
+
var operators = react$1.useMemo(function () {
|
|
80
|
+
var _formRef$current;
|
|
81
|
+
if (field == null) return [index.OPERATOR.EXISTS];
|
|
82
|
+
(_formRef$current = formRef.current) === null || _formRef$current === void 0 || _formRef$current.setValue("operator", index.TypeOperators[field.type][0]);
|
|
83
|
+
return _toConsumableArray(index.TypeOperators[field.type]);
|
|
84
|
+
}, [field]);
|
|
85
|
+
react$1.useEffect(function () {
|
|
86
|
+
if ((values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.EXISTS && (values === null || values === void 0 ? void 0 : values.value) !== undefined) {
|
|
87
|
+
var _formRef$current2;
|
|
88
|
+
(_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 || _formRef$current2.setValue("value", undefined);
|
|
89
|
+
}
|
|
90
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.BOOLEAN && (values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.IS && (values === null || values === void 0 ? void 0 : values.value) === undefined) {
|
|
91
|
+
var _formRef$current3;
|
|
92
|
+
(_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 || _formRef$current3.setValue("value", false);
|
|
93
|
+
}
|
|
94
|
+
}, [values, field]);
|
|
95
|
+
var valueInput = react$1.useMemo(function () {
|
|
96
|
+
if (field == null || !(values !== null && values !== void 0 && values.operator)) return null;
|
|
97
|
+
if ((values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.EXISTS) return null;
|
|
98
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.BOOLEAN) {
|
|
99
|
+
return /*#__PURE__*/jsxRuntime.jsx(form.Field, {
|
|
100
|
+
label: t("label.value"),
|
|
101
|
+
"data-plain": "true",
|
|
102
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
103
|
+
name: "value",
|
|
104
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Switch, {})
|
|
105
|
+
})
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.STRING || (field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.ID) {
|
|
109
|
+
if ((values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.IN) {
|
|
110
|
+
var _field$values;
|
|
111
|
+
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
112
|
+
name: "value",
|
|
113
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Select, {
|
|
114
|
+
multiple: true,
|
|
115
|
+
allowCreate: true,
|
|
116
|
+
allowClear: true,
|
|
117
|
+
options: (_field$values = field.values) !== null && _field$values !== void 0 ? _field$values : [],
|
|
118
|
+
label: t("label.value"),
|
|
119
|
+
onQuery: field.onSearch
|
|
120
|
+
})
|
|
121
|
+
});
|
|
122
|
+
} else {
|
|
123
|
+
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
124
|
+
name: "value",
|
|
125
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Input, {
|
|
126
|
+
label: t("label.value"),
|
|
127
|
+
allowClear: true
|
|
128
|
+
})
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if ((field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.DECIMAL || (field === null || field === void 0 ? void 0 : field.type) === index.FIELD_TYPE.NUMBER) {
|
|
133
|
+
var step = field.type === index.FIELD_TYPE.DECIMAL ? 0.1 : 1;
|
|
134
|
+
if ((values === null || values === void 0 ? void 0 : values.operator) === index.OPERATOR.BETWEEN) {
|
|
135
|
+
return /*#__PURE__*/jsxRuntime.jsxs(form.Field, {
|
|
136
|
+
label: t("label.value"),
|
|
137
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
138
|
+
name: "value[0]",
|
|
139
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Number, {
|
|
140
|
+
step: step,
|
|
141
|
+
allowClear: true
|
|
142
|
+
})
|
|
143
|
+
}), /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
144
|
+
className: "p-2 text-muted",
|
|
145
|
+
children: "<>"
|
|
146
|
+
}), /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
147
|
+
name: "value[1]",
|
|
148
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Number, {
|
|
149
|
+
step: step,
|
|
150
|
+
allowClear: true
|
|
151
|
+
})
|
|
152
|
+
})]
|
|
153
|
+
});
|
|
154
|
+
} else {
|
|
155
|
+
return /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
156
|
+
name: "value",
|
|
157
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Number, {
|
|
158
|
+
label: t("label.value"),
|
|
159
|
+
step: step,
|
|
160
|
+
allowClear: true
|
|
161
|
+
})
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}, [field, values === null || values === void 0 ? void 0 : values.operator]);
|
|
166
|
+
var handleSubmit = react$1.useCallback(function (model) {
|
|
167
|
+
var filter = {
|
|
168
|
+
id: model.id,
|
|
169
|
+
field: model.field,
|
|
170
|
+
negate: model.negate,
|
|
171
|
+
operator: model.operator,
|
|
172
|
+
value: model.value,
|
|
173
|
+
label: model.label
|
|
174
|
+
};
|
|
175
|
+
onChange === null || onChange === void 0 || onChange(filter);
|
|
176
|
+
tree === null || tree === void 0 || tree.events.emit("close");
|
|
177
|
+
}, [onChange]);
|
|
178
|
+
return /*#__PURE__*/jsxRuntime.jsxs(form.Form, {
|
|
179
|
+
formRef: formRef,
|
|
180
|
+
schema: FilterSchema,
|
|
181
|
+
defaultValues: values,
|
|
182
|
+
onChange: setValues,
|
|
183
|
+
onSubmit: handleSubmit,
|
|
184
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs(core.Row, {
|
|
185
|
+
children: [/*#__PURE__*/jsxRuntime.jsx(core.Col, {
|
|
186
|
+
flex: "fill",
|
|
187
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
188
|
+
name: "field",
|
|
189
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Select, {
|
|
190
|
+
required: true,
|
|
191
|
+
ref: inputRef,
|
|
192
|
+
label: t("label.field"),
|
|
193
|
+
options: fields,
|
|
194
|
+
labelProperty: "label",
|
|
195
|
+
valueProperty: "field",
|
|
196
|
+
groupProperty: "type"
|
|
197
|
+
})
|
|
198
|
+
})
|
|
199
|
+
}), /*#__PURE__*/jsxRuntime.jsxs(core.Col, {
|
|
200
|
+
flex: "auto",
|
|
201
|
+
className: "text-center",
|
|
202
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("label", {
|
|
203
|
+
className: "block py-0.5 text-sm",
|
|
204
|
+
children: t("label.exclude")
|
|
205
|
+
}), /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
206
|
+
name: "negate",
|
|
207
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Switch, {
|
|
208
|
+
color: "danger"
|
|
209
|
+
})
|
|
210
|
+
})]
|
|
211
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Col, {
|
|
212
|
+
flex: "auto",
|
|
213
|
+
className: "basis-28",
|
|
214
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
215
|
+
name: "operator",
|
|
216
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Select, {
|
|
217
|
+
label: t("label.operator"),
|
|
218
|
+
options: operators,
|
|
219
|
+
renderer: function renderer(v) {
|
|
220
|
+
return t("operator.".concat(v));
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
})
|
|
224
|
+
})]
|
|
225
|
+
}), /*#__PURE__*/jsxRuntime.jsx("br", {}), valueInput, /*#__PURE__*/jsxRuntime.jsx("br", {}), /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
|
|
226
|
+
name: "label",
|
|
227
|
+
children: /*#__PURE__*/jsxRuntime.jsx(form.Input, {
|
|
228
|
+
label: t("label.label"),
|
|
229
|
+
placeholder: t("label.label"),
|
|
230
|
+
decorateEnd: !(filter !== null && filter !== void 0 && filter.label) && /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
231
|
+
className: "text-sm opacity-65 pe-4",
|
|
232
|
+
children: "Optional"
|
|
233
|
+
})
|
|
234
|
+
})
|
|
235
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
236
|
+
className: "flex pt-4 justify-end gap-1",
|
|
237
|
+
children: [onRemove && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
238
|
+
className: "flex-1",
|
|
239
|
+
children: /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
240
|
+
"data-dropdown-dismiss": "true",
|
|
241
|
+
variant: "link",
|
|
242
|
+
size: "sm",
|
|
243
|
+
color: "danger",
|
|
244
|
+
onClick: onRemove,
|
|
245
|
+
children: t("label.remove")
|
|
246
|
+
})
|
|
247
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
248
|
+
"data-dropdown-dismiss": "true",
|
|
249
|
+
variant: "link",
|
|
250
|
+
size: "sm",
|
|
251
|
+
children: t("label.cancel")
|
|
252
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Button, {
|
|
253
|
+
type: "submit",
|
|
254
|
+
variant: "solid",
|
|
255
|
+
size: "sm",
|
|
256
|
+
children: t("label.apply")
|
|
257
|
+
})]
|
|
258
|
+
})]
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
exports.FilterForm = FilterForm;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
5
|
+
var core = require('@react-fabric/core');
|
|
6
|
+
var react = require('react');
|
|
7
|
+
var reactI18next = require('react-i18next');
|
|
8
|
+
var FilterEdit = require('./FilterEdit.js');
|
|
9
|
+
var FilterView = require('./FilterView.js');
|
|
10
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
11
|
+
|
|
12
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
|
+
var FilterMenu = function FilterMenu(_ref) {
|
|
15
|
+
var filter = _ref.filter;
|
|
16
|
+
_ref.fields;
|
|
17
|
+
var onChange = _ref.onChange,
|
|
18
|
+
onRemove = _ref.onRemove;
|
|
19
|
+
var _useTranslation = reactI18next.useTranslation("searchbar"),
|
|
20
|
+
t = _useTranslation.t;
|
|
21
|
+
var _useState = react.useState(),
|
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
23
|
+
view = _useState2[0],
|
|
24
|
+
setView = _useState2[1];
|
|
25
|
+
return view === "edit" ? /*#__PURE__*/jsxRuntime.jsx(FilterEdit.FilterEdit, {
|
|
26
|
+
filter: filter,
|
|
27
|
+
onChange: onChange,
|
|
28
|
+
onRemove: onRemove
|
|
29
|
+
}) : view === "view" ? /*#__PURE__*/jsxRuntime.jsx(FilterView.FilterView, {
|
|
30
|
+
filter: filter,
|
|
31
|
+
onRemove: onRemove
|
|
32
|
+
}) : /*#__PURE__*/jsxRuntime.jsxs(core.Menu, {
|
|
33
|
+
className: "text-sm",
|
|
34
|
+
children: [filter.canEdit !== false ? /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
35
|
+
icon: core.CoreIcons.edit,
|
|
36
|
+
label: t("label.edit"),
|
|
37
|
+
"data-dropdown-dismiss": "false",
|
|
38
|
+
onClick: function onClick() {
|
|
39
|
+
setView("edit");
|
|
40
|
+
}
|
|
41
|
+
}) : /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
42
|
+
icon: core.CoreIcons.eye,
|
|
43
|
+
label: t("label.view"),
|
|
44
|
+
"data-dropdown-dismiss": "false",
|
|
45
|
+
onClick: function onClick() {
|
|
46
|
+
setView("view");
|
|
47
|
+
}
|
|
48
|
+
}), /*#__PURE__*/jsxRuntime.jsx(core.Divider, {}), filter.canPin !== false && /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
49
|
+
label: t(filter.pinned ? "label.unpin" : "label.pin"),
|
|
50
|
+
onClick: function onClick() {
|
|
51
|
+
return onChange(_objectSpread(_objectSpread({}, filter), {}, {
|
|
52
|
+
pinned: !filter.pinned
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
}), filter.canInvert !== false && /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
56
|
+
label: t(filter.negate ? "label.include" : "label.exclude"),
|
|
57
|
+
onClick: function onClick() {
|
|
58
|
+
return onChange(_objectSpread(_objectSpread({}, filter), {}, {
|
|
59
|
+
negate: !filter.negate
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
}), filter.canDisable !== false && /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
63
|
+
label: t(filter.disabled ? "label.enable" : "label.disable"),
|
|
64
|
+
onClick: function onClick() {
|
|
65
|
+
return onChange(_objectSpread(_objectSpread({}, filter), {}, {
|
|
66
|
+
disabled: !filter.disabled
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
}), !filter.required && /*#__PURE__*/jsxRuntime.jsx(core.Divider, {}), !filter.required && /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
|
|
70
|
+
color: "danger",
|
|
71
|
+
icon: core.CoreIcons.remove,
|
|
72
|
+
label: t("label.remove"),
|
|
73
|
+
onClick: function onClick() {
|
|
74
|
+
return onRemove();
|
|
75
|
+
}
|
|
76
|
+
})]
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
exports.FilterMenu = FilterMenu;
|