@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
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import { CoreIcons, Dropdown, Chip, Icon } from '@react-fabric/core';
|
|
5
|
+
import { isNil } from '@react-fabric/utilities';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import { useMemo, Fragment } from 'react';
|
|
8
|
+
import { useTranslation } from 'react-i18next';
|
|
9
|
+
import { FilterMenu } from './FilterMenu.js';
|
|
10
|
+
import { jsxs, jsx } from '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 FilterTag = function FilterTag(_ref) {
|
|
15
|
+
var _filter$icon;
|
|
16
|
+
var filter = _ref.filter,
|
|
17
|
+
fields = _ref.fields,
|
|
18
|
+
_ref$includedColor = _ref.includedColor,
|
|
19
|
+
includedColor = _ref$includedColor === void 0 ? "primary-500" : _ref$includedColor,
|
|
20
|
+
_ref$excludedColor = _ref.excludedColor,
|
|
21
|
+
excludedColor = _ref$excludedColor === void 0 ? "danger-500" : _ref$excludedColor,
|
|
22
|
+
onChange = _ref.onChange,
|
|
23
|
+
onRemove = _ref.onRemove;
|
|
24
|
+
var _useTranslation = useTranslation("searchbar"),
|
|
25
|
+
t = _useTranslation.t;
|
|
26
|
+
var label = useMemo(function () {
|
|
27
|
+
var _filter$value;
|
|
28
|
+
if (filter.label) return /*#__PURE__*/jsxs(Fragment, {
|
|
29
|
+
children: [filter.negate && /*#__PURE__*/jsx("span", {
|
|
30
|
+
className: "font-semibold",
|
|
31
|
+
children: "NOT"
|
|
32
|
+
}), /*#__PURE__*/jsx("span", {
|
|
33
|
+
children: filter.label
|
|
34
|
+
})]
|
|
35
|
+
});
|
|
36
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
37
|
+
children: [filter.negate && /*#__PURE__*/jsx("span", {
|
|
38
|
+
className: "font-semibold",
|
|
39
|
+
children: "NOT"
|
|
40
|
+
}), /*#__PURE__*/jsx("span", {
|
|
41
|
+
children: filter.field
|
|
42
|
+
}), /*#__PURE__*/jsx("span", {
|
|
43
|
+
className: "font-semibold",
|
|
44
|
+
children: t("operator.".concat(filter.operator), {
|
|
45
|
+
defaultValue: filter.operator
|
|
46
|
+
})
|
|
47
|
+
}), "value" in filter && !isNil(filter.value) && /*#__PURE__*/jsx("span", {
|
|
48
|
+
className: "truncate block",
|
|
49
|
+
children: (_filter$value = filter.value) === null || _filter$value === void 0 ? void 0 : _filter$value.toString().substring(0, 24)
|
|
50
|
+
})]
|
|
51
|
+
});
|
|
52
|
+
}, [filter]);
|
|
53
|
+
var color = useMemo(function () {
|
|
54
|
+
return filter.negate ? excludedColor : includedColor;
|
|
55
|
+
}, [filter, includedColor, excludedColor]);
|
|
56
|
+
var icon = useMemo(function () {
|
|
57
|
+
if (filter.canDisable === false) return undefined;
|
|
58
|
+
return filter.disabled ? CoreIcons.checkboxOff : CoreIcons.checkboxOn;
|
|
59
|
+
}, [filter]);
|
|
60
|
+
return /*#__PURE__*/jsxs(Dropdown, {
|
|
61
|
+
showArrow: true,
|
|
62
|
+
children: [/*#__PURE__*/jsx(Chip, {
|
|
63
|
+
size: "sm",
|
|
64
|
+
color: color,
|
|
65
|
+
className: "outline outline-1 max-w-60",
|
|
66
|
+
variant: filter.pinned ? "solid" : undefined,
|
|
67
|
+
icon: icon,
|
|
68
|
+
iconColor: color,
|
|
69
|
+
onIconClick: function onIconClick(e) {
|
|
70
|
+
return [onChange(_objectSpread(_objectSpread({}, filter), {}, {
|
|
71
|
+
disabled: !filter.disabled
|
|
72
|
+
})), e.stopPropagation()];
|
|
73
|
+
},
|
|
74
|
+
stopPropagation: true,
|
|
75
|
+
onRemove: filter.required ? undefined : function () {
|
|
76
|
+
return onRemove();
|
|
77
|
+
},
|
|
78
|
+
children: /*#__PURE__*/jsxs("div", {
|
|
79
|
+
className: classNames("flex gap-1", filter.disabled && "line-through opacity-65"),
|
|
80
|
+
children: [filter.pinned && /*#__PURE__*/jsx(Icon, {
|
|
81
|
+
icon: (_filter$icon = filter.icon) !== null && _filter$icon !== void 0 ? _filter$icon : CoreIcons.pin
|
|
82
|
+
}), label]
|
|
83
|
+
})
|
|
84
|
+
}), /*#__PURE__*/jsx(FilterMenu, {
|
|
85
|
+
filter: filter,
|
|
86
|
+
fields: fields,
|
|
87
|
+
onChange: onChange,
|
|
88
|
+
onRemove: onRemove
|
|
89
|
+
})]
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export { FilterTag };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Copy, Button } from '@react-fabric/core';
|
|
4
|
+
import { isArray } from '@react-fabric/utilities';
|
|
5
|
+
import { useMemo, Fragment } from 'react';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import { OPERATOR } from '../types/index.js';
|
|
8
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* React Fabric
|
|
12
|
+
* @version: 1.0.0
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
* The MIT License (MIT)
|
|
16
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
17
|
+
*
|
|
18
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
19
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
20
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
21
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
22
|
+
* subject to the following conditions:
|
|
23
|
+
*
|
|
24
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
25
|
+
* portions of the Software.
|
|
26
|
+
*
|
|
27
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
28
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
29
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
30
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
var FilterView = function FilterView(_ref) {
|
|
34
|
+
var filter = _ref.filter,
|
|
35
|
+
onRemove = _ref.onRemove;
|
|
36
|
+
var _useTranslation = useTranslation("searchbar"),
|
|
37
|
+
t = _useTranslation.t;
|
|
38
|
+
var view = useMemo(function () {
|
|
39
|
+
var _filter$query;
|
|
40
|
+
if ("query" in filter) return JSON.stringify(JSON.parse((_filter$query = filter.query) !== null && _filter$query !== void 0 ? _filter$query : "{}"), null, 2);
|
|
41
|
+
if ("field" in filter) {
|
|
42
|
+
var _filter$value;
|
|
43
|
+
var value = (_filter$value = filter.value) === null || _filter$value === void 0 ? void 0 : _filter$value.toString();
|
|
44
|
+
if (filter.operator === OPERATOR.BETWEEN && isArray(filter.value)) {
|
|
45
|
+
var _filter$value2;
|
|
46
|
+
value = "[".concat((_filter$value2 = filter.value) === null || _filter$value2 === void 0 ? void 0 : _filter$value2.join(" - "), "]");
|
|
47
|
+
}
|
|
48
|
+
if (filter.operator === OPERATOR.IN && isArray(filter.value)) {
|
|
49
|
+
var _filter$value3;
|
|
50
|
+
value = "[".concat((_filter$value3 = filter.value) === null || _filter$value3 === void 0 ? void 0 : _filter$value3.join(", "), "]");
|
|
51
|
+
}
|
|
52
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
53
|
+
children: [filter.negate && /*#__PURE__*/jsx("b", {
|
|
54
|
+
children: "NOT\xA0"
|
|
55
|
+
}), /*#__PURE__*/jsx("span", {
|
|
56
|
+
children: filter.field
|
|
57
|
+
}), /*#__PURE__*/jsxs("b", {
|
|
58
|
+
children: ["\xA0", t("operator.".concat(filter.operator)), "\xA0"]
|
|
59
|
+
}), /*#__PURE__*/jsx("div", {
|
|
60
|
+
children: value
|
|
61
|
+
})]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return "";
|
|
65
|
+
}, [filter]);
|
|
66
|
+
return /*#__PURE__*/jsxs("div", {
|
|
67
|
+
className: "p-2 bg-base relative",
|
|
68
|
+
children: ["query" in filter && /*#__PURE__*/jsx("div", {
|
|
69
|
+
className: "absolute top-2 end-2 z-10",
|
|
70
|
+
children: /*#__PURE__*/jsx(Copy, {
|
|
71
|
+
size: "sm",
|
|
72
|
+
text: view
|
|
73
|
+
})
|
|
74
|
+
}), /*#__PURE__*/jsx("pre", {
|
|
75
|
+
className: "overflow-auto bg-base outline text-sm p-2 max-h-[24rem] max-w-[48rem] min-w-[24rem]",
|
|
76
|
+
children: view
|
|
77
|
+
}), !filter.required && /*#__PURE__*/jsx(Button, {
|
|
78
|
+
size: "sm",
|
|
79
|
+
variant: "link",
|
|
80
|
+
color: "danger",
|
|
81
|
+
"data-dropdown-dismiss": "true",
|
|
82
|
+
onClick: onRemove,
|
|
83
|
+
children: t("label.remove")
|
|
84
|
+
})]
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export { FilterView };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
4
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
5
|
+
import { useFloatingTree } from '@floating-ui/react';
|
|
6
|
+
import { Callout, Button } from '@react-fabric/core';
|
|
7
|
+
import { Form, Controller, Input } from '@react-fabric/form';
|
|
8
|
+
import { CodeEditor } from '@react-fabric/monaco';
|
|
9
|
+
import { yup, isEmpty, shortHash } from '@react-fabric/utilities';
|
|
10
|
+
import classNames from 'classnames';
|
|
11
|
+
import { useRef, useMemo, useEffect, useCallback } from 'react';
|
|
12
|
+
import { useTranslation } from 'react-i18next';
|
|
13
|
+
import { useFilterContext } from './Context.js';
|
|
14
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
15
|
+
|
|
16
|
+
var _excluded = ["checked", "error", "invalid"];
|
|
17
|
+
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; }
|
|
18
|
+
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; }
|
|
19
|
+
var QuerySchema = new yup.ObjectSchema({
|
|
20
|
+
id: yup.string().required(),
|
|
21
|
+
label: yup.string().required(),
|
|
22
|
+
query: yup.string().required().test(function (value) {
|
|
23
|
+
try {
|
|
24
|
+
return !isEmpty(JSON.parse(value));
|
|
25
|
+
} catch (_unused) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
var QueryForm = function QueryForm(_ref) {
|
|
31
|
+
var filter = _ref.filter,
|
|
32
|
+
onChange = _ref.onChange,
|
|
33
|
+
onRemove = _ref.onRemove;
|
|
34
|
+
var _useTranslation = useTranslation("searchbar"),
|
|
35
|
+
t = _useTranslation.t;
|
|
36
|
+
var tree = useFloatingTree();
|
|
37
|
+
var _useFilterContext = useFilterContext(),
|
|
38
|
+
_useFilterContext$def = _useFilterContext.defaultQuery,
|
|
39
|
+
defaultQuery = _useFilterContext$def === void 0 ? "" : _useFilterContext$def,
|
|
40
|
+
querySchema = _useFilterContext.querySchema;
|
|
41
|
+
var inputRef = useRef(null);
|
|
42
|
+
var filterValue = useMemo(function () {
|
|
43
|
+
var _filter$query;
|
|
44
|
+
if (filter && "query" in filter && filter.query) return {
|
|
45
|
+
id: filter.id,
|
|
46
|
+
query: JSON.stringify(JSON.parse((_filter$query = filter.query) !== null && _filter$query !== void 0 ? _filter$query : "{}"), null, 4),
|
|
47
|
+
label: filter.label
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
id: shortHash(),
|
|
51
|
+
label: "",
|
|
52
|
+
query: defaultQuery
|
|
53
|
+
};
|
|
54
|
+
}, [filter]);
|
|
55
|
+
useEffect(function () {
|
|
56
|
+
setTimeout(function () {
|
|
57
|
+
var _inputRef$current;
|
|
58
|
+
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
59
|
+
}, 100);
|
|
60
|
+
}, []);
|
|
61
|
+
var handleSubmit = useCallback(function (model) {
|
|
62
|
+
var filter = {
|
|
63
|
+
id: model.id,
|
|
64
|
+
query: model.query,
|
|
65
|
+
label: model.label
|
|
66
|
+
};
|
|
67
|
+
onChange === null || onChange === void 0 || onChange(filter);
|
|
68
|
+
tree === null || tree === void 0 || tree.events.emit("close");
|
|
69
|
+
}, [onChange]);
|
|
70
|
+
return /*#__PURE__*/jsxs(Form, {
|
|
71
|
+
schema: QuerySchema,
|
|
72
|
+
defaultValues: filterValue,
|
|
73
|
+
onSubmit: handleSubmit,
|
|
74
|
+
children: [/*#__PURE__*/jsx(Callout, {
|
|
75
|
+
color: "warning",
|
|
76
|
+
children: "For advanced users only!"
|
|
77
|
+
}), /*#__PURE__*/jsx(Controller, {
|
|
78
|
+
name: "label",
|
|
79
|
+
children: /*#__PURE__*/jsx(Input, {
|
|
80
|
+
required: true,
|
|
81
|
+
ref: inputRef,
|
|
82
|
+
label: t("label.label"),
|
|
83
|
+
placeholder: t("label.label")
|
|
84
|
+
})
|
|
85
|
+
}), /*#__PURE__*/jsx(Controller, {
|
|
86
|
+
name: "query",
|
|
87
|
+
children: function children(_ref2) {
|
|
88
|
+
_ref2.checked;
|
|
89
|
+
_ref2.error;
|
|
90
|
+
var invalid = _ref2.invalid,
|
|
91
|
+
field = _objectWithoutProperties(_ref2, _excluded);
|
|
92
|
+
return /*#__PURE__*/jsxs("div", {
|
|
93
|
+
className: "my-2",
|
|
94
|
+
children: [/*#__PURE__*/jsx("label", {
|
|
95
|
+
className: classNames("block px-2", invalid && "text-danger-600"),
|
|
96
|
+
children: t("label.query")
|
|
97
|
+
}), /*#__PURE__*/jsx("div", {
|
|
98
|
+
className: "h-[380px] w-[600px] grid outline",
|
|
99
|
+
children: /*#__PURE__*/jsx(CodeEditor, _objectSpread(_objectSpread({
|
|
100
|
+
minimal: true,
|
|
101
|
+
required: true
|
|
102
|
+
}, field), {}, {
|
|
103
|
+
schema: querySchema
|
|
104
|
+
}))
|
|
105
|
+
})]
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}), /*#__PURE__*/jsxs("div", {
|
|
109
|
+
className: "flex justify-end gap-1",
|
|
110
|
+
children: [onRemove && /*#__PURE__*/jsx("div", {
|
|
111
|
+
className: "flex-1",
|
|
112
|
+
children: /*#__PURE__*/jsx(Button, {
|
|
113
|
+
"data-dropdown-dismiss": "true",
|
|
114
|
+
variant: "link",
|
|
115
|
+
size: "sm",
|
|
116
|
+
color: "danger",
|
|
117
|
+
onClick: onRemove,
|
|
118
|
+
children: t("label.remove")
|
|
119
|
+
})
|
|
120
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
121
|
+
"data-dropdown-dismiss": "true",
|
|
122
|
+
variant: "link",
|
|
123
|
+
size: "sm",
|
|
124
|
+
children: t("label.cancel")
|
|
125
|
+
}), /*#__PURE__*/jsx(Button, {
|
|
126
|
+
type: "submit",
|
|
127
|
+
variant: "solid",
|
|
128
|
+
size: "sm",
|
|
129
|
+
children: t("label.apply")
|
|
130
|
+
})]
|
|
131
|
+
})]
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export { QueryForm };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
var label = {
|
|
4
|
+
filters: "المرشحات",
|
|
5
|
+
all_filters: "جميع المرشحات",
|
|
6
|
+
field: "مجال",
|
|
7
|
+
operator: "المشغل",
|
|
8
|
+
value: "قيمة",
|
|
9
|
+
label: "ملصق",
|
|
10
|
+
optional: "خياري",
|
|
11
|
+
add: "إضافة عامل تصفية",
|
|
12
|
+
edit: "يحرر",
|
|
13
|
+
view: "منظر",
|
|
14
|
+
pin: "مثبت",
|
|
15
|
+
unpin: "غير مثبت",
|
|
16
|
+
includeAll: "تضمين الكل",
|
|
17
|
+
excludeAll: "استبعاد الكل",
|
|
18
|
+
invertAll: "عكس التضمين/الاستبعاد",
|
|
19
|
+
removeAll: "إزالة الكل",
|
|
20
|
+
enableAll: "تمكين الكل",
|
|
21
|
+
disableAll: "تعطيل الكل",
|
|
22
|
+
toggleDisable: "عكس تعطيل/تمكين",
|
|
23
|
+
remove: "يزيل",
|
|
24
|
+
enable: "يُمكَِن",
|
|
25
|
+
disable: "إبطال",
|
|
26
|
+
exclude: "استبعاد",
|
|
27
|
+
include: "يشمل",
|
|
28
|
+
refresh: "ينعش",
|
|
29
|
+
update: "تحديث",
|
|
30
|
+
query: "استفسار",
|
|
31
|
+
apply: "يتقدم",
|
|
32
|
+
cancel: "يلغي",
|
|
33
|
+
"delete": "يمسح",
|
|
34
|
+
basicFilter: "الفلتر الأساسي",
|
|
35
|
+
customQuery: "استعلام مخصص",
|
|
36
|
+
forAdvanced: "للمستخدمين المتقدمين فقط!"
|
|
37
|
+
};
|
|
38
|
+
var operator = {
|
|
39
|
+
EXISTS: "موجود",
|
|
40
|
+
IS: "يكون",
|
|
41
|
+
IN: "في",
|
|
42
|
+
LT: "<",
|
|
43
|
+
GT: ">",
|
|
44
|
+
LTE: "≤",
|
|
45
|
+
GTE: "≥",
|
|
46
|
+
INCLUDES: "يشمل",
|
|
47
|
+
STARTS: "ابدا ب",
|
|
48
|
+
ENDS: "ينتهي مع",
|
|
49
|
+
WITHIN: "في غضون",
|
|
50
|
+
BETWEEN: "بين هذا وذاك"
|
|
51
|
+
};
|
|
52
|
+
var placeholder = "مصطلح البحث...";
|
|
53
|
+
var type = {
|
|
54
|
+
STRING: "سلسلة",
|
|
55
|
+
NUMBER: "كثافة العمليات",
|
|
56
|
+
DECIMAL: "يطفو",
|
|
57
|
+
BOOLEAN: "رقم",
|
|
58
|
+
DATE: "منطقي",
|
|
59
|
+
DATETIME: "تاريخ",
|
|
60
|
+
GEO: "GeoJSON"
|
|
61
|
+
};
|
|
62
|
+
var validate = {
|
|
63
|
+
field: "حقل مطلوب",
|
|
64
|
+
operator: "عامل مطلوب",
|
|
65
|
+
value: "القيمة المطلوبة",
|
|
66
|
+
compare: "مقارنة الحقل المطلوب",
|
|
67
|
+
label: "التصنيف مطلوب"
|
|
68
|
+
};
|
|
69
|
+
var ar = {
|
|
70
|
+
label: label,
|
|
71
|
+
operator: operator,
|
|
72
|
+
placeholder: placeholder,
|
|
73
|
+
type: type,
|
|
74
|
+
validate: validate
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export { ar as default, label, operator, placeholder, type, validate };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
var label = {
|
|
4
|
+
filters: "Filters",
|
|
5
|
+
all_filters: "All Filters",
|
|
6
|
+
field: "Field",
|
|
7
|
+
operator: "Operator",
|
|
8
|
+
value: "Value",
|
|
9
|
+
label: "Label",
|
|
10
|
+
optional: "Optional",
|
|
11
|
+
add: "Add Filter",
|
|
12
|
+
edit: "Edit",
|
|
13
|
+
view: "View",
|
|
14
|
+
pin: "Pinned",
|
|
15
|
+
unpin: "Unpinned",
|
|
16
|
+
includeAll: "Include All",
|
|
17
|
+
excludeAll: "Exclude All",
|
|
18
|
+
invertAll: "Invert Include/Exclude",
|
|
19
|
+
removeAll: "Remove All",
|
|
20
|
+
enableAll: "Enable All",
|
|
21
|
+
disableAll: "Disable All",
|
|
22
|
+
toggleDisable: "Invert Disable/Enable",
|
|
23
|
+
remove: "Remove",
|
|
24
|
+
enable: "Enable",
|
|
25
|
+
disable: "Disable",
|
|
26
|
+
exclude: "Exclude",
|
|
27
|
+
include: "Include",
|
|
28
|
+
refresh: "Refresh",
|
|
29
|
+
update: "Update",
|
|
30
|
+
query: "Query",
|
|
31
|
+
apply: "Apply",
|
|
32
|
+
cancel: "Cancel",
|
|
33
|
+
"delete": "Delete",
|
|
34
|
+
basicFilter: "Basic Filter",
|
|
35
|
+
customQuery: "Custom Query",
|
|
36
|
+
forAdvanced: "For advanced users only!"
|
|
37
|
+
};
|
|
38
|
+
var operator = {
|
|
39
|
+
EXISTS: "Exists",
|
|
40
|
+
IS: "Is",
|
|
41
|
+
IN: "In",
|
|
42
|
+
LT: "<",
|
|
43
|
+
GT: ">",
|
|
44
|
+
LTE: "≤",
|
|
45
|
+
GTE: "≥",
|
|
46
|
+
INCLUDES: "Includes",
|
|
47
|
+
STARTS: "Starts with",
|
|
48
|
+
ENDS: "Ends with",
|
|
49
|
+
WITHIN: "Within",
|
|
50
|
+
BETWEEN: "Between"
|
|
51
|
+
};
|
|
52
|
+
var placeholder = "Search term...";
|
|
53
|
+
var type = {
|
|
54
|
+
STRING: "String",
|
|
55
|
+
NUMBER: "Number",
|
|
56
|
+
DECIMAL: "Decimal",
|
|
57
|
+
BOOLEAN: "Bool",
|
|
58
|
+
DATE: "Date",
|
|
59
|
+
DATETIME: "Date Time",
|
|
60
|
+
GEO: "GeoJSON"
|
|
61
|
+
};
|
|
62
|
+
var validate = {
|
|
63
|
+
field: "Field required",
|
|
64
|
+
operator: "Operator required",
|
|
65
|
+
value: "Value required",
|
|
66
|
+
compare: "Compare field required",
|
|
67
|
+
label: "Label required"
|
|
68
|
+
};
|
|
69
|
+
var en = {
|
|
70
|
+
label: label,
|
|
71
|
+
operator: operator,
|
|
72
|
+
placeholder: placeholder,
|
|
73
|
+
type: type,
|
|
74
|
+
validate: validate
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export { en as default, label, operator, placeholder, type, validate };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { addTranslationBundle } from '@react-fabric/core';
|
|
4
|
+
import ar from './ar.json.js';
|
|
5
|
+
import en from './en.json.js';
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* React Fabric
|
|
9
|
+
* @version: 1.0.0
|
|
10
|
+
*
|
|
11
|
+
*
|
|
12
|
+
* The MIT License (MIT)
|
|
13
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
14
|
+
*
|
|
15
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
16
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
17
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
18
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
19
|
+
* subject to the following conditions:
|
|
20
|
+
*
|
|
21
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
22
|
+
* portions of the Software.
|
|
23
|
+
*
|
|
24
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
25
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
26
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
27
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
addTranslationBundle("searchbar", {
|
|
31
|
+
en: en,
|
|
32
|
+
ar: ar
|
|
33
|
+
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
4
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
5
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
6
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
7
|
+
import { useLocalStorage, useDebounce, Button } from '@react-fabric/core';
|
|
8
|
+
import { Field, AutoComplete } from '@react-fabric/form';
|
|
9
|
+
import { EMPTY_ARRAY, isArray, dedupe } from '@react-fabric/utilities';
|
|
10
|
+
import { useState, useMemo, useReducer } from 'react';
|
|
11
|
+
import { useTranslation } from 'react-i18next';
|
|
12
|
+
import { FilterBar } from '../filterbar/FilterBar.js';
|
|
13
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
14
|
+
|
|
15
|
+
var _excluded = ["historyKey", "historyCount", "defaultQueryList", "prepend", "append", "decorateEnd", "decorateStart", "actions", "hideFilters", "defaultCollapsed", "disabled", "onCollapsed", "onQuery", "onSearch", "query", "multiple", "filters"];
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
|
+
var SearchBar = function SearchBar(_ref) {
|
|
19
|
+
var _ref$historyKey = _ref.historyKey,
|
|
20
|
+
historyKey = _ref$historyKey === void 0 ? "ruf:search" : _ref$historyKey,
|
|
21
|
+
_ref$historyCount = _ref.historyCount,
|
|
22
|
+
historyCount = _ref$historyCount === void 0 ? 20 : _ref$historyCount,
|
|
23
|
+
defaultQueryList = _ref.defaultQueryList,
|
|
24
|
+
prepend = _ref.prepend,
|
|
25
|
+
append = _ref.append,
|
|
26
|
+
decorateEnd = _ref.decorateEnd,
|
|
27
|
+
decorateStart = _ref.decorateStart,
|
|
28
|
+
actions = _ref.actions,
|
|
29
|
+
hideFilters = _ref.hideFilters,
|
|
30
|
+
_ref$defaultCollapsed = _ref.defaultCollapsed,
|
|
31
|
+
defaultCollapsed = _ref$defaultCollapsed === void 0 ? false : _ref$defaultCollapsed;
|
|
32
|
+
_ref.disabled;
|
|
33
|
+
_ref.onCollapsed;
|
|
34
|
+
var onQuery = _ref.onQuery,
|
|
35
|
+
onSearch = _ref.onSearch,
|
|
36
|
+
query = _ref.query,
|
|
37
|
+
multiple = _ref.multiple,
|
|
38
|
+
_ref$filters = _ref.filters,
|
|
39
|
+
filters = _ref$filters === void 0 ? EMPTY_ARRAY : _ref$filters,
|
|
40
|
+
filterProps = _objectWithoutProperties(_ref, _excluded);
|
|
41
|
+
var _useTranslation = useTranslation("searchbar"),
|
|
42
|
+
t = _useTranslation.t;
|
|
43
|
+
var _useLocalStorage = useLocalStorage(historyKey, defaultQueryList !== null && defaultQueryList !== void 0 ? defaultQueryList : []),
|
|
44
|
+
_useLocalStorage2 = _slicedToArray(_useLocalStorage, 2),
|
|
45
|
+
history = _useLocalStorage2[0],
|
|
46
|
+
setHistory = _useLocalStorage2[1];
|
|
47
|
+
var _useState = useState(defaultCollapsed),
|
|
48
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
49
|
+
collapsed = _useState2[0],
|
|
50
|
+
setCollapsed = _useState2[1];
|
|
51
|
+
var emptyValue = useMemo(function () {
|
|
52
|
+
return multiple ? EMPTY_ARRAY : "";
|
|
53
|
+
}, [multiple]);
|
|
54
|
+
var fireSearch = useDebounce(function (query, filters) {
|
|
55
|
+
onSearch === null || onSearch === void 0 || onSearch({
|
|
56
|
+
query: query,
|
|
57
|
+
filters: filters
|
|
58
|
+
});
|
|
59
|
+
}, []);
|
|
60
|
+
var _useReducer = useReducer(function (state, action) {
|
|
61
|
+
if (action.type === "dirty") {
|
|
62
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
63
|
+
dirty: action.dirty
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (action.type === "query") {
|
|
67
|
+
var _action$query, _action$query2;
|
|
68
|
+
!multiple && fireSearch((_action$query = action.query) !== null && _action$query !== void 0 ? _action$query : emptyValue, state.filters);
|
|
69
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
70
|
+
dirty: false,
|
|
71
|
+
query: (_action$query2 = action.query) !== null && _action$query2 !== void 0 ? _action$query2 : emptyValue
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (action.type === "filter") {
|
|
75
|
+
var _action$filters, _action$filters2;
|
|
76
|
+
fireSearch(state.query, (_action$filters = action.filters) !== null && _action$filters !== void 0 ? _action$filters : []);
|
|
77
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
78
|
+
dirty: false,
|
|
79
|
+
filters: (_action$filters2 = action.filters) !== null && _action$filters2 !== void 0 ? _action$filters2 : []
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return state;
|
|
83
|
+
}, {
|
|
84
|
+
dirty: false,
|
|
85
|
+
query: query,
|
|
86
|
+
filters: filters
|
|
87
|
+
}),
|
|
88
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
89
|
+
state = _useReducer2[0],
|
|
90
|
+
dispatch = _useReducer2[1];
|
|
91
|
+
var updateHistory = function updateHistory(value) {
|
|
92
|
+
var historyEntry = isArray(value) ? value : [value];
|
|
93
|
+
setHistory(dedupe([].concat(_toConsumableArray(historyEntry), _toConsumableArray(history))).slice(0, historyCount));
|
|
94
|
+
dispatch({
|
|
95
|
+
type: "query",
|
|
96
|
+
query: value
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
var handleFilterChange = function handleFilterChange() {
|
|
100
|
+
var filters = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
101
|
+
dispatch({
|
|
102
|
+
type: "filter",
|
|
103
|
+
filters: filters
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
return /*#__PURE__*/jsxs("div", {
|
|
107
|
+
children: [/*#__PURE__*/jsxs("div", {
|
|
108
|
+
className: "flex flex-nowrap gap-1 mb-1",
|
|
109
|
+
children: [/*#__PURE__*/jsxs(Field, {
|
|
110
|
+
"data-inner": true,
|
|
111
|
+
className: "flex-1",
|
|
112
|
+
children: [!hideFilters && /*#__PURE__*/jsx(Button, {
|
|
113
|
+
variant: "link",
|
|
114
|
+
badge: filters.length,
|
|
115
|
+
onClick: function onClick() {
|
|
116
|
+
return setCollapsed(!collapsed);
|
|
117
|
+
},
|
|
118
|
+
children: t("label.filters")
|
|
119
|
+
}), prepend, /*#__PURE__*/jsx(AutoComplete, {
|
|
120
|
+
allowClear: true,
|
|
121
|
+
expandOnEdit: true,
|
|
122
|
+
multiple: multiple,
|
|
123
|
+
history: history,
|
|
124
|
+
value: state.query,
|
|
125
|
+
decorateEnd: decorateEnd,
|
|
126
|
+
decorateStart: decorateStart,
|
|
127
|
+
onInput: function onInput() {
|
|
128
|
+
return dispatch({
|
|
129
|
+
type: "dirty",
|
|
130
|
+
dirty: true
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
onSelect: updateHistory,
|
|
134
|
+
onQuery: onQuery,
|
|
135
|
+
onEnterPressed: function onEnterPressed() {
|
|
136
|
+
return fireSearch(state.query, state.filters);
|
|
137
|
+
}
|
|
138
|
+
}), append, /*#__PURE__*/jsx(Button, {
|
|
139
|
+
variant: "solid",
|
|
140
|
+
color: state.dirty ? "warning" : "primary",
|
|
141
|
+
onClick: function onClick() {
|
|
142
|
+
return fireSearch(state.query, state.filters);
|
|
143
|
+
},
|
|
144
|
+
children: t(state.dirty ? "label.update" : "label.refresh")
|
|
145
|
+
})]
|
|
146
|
+
}), actions]
|
|
147
|
+
}), !hideFilters && !collapsed && /*#__PURE__*/jsx(FilterBar, _objectSpread(_objectSpread({}, filterProps), {}, {
|
|
148
|
+
filters: state.filters,
|
|
149
|
+
onFilterChanged: handleFilterChange
|
|
150
|
+
}))]
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export { SearchBar };
|